Merge branch 'master' of github.com:scemama/irpf90

This commit is contained in:
Anthony Scemama 2017-07-11 23:58:19 +02:00
commit 3eef718b68
8 changed files with 93 additions and 82 deletions

View File

@ -1,7 +1,21 @@
PYTHON=python
PYVERSION=$(shell $(PYTHON) -c "import sys; print(sys.version[:3])")
HAS_CYTHON=$(shell bash -c "which cython &> /dev/null && echo 1 || echo 0")
ifneq ($(HAS_CYTHON),0)
../bin/irpf90: irpf90.so
rm ../bin/irpf90 ; cd ../bin ; ln -s ../src/irpf90_python.exe irpf90
irpf90.so : $(wildcard *.py) irpf90.c
./cython_setup.py build_ext --inplace
irpf90.c: irpf90.py
cython --embed irpf90.py
else
../bin/irpf90: irpf90_python.exe
rm ../bin/irpf90 ; cd ../bin ; ln -s ../src/irpf90_python.exe irpf90
endif
clean:
rm -f *.c *.so *.pyc *.pyo 2>/dev/null

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
# IRPF90 is a Fortran90 preprocessor written in Python for programming using
# the Implicit Reference to Parameters (IRP) method.
# Copyright (C) 2009 Anthony SCEMAMA
# Copyright (C) 2009 Anthony SCEMAMA
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -20,8 +20,8 @@
# Anthony Scemama
# LCPQ - IRSAMC - CNRS
# Universite Paul Sabatier
# 118, route de Narbonne
# 31062 Toulouse Cedex 4
# 118, route de Narbonne
# 31062 Toulouse Cedex 4
# scemama@irsamc.ups-tlse.fr
import os, sys
@ -42,7 +42,7 @@ def dress(f, in_root=False):
""" Transfoms the filename into $PWD/IRPF90_temp/f
Note:
In root=True resurn $PWD/f
In root=True resurn $PWD/f
"""
pwd = os.getcwd()
@ -110,7 +110,7 @@ def create_build_link(t, l_irp_m, l_usr_m, l_ext_m, ninja=True):
# (Module, List[str], List[str]) -> str
""" Create the build command who will link the .o file into the target executable
To link we need the .o file corresponding to the target, and the ar lib.
To link we need the .o file corresponding to the target, and the ar lib.
"""
irp_id = irpf90_t.irp_id
@ -154,8 +154,8 @@ def create_build_compile(t, l_module, l_ext_modfile=[], ninja=True):
- The module can produce a .MOD file
- The module can Need another .MOD file.
This .MOD file can be produced by:
1) a file generated by IRP_F90 preprocessor.
This .MOD file can be produced by:
1) a file generated by IRP_F90 preprocessor.
2) a file defined by the user but a .irp.f90 file.
3) a file not handle at all by IRPF90.
@ -215,12 +215,12 @@ def create_build_compile(t, l_module, l_ext_modfile=[], ninja=True):
list_of_includes = ' '
l_build = [
"build {target_o}: compile_fortran_{irp_id} {target_F90} | {list_of_includes} {list_of_modules} {list_of_modules_irp}",
"build {target_o}: compile_fortran_{irp_id} {target_F90} | ../Makefile {list_of_includes} {list_of_modules} {list_of_modules_irp}",
" short_in = {short_target_F90}", " short_out = {short_target}", ""
]
l_build_make = [
"{target_o}: {target_F90} | {list_of_includes} {list_of_modules} {list_of_modules_irp}",
"{target_o}: {target_F90} | ../Makefile {list_of_includes} {list_of_modules} {list_of_modules_irp}",
'\t@printf "F: {short_target_F90} -> {short_target}\\n"', "\t@$(FC) $(FCFLAGS) -c $^ -o $@",
""
]
@ -297,10 +297,10 @@ def create_make_all_clean(l_main):
#
'''Create the ALL and CLEAN target of Makefile
Note: Portability doesn't mater. -delete is maybe not posix
but -exec rm {} + is far more ugly!
'''
Note: Portability doesn't mater. -delete is maybe not posix
but -exec rm {} + is far more ugly!
'''
l_executable = ' '.join(dress(t.filename, in_root=True) for t in l_main)
@ -371,8 +371,8 @@ def run(d_module, ninja):
"""Wrote the ninja file needed to compile the program
Note:
- FC,AR,CC,CXX,LIB, FCFLAGS, CFLAGS, CXXFLAGS are compiler enviroment read
- SRC,OBJ: Are the not irp.f file defined by the user
- FC,AR,CC,CXX,LIB, FCFLAGS, CFLAGS, CXXFLAGS are compiler enviroment read
- SRC,OBJ: Are the not irp.f file defined by the user
"""
# Add required flags

View File

@ -42,12 +42,12 @@ class Entity(object):
# (list[str], str, int, Irpy_comm_world)
'''Instantiate the object.
Args:
text: List of lines between BEGIN_PROVIDER and END_PROVIDER included
int: An unique int id (usefull when profilling)
name: The name of the provider defined after the chosen BEGIN_PROVIDER statement
comm_world: A object to communicate we the external world.
'''
Args:
text: List of lines between BEGIN_PROVIDER and END_PROVIDER included
int: An unique int id (usefull when profilling)
name: The name of the provider defined after the chosen BEGIN_PROVIDER statement
comm_world: A object to communicate we the external world.
'''
assert type(text) == list
assert len(text) > 0
@ -69,8 +69,8 @@ class Entity(object):
# () -> Dict[str,Entity]
'''Create an alias to the global dictionary of Entity.
Note: Be aware of the possiblity of Cyclic Dependency.
'''
Note: Be aware of the possiblity of Cyclic Dependency.
'''
return self.comm_world.d_entity
@irpy.lazy_property
@ -78,9 +78,9 @@ class Entity(object):
# () -> Tuple[str, Parsed_text]
'''Create an alias to the global tuple for parsed text
Note: self.comm_world.t_filename_parsed_text need d_entity.
Be aware of the possibility of Cyclic Dependency
'''
Note: self.comm_world.t_filename_parsed_text need d_entity.
Be aware of the possibility of Cyclic Dependency
'''
return self.comm_world.t_filename_parsed_text
@irpy.lazy_property
@ -104,9 +104,9 @@ class Entity(object):
Exemple:
BEGIN_PROVIDER [pi, double precision] &
BEGIN_PROVIDER [e, double preision]
return True for 'pi' and False for 'e'
'''
return True for 'pi' and False for 'e'
'''
return self.name == self.same_as
@irpy.lazy_property
@ -114,12 +114,12 @@ class Entity(object):
# () -> Line
'''Find the declaration statement associated with the name of the provider
Exemple:
BEGIN_PROVIDER [pi, double precision] &
BEGIN_PROVIDER [e, double preision]
Exemple:
BEGIN_PROVIDER [pi, double precision] &
BEGIN_PROVIDER [e, double preision]
if self.name == e, will return BEGIN_PROVIDER [e, double preision]
'''
if self.name == e, will return BEGIN_PROVIDER [e, double preision]
'''
d = self.d_type_lines
return next(line for _, line in d[Begin_provider] + d[Cont_provider]
@ -247,16 +247,16 @@ class Entity(object):
# () -> List[str]
'''Extract the dimension of the needed array in a form of list of variable name
Exemple:
BEGIN_PROVIDER [real, ao_num ]
-> []
Exemple:
BEGIN_PROVIDER [real, ao_num ]
-> []
BEGIN_PROVIDER [ real, ao_oneD_p, (ao_num) ]
-> ['ao_num']
BEGIN_PROVIDER [ real, ao_oneD_p, (ao_num) ]
-> ['ao_num']
BEGIN_PROVIDER [ real, ao_oneD_prim_p, (ao_num,ao_prim_num_max) ]
-> ['ao_num', 'ao_prim_num_max']
'''
BEGIN_PROVIDER [ real, ao_oneD_prim_p, (ao_num,ao_prim_num_max) ]
-> ['ao_num', 'ao_prim_num_max']
'''
line = self.prototype.text.split('!')[0]
buffer = line.replace(']', '').split(',', 2)
@ -444,7 +444,7 @@ class Entity(object):
# Get the raw text for the builder
# ~#~#~#~#~#
#Next return the first element of the iterator
#Next return the first element of the iterator
ps_text = next(text for filename, text in self.cm_t_filename_parsed_text
if self.prototype.filename[0].startswith(filename))
begin = next(i for i, (_, line) in enumerate(ps_text)

View File

@ -169,9 +169,6 @@ def main():
if not command_line.do_run:
return
import irp_stack
irp_stack.create()
comm_world.create_buildfile(command_line.do_ninja)
comm_world.write_modules()

View File

@ -216,15 +216,15 @@ def move_to_top_list(text, it):
Note:
- The permutation neeed to be done following `it` order
- We can have `nested` subroutine / Function. (Because of interface)
- This function is called way to much. Is need to be efficient
- This function is Impure
- One pass over `text`
- We can have `nested` subroutine / Function. (Because of interface)
- This function is called way to much. Is need to be efficient
- This function is Unpure
- One pass over `text`
NB:
- I am not really proud of the Sentinel value for the deleted,
but I waste already so much time on more cleaver but not working solution...
- I am not really proud of the Sentinel value for the deleted,
but I waste already so much time on more cleaver but not working solution...
'''
assert set(it).issubset([NoDep, Declaration, Implicit, Use, Cont_provider])
@ -284,7 +284,7 @@ def move_interface(parsed_text, s_type=(Use, Implicit, Declaration, Subroutine,
'''Move everything containt into 'interface' below the first instance of s_type who preced it
Note:
= This function is impure
= This function is unpur
'''
# Get the born of the interface
@ -311,7 +311,7 @@ def build_sub_needs(parsed_text, d_subroutine):
'''Set the needs, and provides arguements of Routine present in parsed_text
Note:
This function is impure
This function is unpure
'''
l_buffer = []

View File

@ -121,7 +121,7 @@ def get_canonized_text(text_lower):
def get_type(i, filename, line, line_lower, line_lower_canonized, is_doc):
# ( int,str,str,str,str,bool) -> Irpf90_t
# ( int,str,str,str,str,bool) -> Irpf90_t
'''Find the type of a text line'''
line = line.rstrip()
@ -204,8 +204,8 @@ def save_and_execute(irpdir, scriptname, code, interpreter):
''' Save the script in irpdir/scriptname and Execute it
Note:
The script are executed in the orginal directory of the .irp.f (aka '..')
and this directory is added to PYTHONPATH.
The script are executed in the orginal directory of the .irp.f (aka '..')
and this directory is added to PYTHONPATH.
'''
irpdir_scriptname = os.path.abspath(os.path.join(irpdir, scriptname))
@ -418,7 +418,7 @@ def remove_comments(text, form):
'''Remove all comments
Note:
This function is impure
This function is unpur
'''
result = []
@ -800,8 +800,8 @@ def process_old_style_do(text):
######################################################################
def change_single_line_ifs(text):
# List[Line] -> List[Line]
'''Changes: `if (test) result`
into
'''Changes: `if (test) result`
into
`if (test) then
result
endif`'''

View File

@ -61,9 +61,9 @@ endif
EXE := $(shell egrep -ri '^\s*program' *.irp.f | cut -d'.' -f1)
ARCH = $(addprefix $(CURDIR)/,IRPF90_temp/irpf90.a)
.PHONY: clean all
.PHONY: clean all
all: $(EXE)
all: $(EXE)
define run
$(BUILD_SYSTEM_stripped) -C $(dir $(BUILD_FILE) ) -f $(notdir $(BUILD_FILE) ) $(1)
@ -89,6 +89,6 @@ $(BUILD_FILE): $(shell find . -maxdepth 2 -path ./IRPF90_temp -prune -o -name '
clean:
rm -f -- $(BUILD_FILE) $(EXE)
veryclean: clean
veryclean: clean
rm -rf IRPF90_temp/ IRPF90_man/ irpf90_entities dist tags

View File

@ -73,13 +73,13 @@ def parmap(f, it, parallel=False):
'''Parallel version of the std map function
The parallel flag is set to togle the // execusion
Note:
- We try to use the Mulprocesses map is possible else we use our own
- The order of the sequence if concerved
- We try to use the Mulprocesses map is possible else we use our own
- The order of the sequence if concerved
- Will use all the processesor possible
- We return a List
- The traceback is loose if an error occur but a Exception is raise.
- We return a List
- The traceback is loose if an error occur but a Exception is raise.
'''
if not parallel:
@ -95,12 +95,12 @@ def parmap(f, it, parallel=False):
# https://docs.python.org/2/library/pickle.html#what-can-be-pickled-and-unpickled
#from cPickle import PicklingError
#try:
# p = multiprocessing.Pool(nproc)
# l_res = p.map(f, it,nproc)
# p = multiprocessing.Pool(nproc)
# l_res = p.map(f, it,nproc)
#except PicklingError:
# pass
# pass
#else:
# return l_res
# return l_res
# ~!~!~!
# Parallelisation By Us
@ -129,10 +129,10 @@ def parmap(f, it, parallel=False):
'''Read a task from q_in, excute it, and store it in q_out
Note:
- We use 'F' and not 'f'.
- The for loop will break when stop_contition occur
- We get, and put an idx to allow the possibility of ordering afterward
- We store any exeception, to raise her afterward
- We use 'F' and not 'f'.
- The for loop will break when stop_contition occur
- We get, and put an idx to allow the possibility of ordering afterward
- We store any exeception, to raise her afterward
'''
for i, x in iter(q_in.get, stop_condition):
@ -192,7 +192,7 @@ def cached_file(filename, text):
'''Check if file locatte at filename containt the same data as text
Return:
True if data is the same, false otherwise
True if data is the same, false otherwise
'''
def digest(data):
@ -213,7 +213,7 @@ def lazy_write_file(filename, text, conservative=False, touch=False):
'''Write data lazily in filename location.
Note:
If convervative is set, we don't overwrite.
If convervative is set, we don't overwrite.
'''
if not os.path.exists(filename) or not cached_file(filename, text) and not conservative:
@ -286,7 +286,7 @@ def flatten(l_2d):
'''Construct a copy of the 2d list collapsed into one dimension.
Note:
- We collapse in a C-style fashion (row_major).
- We collapse in a C-style fashion (row_major).
'''
return [item for l_1d in l_2d for item in l_1d]
@ -322,9 +322,9 @@ def build_dim(l_dim, colons=False):
'''Contruct a valid fortran90 array dimension code from a list dimension
Exemple:
[4,8] -> (4,8) if not colons
[4,8] -> (:,:) if colons
[4,8] -> (4,8) if not colons
[4,8] -> (:,:) if colons
'''
if not l_dim:
return ""