├── .gitignore ├── LICENSE ├── README.rst ├── docs ├── Makefile ├── auto_make ├── conf.py ├── getting_started │ ├── backus.rst │ ├── baygon.rst │ ├── class.rst │ ├── getting_started.rst │ ├── host_python_package.rst │ ├── imports.rst │ ├── mean.rst │ ├── newspaper.rst │ ├── pre.rst │ ├── pycessor.rst │ ├── stat_package_structure │ ├── template.rst │ ├── testing_mean.rst │ └── variance.rst ├── index.rst ├── installation.rst ├── language_reference │ ├── allocation.rst │ ├── callback.rst │ ├── class.rst │ ├── coarray.rst │ ├── control_flow.rst │ ├── declaration.rst │ ├── function.rst │ ├── fytypes.rst │ ├── imports.rst │ ├── inline.rst │ ├── interface.rst │ ├── language_reference.rst │ ├── load.rst │ ├── operator.rst │ ├── pre.rst │ ├── print.rst │ ├── pycessor.rst │ ├── read.rst │ ├── syntax.rst │ ├── template.rst │ └── variable.rst ├── overview │ ├── contribute.rst │ ├── feature │ │ ├── class.rst │ │ ├── feature.rst │ │ ├── fytypes.rst │ │ ├── performance.rst │ │ ├── pycessor.rst │ │ ├── python_comfort.rst │ │ ├── python_syntax.rst │ │ ├── template.rst │ │ └── wrap_code.rst │ ├── installation.rst │ ├── license.rst │ ├── overview.rst │ ├── pre.rst │ └── support.rst └── toc.rst ├── example ├── select_real_kinds │ ├── a.fy │ └── select_real_kinds_test.py └── stat │ ├── setup.py │ └── stat │ ├── backus │ ├── backus.fy │ ├── brent.f90 │ ├── brent_consummer.fy │ ├── consummer.fy │ ├── fortran.py │ ├── ritchie.f90 │ └── so.py │ ├── baygon │ ├── baygon.fy │ ├── baygon_test.py │ ├── force_test.py │ ├── release_test.py │ └── verbose_test.py │ ├── class │ ├── class.fy │ └── class_test.py │ ├── imports │ ├── __init__.fy │ ├── imports.fy │ └── imports_test.py │ ├── mean │ ├── mean.fy │ └── mean_test.py │ ├── newspaper │ ├── print.fy │ ├── print_test.py │ ├── read.fy │ └── read_test.py │ ├── pycessor │ ├── pycessor.fy │ └── pycessor_test.py │ ├── template │ ├── class.fy │ ├── class_test.py │ ├── function.fy │ ├── function_test.py │ ├── package.fy │ ├── package_test.py │ └── quicksort.fy │ └── variance │ ├── explicit_spec_interpolation.fy │ ├── explicit_spec_interpolation_test.py │ ├── variance.fy │ ├── variance_spec.fy │ └── variance_test.py ├── exp ├── a ├── args_kwargs.py ├── class_method_at_runtime.py ├── ctype_crash │ ├── multiprocessing_ctype_from_address.py │ ├── multiprocessing_wall_pool.py │ ├── multiprocessing_wall_process.py │ └── multiprocessing_wall_process_fytype.py ├── ctypes_exp │ ├── a.f90 │ ├── ctypes_dict_access.py │ ├── global_int.py │ ├── numpy_char.py │ ├── numpy_char_2.py │ ├── numpy_exp.py │ ├── numpy_string_exp.py │ ├── numpy_string_multi_dimensional_exp.py │ ├── vector_passing.py │ ├── vector_passing_sub.py │ └── vector_string.py ├── def_order.py ├── dependency.py ├── detecting_traceback_open_close_error.py ├── dict_update.py ├── dill_pickling.py ├── dynamic_module.py ├── exception_handling.py ├── exception_handling_dynamic_creation.py ├── execution.py ├── fortran │ ├── a.f90 │ ├── array_syntax.py │ ├── class_abstract.py │ ├── class_overhead.py │ ├── class_procedure_overhead.py │ ├── class_tbp_overhead.py │ ├── compilation_linking │ │ ├── a.f90 │ │ ├── b.f90 │ │ ├── c.f90 │ │ └── comp_link_exp.py │ ├── if_with_integer.py │ ├── implicit_none.py │ ├── keyword_argument.py │ ├── module_def_order.py │ ├── module_import.py │ ├── module_with_empty_contains.py │ ├── name_mangling │ │ ├── a.f90 │ │ ├── b.f90 │ │ ├── name_mangling.py │ │ └── name_mangling_2.py │ ├── nested_type.py │ ├── object_name_given.py │ ├── print_to_file │ │ ├── a.f90 │ │ ├── print_empty.py │ │ ├── print_format.py │ │ ├── print_to_file.py │ │ └── print_vector.py │ ├── read_from_file │ │ ├── a.f90 │ │ ├── read_from_file.py │ │ ├── read_list_directed.py │ │ └── read_name_list.py │ ├── scope_access.py │ ├── scope_access_2.py │ ├── signalqq │ │ ├── a.f90 │ │ ├── signalqq.py │ │ ├── signalqq_2.py │ │ ├── signalqq_3.py │ │ ├── signalqq_linux_signal.py │ │ ├── signalqq_linux_signal_2.py │ │ ├── signalqq_linux_signal_escaping_ifcore.py │ │ └── signalqq_out_of_bound.py │ ├── size.py │ ├── submodule │ │ ├── 123.f90 │ │ ├── a.f90 │ │ ├── b.f90 │ │ ├── c.f90 │ │ ├── d.f90 │ │ └── out │ ├── submodule_2 │ │ ├── m1.f90 │ │ ├── m2.f90 │ │ ├── m3.f90 │ │ ├── m4.f90 │ │ ├── mx.f90 │ │ ├── submodule_compilation_order.py │ │ └── submodule_compilation_order_mx.py │ ├── submodule_3 │ │ ├── m1.f90 │ │ ├── m2.f90 │ │ ├── m3.f90 │ │ ├── m4.f90 │ │ ├── mx.f90 │ │ └── submodule_compilation_order.py │ ├── submodule_4 │ │ ├── compilation.py │ │ ├── m1.f90 │ │ └── m2.f90 │ ├── use_iso_c.py │ ├── var_init_in_function.py │ └── variable_access.py ├── fython │ ├── a.fy │ ├── exp_profiling.py │ ├── for_loop.py │ ├── less_equal.py │ └── mkl_import.py ├── getattr.py ├── globals_for_keyword.py ├── importing.py ├── package_name.py ├── ply │ ├── dalke_1.py │ ├── parsetab.py │ ├── ply_python.py │ └── python_grammar.bnf ├── property.py ├── py_exec_exp.py ├── py_exec_exp_2.py ├── py_import_exp.py ├── python_c3_class_mro │ ├── activate_state_mro_run.py │ ├── python_c3_mro_activate_state.py │ ├── python_c3_mro_anler.py │ └── python_c3_mro_anler_run.py ├── regex.py ├── regex_2.py ├── set.py ├── trying_globals_for_keyword.py ├── variable_with_same_name_as_module.py ├── wrapping_w_ctypes │ ├── a.f90 │ ├── b.c │ └── b.py └── wrapping_w_ctypes_2 │ ├── a.f90 │ ├── b.c │ └── b.py ├── fython ├── __init__.py ├── code │ ├── __init__.py │ ├── childcod.py │ ├── code.py │ └── linecod.py ├── config │ ├── __init__.py │ ├── buffer.py │ ├── compilation.py │ ├── data.py │ ├── debugging.py │ ├── exception.py │ ├── extension.py │ ├── gen_guid.py │ ├── get_frame_dir.py │ ├── language.py │ ├── md5.py │ ├── mkdir.py │ ├── path.py │ ├── pickling.py │ ├── shell.py │ ├── traceback.py │ ├── trim.py │ ├── url.py │ └── verbose.py ├── fml │ ├── __init__.py │ ├── add_interpolant.py │ ├── fml.py │ ├── fml_desc │ ├── fml_grammar │ ├── fml_lex.py │ ├── fml_parsetab.py │ └── fml_yacc.py ├── fytypes │ ├── __init__.py │ └── fytypes.py ├── hello │ ├── __init__.py │ ├── hello.fy │ └── hello.py ├── import_py │ ├── __init__.py │ ├── get_imported.py │ ├── import_py.py │ └── resolution ├── instruction │ ├── allocruc.py │ ├── breakruc.py │ ├── continueruc.py │ ├── criticalruc.py │ ├── deallocruc.py │ ├── elementruc.py │ ├── elifruc.py │ ├── elseruc.py │ ├── elwhereruc.py │ ├── errorruc.py │ ├── fopruc.py │ ├── forruc.py │ ├── ifruc.py │ ├── inlineruc.py │ ├── iruc.py │ ├── lexiruc.py │ ├── ompruc.py │ ├── passruc.py │ ├── printruc.py │ ├── privateruc.py │ ├── publicruc.py │ ├── readruc.py │ ├── returnruc.py │ ├── stopruc.py │ ├── syncruc.py │ ├── templateruc.py │ ├── whereruc.py │ ├── whileruc.py │ └── xipruc.py ├── interpolant │ └── interpolant.py ├── kompile │ ├── __init__.py │ ├── kompile.py │ └── stack.py ├── language ├── lex │ ├── __init__.py │ ├── config.py │ ├── find_lines.py │ ├── get_lexem.py │ ├── get_lexer.py │ ├── lex.py │ ├── line.py │ ├── mark_eopx.py │ ├── mark_invisible.py │ ├── mark_newlinex.py │ ├── mark_newlinex_parsetab.py │ ├── mark_opx_from_semix.py │ ├── mark_ropx.py │ ├── mark_unsafe_interpolation_lexem.py │ ├── mark_uopx.py │ ├── translate_fml.py │ └── unbalanced_parenthesis_locator.py ├── lexem │ ├── __init__.py │ ├── bdotx.py │ ├── bofx.py │ ├── bopx.py │ ├── colonx.py │ ├── commax.py │ ├── dedentx.py │ ├── eofx.py │ ├── eopx.py │ ├── funx.py │ ├── indentx.py │ ├── interpolationx.py │ ├── iopx.py │ ├── lcax.py │ ├── linefeedx.py │ ├── lkcax.py │ ├── lketx.py │ ├── lpackagex.py │ ├── lparx.py │ ├── lpcax.py │ ├── namex.py │ ├── newlinex.py │ ├── numberx.py │ ├── opx.py │ ├── rketx.py │ ├── ropx.py │ ├── rpackagex.py │ ├── rparx.py │ ├── semix.py │ ├── slicex.py │ ├── stringx.py │ ├── udotx.py │ └── uopx.py ├── load │ ├── __init__.py │ └── load.py ├── module │ ├── __init__.py │ ├── fortmodule.py │ ├── fymodule.py │ ├── get_module.py │ ├── restore_module.py │ ├── somodule.py │ └── sourcemodule.py ├── package_interpolation │ ├── __init__.py │ └── package_interpolation.py ├── printruc │ ├── __init__.py │ ├── close_file.py │ ├── csv_replace_fct.py │ ├── make_print.py │ ├── open_file.py │ ├── printruc.py │ ├── printruc_type.py │ ├── resolution │ └── resolve_modifier.py ├── pywrapper │ ├── __init__.py │ └── pywrapper.py ├── readruc │ ├── __init__.py │ ├── make_read.py │ ├── open_file.py │ ├── readruc.py │ └── resolution ├── resolution_convention ├── resolve │ ├── __init__.py │ ├── defr.py │ ├── genericr.py │ ├── resolution │ ├── resolve.py │ └── unaryr.py ├── spec │ ├── classpec.py │ ├── importpec.py │ ├── importpec_resolution │ ├── interfacepec.py │ ├── routpec.py │ └── varpec.py ├── symbol │ ├── __init__.py │ ├── bitbol.py │ ├── dotbol.py │ ├── enumbol.py │ ├── funbol.py │ ├── ibol.py │ ├── ketbol.py │ ├── opbol.py │ ├── packagebol.py │ ├── parbol.py │ ├── semibol.py │ ├── slicebol.py │ └── strresolver.py ├── test │ ├── __init__.py │ ├── alltest.py │ ├── callback │ │ ├── callback_test.py │ │ └── fy_caller.fy │ ├── classpec │ │ ├── a.fy │ │ ├── class_nested_test.py │ │ ├── class_self_test.py │ │ ├── classpec_all_1_test.py │ │ ├── classpec_all_2_test.py │ │ ├── classpec_field_test.py │ │ ├── classpec_inheritance_test.py │ │ ├── classpec_method_test.py │ │ ├── classpec_mro_test.py │ │ ├── classpec_pget_pset_test.py │ │ ├── classpec_pget_test.py │ │ ├── classpec_pset_test.py │ │ └── classpec_spec_interpolation_test.py │ ├── coarray │ │ ├── a.fy │ │ ├── corray_1_test.py │ │ ├── corray_2_test.py │ │ ├── corray_3_test.py │ │ └── corray_4_test.py │ ├── config │ │ ├── a │ │ │ └── b │ │ │ │ └── c │ │ │ │ └── d │ │ │ │ └── a.py │ │ ├── b │ │ │ └── b.py │ │ ├── c.py │ │ ├── d.py │ │ ├── get_frame_dir_1_test.py │ │ ├── get_frame_dir_2_test.py │ │ └── trim_test.py │ ├── dotbol │ │ ├── a.fy │ │ ├── dotbol_1_test.py │ │ ├── dotbol_2_test.py │ │ ├── dotbol_3_test.py │ │ ├── dotbol_4_test.py │ │ └── dotbol_5_test.py │ ├── file │ ├── fml │ │ ├── basic_test.py │ │ └── multiline_test.py │ ├── fortran_compiler │ │ ├── a.fy │ │ ├── gfortran_test.py │ │ ├── ifort_test.py │ │ └── set_compiler_test.py │ ├── funbol │ │ ├── a.fy │ │ ├── funbol_test.py │ │ └── uopx_test.py │ ├── fython_module_access │ │ ├── a.fy │ │ ├── subroutine_test.py │ │ └── variable_test.py │ ├── fytypes │ │ ├── character_test.py │ │ ├── integer_test.py │ │ └── real_test.py │ ├── hello │ │ └── hello_test.py │ ├── imp.py │ ├── importpec_fort │ │ ├── a.f90 │ │ ├── b.fy │ │ ├── c.fy │ │ ├── fort_funbol_intrinsic_import_test.py │ │ ├── fort_namespace_import_test.py │ │ ├── fort_namex_intrinsic_import_test.py │ │ ├── fort_slice_import_test.py │ │ └── fort_star_import_test.py │ ├── importpec_fy │ │ ├── a.fy │ │ ├── b.fy │ │ ├── fy_alias_namespace_import_test.py │ │ ├── fy_namex_aliased_namespace_import_test.py │ │ ├── fy_slice_import_1_test.py │ │ ├── fy_slice_import_2_test.py │ │ ├── fy_star_import_test.py │ │ ├── import_throw_test.py │ │ └── temp_package │ │ │ └── __init__.fy │ ├── importpec_py │ │ ├── a.py │ │ ├── b.fy │ │ ├── c │ │ │ └── a.py │ │ ├── py_namespace_alias_import_test.py │ │ ├── py_namespace_import_test.py │ │ ├── py_slice_import_1_test.py │ │ ├── py_slice_import_2_test.py │ │ └── py_star_import_test.py │ ├── importpec_so │ │ ├── a.f90 │ │ ├── b.fy │ │ └── so_star_import_test.py │ ├── inlineruc │ │ ├── a.fy │ │ ├── inlineruc_class_1_test.py │ │ ├── inlineruc_class_test.py │ │ ├── inlineruc_module_test.py │ │ ├── inlineruc_rout_1_test.py │ │ ├── inlineruc_rout_2_test.py │ │ └── inlineruc_var_test.py │ ├── instruction │ │ ├── a.fy │ │ ├── allocruc_deallocruc_test.py │ │ ├── elementruc_keyword_test.py │ │ ├── forruc_test.py │ │ ├── ifruc_test.py │ │ ├── iruc_test.py │ │ ├── ompruc_test.py │ │ ├── privateruc_test.py │ │ ├── publicruc_test.py │ │ ├── stringx_test.py │ │ ├── various_test.py │ │ ├── whereruc_test.py │ │ └── whileruc_test.py │ ├── interfacepec │ │ ├── a.fy │ │ └── interfacepec_test.py │ ├── interpolation │ │ ├── a.fy │ │ ├── for_loop_test.py │ │ ├── indent_test.py │ │ ├── inline_2_test.py │ │ └── inline_test.py │ ├── lex │ │ ├── a.fy │ │ ├── comment_eof_test.py │ │ ├── eof_test.py │ │ ├── indent start: │ │ ├── indent_1_test.py │ │ ├── indent_2_test.py │ │ ├── indent_test.py │ │ ├── linefeed_test.py │ │ └── trailing_tab_test.py │ ├── lexiruc │ │ ├── a.fy │ │ ├── lexiruc_1_test.py │ │ ├── lexiruc_2_test.py │ │ ├── lexiruc_3_test.py │ │ ├── lexiruc_4_test.py │ │ ├── lexiruc_classpec_2_test.py │ │ └── lexiruc_classpec_test.py │ ├── out │ ├── packagebol │ │ ├── a.fy │ │ ├── b.fy │ │ ├── c.fy │ │ ├── packagebol_1_test.py │ │ ├── packagebol_2_test.py │ │ └── packagebol_3_test.py │ ├── printruc │ │ ├── a.fy │ │ ├── file │ │ ├── out │ │ ├── printruc_3_test.py │ │ ├── printruc_c_test.py │ │ ├── printruc_childcod_2_test.py │ │ ├── printruc_childcod_test.py │ │ ├── printruc_dotbol_test.py │ │ ├── printruc_json_test.py │ │ ├── printruc_multiline_test.py │ │ ├── printruc_test.py │ │ ├── printruc_vc_format_test.py │ │ └── string_expr_test.py │ ├── readruc │ │ ├── a.fy │ │ └── readruc_test.py │ ├── restore │ │ ├── a.fy │ │ ├── b.fy │ │ ├── restore_1_test.py │ │ └── restore_2_test.py │ ├── routpec │ │ ├── a.fy │ │ ├── automatic_argument_completion_test.py │ │ ├── routpec_deferred_name_test.py │ │ ├── routpec_nested_test.py │ │ ├── routpec_test.py │ │ ├── spec_interpolation_1_test.py │ │ └── spec_interpolation_2_test.py │ ├── shell.py │ ├── symbol │ │ ├── a.fy │ │ ├── semibol_test.py │ │ └── slicebol_test.py │ ├── test_helper │ ├── traceback │ │ ├── a.fy │ │ ├── traceback_2_test.py │ │ └── traceback_test.py │ ├── varpec │ │ ├── a.fy │ │ ├── varpec_1_test.py │ │ ├── varpec_2_test.py │ │ ├── varpec_3_test.py │ │ ├── varpec_4_test.py │ │ └── varpec_test.py │ └── writer.py ├── traceback │ ├── __init__.py │ ├── frame.py │ ├── open_close_line.py │ ├── stack_trace.py │ └── traceback.fy ├── unit │ ├── __init__.py │ ├── lexem.py │ └── unit.py └── yacc │ ├── __init__.py │ ├── grammar │ ├── yacc.py │ └── yacc_parsetab.py ├── setup.py └── sublime_syntax_definition ├── fython.YAML-tmLanguage └── fython.tmLanguage /.gitignore: -------------------------------------------------------------------------------- 1 | z_* 2 | z_*/ 3 | 4 | *~ 5 | .fuse* 6 | 7 | *.egg*/ 8 | build/ 9 | dist/ 10 | 11 | /docs/_*/ 12 | 13 | __pycache__/ 14 | 15 | 16 | *.o 17 | *.so 18 | *.mod 19 | *.smod 20 | *.pyc 21 | *.b 22 | *.out 23 | *.tmp -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2015 Nicolas Essis-Breton 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /docs/auto_make: -------------------------------------------------------------------------------- 1 | sphinx-autobuild . _build/html 2 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | import shlex 4 | 5 | source_suffix = '.rst' 6 | 7 | master_doc = 'index' 8 | 9 | project = 'Fython' 10 | author = 'Nicolas Essis-Breton' 11 | html_show_sphinx = 0 12 | html_show_copyright = 1 13 | copyright = '2015, Nicolas Essis-Breton. Released under an Apache License 2.0' 14 | 15 | version = '1.0 alpha' 16 | release = version 17 | 18 | on_rtd = os.environ.get('READTHEDOCS', None) == 'True' 19 | if not on_rtd: 20 | import sphinx_rtd_theme 21 | html_theme = 'sphinx_rtd_theme' 22 | html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] 23 | print(sphinx_rtd_theme.get_html_theme_path()) -------------------------------------------------------------------------------- /docs/getting_started/class.rst: -------------------------------------------------------------------------------- 1 | Class 2 | ------- 3 | 4 | Similar to Python, the first argument to any class method must be ``self``. 5 | You can use any name for the self argument, 6 | the only rule is that the first argument is the self argument. 7 | 8 | **class.fy** 9 | 10 | .. literalinclude:: ../../example/stat/stat/class/class.fy 11 | 12 | Inheritance and spec interpolation are also possible. 13 | See the language section for more details. 14 | 15 | **class_test.py** 16 | 17 | .. literalinclude:: ../../example/stat/stat/class/class_test.py 18 | -------------------------------------------------------------------------------- /docs/getting_started/getting_started.rst: -------------------------------------------------------------------------------- 1 | Getting Started 2 | =============== 3 | 4 | .. include:: pre.rst 5 | 6 | .. include:: host_python_package.rst 7 | 8 | .. include:: mean.rst 9 | 10 | .. include:: testing_mean.rst 11 | 12 | .. include:: variance.rst 13 | 14 | .. include:: newspaper.rst 15 | 16 | .. include:: class.rst 17 | 18 | .. include:: imports.rst 19 | 20 | .. include:: pycessor.rst 21 | 22 | .. include:: baygon.rst 23 | 24 | .. include:: template.rst 25 | 26 | .. include:: backus.rst 27 | -------------------------------------------------------------------------------- /docs/getting_started/host_python_package.rst: -------------------------------------------------------------------------------- 1 | The Host Python package 2 | --------------------------- 3 | 4 | First, we create the folder structure for the Python package 5 | where our Fython package will reside 6 | 7 | .. literalinclude:: stat_package_structure 8 | :language: shell 9 | 10 | The content of ``setup.py`` is 11 | 12 | .. literalinclude:: ../../example/stat/setup.py 13 | :language: python 14 | 15 | We register the package in Python with 16 | 17 | .. code-block:: shell 18 | 19 | python3 setup.py develop 20 | 21 | -------------------------------------------------------------------------------- /docs/getting_started/mean.rst: -------------------------------------------------------------------------------- 1 | Mean 2 | ---- 3 | 4 | The Mean module illustrate the basic semantic of Fython. 5 | We write three kind of mean functions. 6 | 7 | In Fython, the arguments of a function must have the intent attribute 8 | ``in``, ``out`` or ``inout``. 9 | 10 | **mean.fy** 11 | 12 | .. literalinclude:: ../../example/stat/stat/mean/mean.fy -------------------------------------------------------------------------------- /docs/getting_started/pre.rst: -------------------------------------------------------------------------------- 1 | Any Fython package must be part of a 2 | Python package. 3 | This way Fython can leverage Python automatic package detection system. 4 | 5 | In this tutorial, we will create a Fython package 6 | ``stat`` that illustrates most of Fython Functionalities. 7 | 8 | The code for this tutorial is in 9 | `fython/example/stat `_. 10 | -------------------------------------------------------------------------------- /docs/getting_started/stat_package_structure: -------------------------------------------------------------------------------- 1 | stat/ 2 | 3 | setup.py 4 | 5 | stat/ 6 | 7 | mean/ 8 | mean.fy 9 | mean_test.py 10 | 11 | variance/ 12 | variance.fy 13 | variance_spec.fy 14 | variance_test.py 15 | 16 | newspaper/ 17 | print.fy 18 | print_test.py 19 | read.fy 20 | read_test.fy 21 | 22 | class/ 23 | class.py 24 | class_test.fy 25 | 26 | imports/ 27 | __init__.fy 28 | imports.fy 29 | imports_test.fy 30 | 31 | pycessor/ 32 | pycessor.fy 33 | pycessor_test.py 34 | 35 | baygon/ 36 | baygon.fy 37 | baygon_test.py 38 | force_test.py 39 | release_test.py 40 | verbose_test.py 41 | 42 | backus/ 43 | fortran.py 44 | so.py 45 | -------------------------------------------------------------------------------- /docs/getting_started/testing_mean.rst: -------------------------------------------------------------------------------- 1 | Testing Mean 2 | ------------ 3 | 4 | Let's test drive our mean module 5 | 6 | **mean.py** 7 | 8 | .. literalinclude:: ../../example/stat/stat/mean/mean_test.py 9 | :language: python 10 | 11 | We did not attempt to access the constant ``bolztman``. 12 | This is because variable defined with as constant 13 | are not accessible from fython. 14 | 15 | That's it for the mean module. 16 | Now you can write a standalone Fython module. 17 | In preparation for those days where you need more, let's see the variance module. 18 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. include:: overview/overview.rst 2 | 3 | .. include:: toc.rst -------------------------------------------------------------------------------- /docs/language_reference/allocation.rst: -------------------------------------------------------------------------------- 1 | Allocation 2 | ---------- 3 | 4 | Memory is allocated and deallocated with the ``alloc`` and ``dealloc`` keyword 5 | 6 | .. code-block:: fython 7 | 8 | alloc: x y(n) z 9 | 10 | alloc(n): 11 | x 12 | y 13 | z(m) 14 | 15 | dealloc: x y z 16 | 17 | When the keyword ``alloc`` has an argument, it is used 18 | as the default size for any variable where no size is specified. -------------------------------------------------------------------------------- /docs/language_reference/coarray.rst: -------------------------------------------------------------------------------- 1 | Coarray 2 | --------- 3 | 4 | A coarray is defined by specifying its codimension in bracket 5 | 6 | .. code-block:: fython 7 | 8 | real x[*] 9 | real y(10)[*] 10 | 11 | A coarray is accessed with the slice notation 12 | 13 | .. code-block:: fython 14 | 15 | x = 1 # this_image() x 16 | x[2] = 2 # x on image 2 17 | 18 | y[1] = 1 # this_image() y 19 | y[:][2] = 1 # y on image 2 20 | 21 | To use coarray in Fython, you need to set the compiler to use with the 22 | ``set_compiler`` function 23 | 24 | .. code-block:: python 25 | 26 | #>>> 27 | from fython import * 28 | 29 | set_compiler( 30 | cmd = 'ifort', 31 | prefix = '', 32 | infix = '_mp_', 33 | suffix = '_', 34 | debug = '-coarray -coarray-num-images=5', 35 | release = '-coarray -coarray-num-images=5', 36 | error_regex = 'error:', 37 | ) 38 | 39 | m = load('.coarray_test') 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /docs/language_reference/declaration.rst: -------------------------------------------------------------------------------- 1 | Declaration 2 | ----------- 3 | 4 | The declarations order follows Fortran convention. 5 | Variables, Classes and interface declaration shoud appear first 6 | within a scoping unit, then functions. 7 | 8 | A scoping unit is the entire module, 9 | the body of a class, or the body of a function. 10 | 11 | For this release, nested class or nested function are not supported. -------------------------------------------------------------------------------- /docs/language_reference/inline.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicolasessisbreton/fython/988f5a94cee8b16b0000501a22239195c73424a1/docs/language_reference/inline.rst -------------------------------------------------------------------------------- /docs/language_reference/interface.rst: -------------------------------------------------------------------------------- 1 | Interface 2 | --------- 3 | 4 | An interface is declared with the interface keyword 5 | 6 | .. code-block:: fython 7 | 8 | interface: 9 | def f: 10 | real in x 11 | real res r 12 | 13 | To facilitate the definition of C procedure 14 | the modifier ``iso(c)`` can be used 15 | 16 | .. code-block:: fython 17 | 18 | interface: 19 | def iso(c) f: 20 | real in x 21 | 22 | The ``iso(c)`` modifier can be used on any function declaration 23 | and is not restricted to interface declaration. 24 | The effect of the modifier is to produce 25 | 26 | .. code-block:: fortran 27 | 28 | !!! 29 | subroutine f(x) bind(c) 30 | use iso_c_binding 31 | real, intent(in) :: x 32 | end subroutine 33 | 34 | 35 | -------------------------------------------------------------------------------- /docs/language_reference/language_reference.rst: -------------------------------------------------------------------------------- 1 | Language Reference 2 | ================== 3 | 4 | .. include:: pre.rst 5 | 6 | .. include:: syntax.rst 7 | 8 | .. include:: imports.rst 9 | 10 | .. include:: declaration.rst 11 | 12 | .. include:: operator.rst 13 | 14 | .. include:: variable.rst 15 | 16 | .. include:: coarray.rst 17 | 18 | .. include:: function.rst 19 | 20 | .. include:: interface.rst 21 | 22 | .. include:: class.rst 23 | 24 | .. include:: allocation.rst 25 | 26 | .. include:: control_flow.rst 27 | 28 | .. include:: print.rst 29 | 30 | .. include:: read.rst 31 | 32 | .. include:: fytypes.rst 33 | 34 | .. include:: callback.rst 35 | 36 | .. include:: load.rst 37 | 38 | .. include:: pycessor.rst 39 | 40 | .. include:: template.rst 41 | 42 | -------------------------------------------------------------------------------- /docs/language_reference/operator.rst: -------------------------------------------------------------------------------- 1 | Operator 2 | -------- 3 | 4 | Fython has the augmented assignment operators, 5 | the logical operator, the bitwise operators, 6 | and the pointer operator. 7 | 8 | .. code-block:: fython 9 | 10 | x += 1 11 | x -= 1 12 | x *= 2 13 | x /= 2 14 | 15 | x <<= 1 16 | x &= 1 17 | x ^= 1 18 | x |= 1 19 | x >>= 1 20 | 21 | 22 | x < <= == != => > y # this is an invalid syntax 23 | 24 | x and y or b not c 25 | 26 | x >> 1 + y << 4 27 | 28 | x => y # pointer 29 | 30 | The min and max operator are often convenient. 31 | 32 | .. code-block:: fython 33 | 34 | x ++= y # x = max(x, y) 35 | x --= y # x = min(x, y) -------------------------------------------------------------------------------- /docs/language_reference/pre.rst: -------------------------------------------------------------------------------- 1 | This section describes in details the Fython language. 2 | 3 | In code examples 4 | 5 | - shell code is indicated with a dollar ``$`` 6 | - Python code is indicated with triple quote ``>>>`` 7 | - Fortran code is indicated with triple bangs ``!!!`` 8 | 9 | When no mention of the language is made, 10 | assume it is Fython. 11 | 12 | The term shared library is often simply referenced by ``so``. -------------------------------------------------------------------------------- /docs/language_reference/template.rst: -------------------------------------------------------------------------------- 1 | Template 2 | --------- 3 | 4 | A function template is defined with the ``def`` statement 5 | 6 | .. code-block:: python 7 | 8 | def f: 9 | T in x 10 | T res r 11 | r += x 12 | 13 | def g = f(T=real) 14 | 15 | To templatize a whole package use the import statement 16 | 17 | .. code-block:: fython 18 | 19 | import quicksort(*) 20 | ||type_provide=stat.mean, target_class=KMean|| 21 | 22 | Package interpolation can also be multilines 23 | 24 | .. code-block:: fython 25 | 26 | import quicksort(*) 27 | || 28 | type_provide = stat.mean 29 | target_class = KMean 30 | 31 | || 32 | 33 | To disable package interpolation during a package import, 34 | use the ``asis`` modifier. 35 | 36 | .. code-block:: fython 37 | 38 | import asis random 39 | 40 | This is usefull to avoid further interpolation during an ongoing package interpolation. 41 | -------------------------------------------------------------------------------- /docs/overview/contribute.rst: -------------------------------------------------------------------------------- 1 | Contribute 2 | ----------- 3 | 4 | Any contribution is welcomed. 5 | The source is avalaible on `github `_. 6 | -------------------------------------------------------------------------------- /docs/overview/feature/class.rst: -------------------------------------------------------------------------------- 1 | Class 2 | ----- 3 | 4 | define python style class 5 | 6 | inheritance follow -------------------------------------------------------------------------------- /docs/overview/feature/feature.rst: -------------------------------------------------------------------------------- 1 | Features 2 | -------- 3 | 4 | .. include:: overview/feature/performance.rst 5 | 6 | .. include:: overview/feature/python_syntax.rst 7 | 8 | .. include:: overview/feature/python_comfort.rst 9 | 10 | .. include:: overview/feature/pycessor.rst 11 | 12 | .. include:: overview/feature/template.rst 13 | 14 | .. include:: overview/feature/fytypes.rst 15 | 16 | .. include:: overview/feature/wrap_code.rst 17 | -------------------------------------------------------------------------------- /docs/overview/feature/performance.rst: -------------------------------------------------------------------------------- 1 | Performance 2 | ~~~~~~~~~~~ 3 | 4 | The Fython language is a syntaxtic binding for the Fortran language. 5 | Any instruction you write in Fython is 6 | translated to Fortran, with the exact same meaning. 7 | The translated Fortran code is then compiled to machine instructions. 8 | There is no boiler plate code generation or LLVM in between. 9 | What you code is what you run (WYCIWYR). 10 | -------------------------------------------------------------------------------- /docs/overview/feature/pycessor.rst: -------------------------------------------------------------------------------- 1 | Pycessor 2 | ~~~~~~~~ 3 | 4 | Use Python to easily do your preprocessing magic 5 | 6 | .. code-block:: fython 7 | 8 | import numpy 9 | 10 | real pi = |numpy.pi| 11 | 12 | # lazy initialization of exotic random variate 13 | real v(1e3) 14 | 15 | | 16 | for i in range(1000): 17 | write('v[i] = {:f}'.format(numpy.random.uniform())) 18 | 19 | | 20 | 21 | Any expression enclosed in bars is evaluated against the imported Python module. 22 | The return value of a pycession can be any valid Fython code. -------------------------------------------------------------------------------- /docs/overview/feature/python_syntax.rst: -------------------------------------------------------------------------------- 1 | Python Syntax 2 | ~~~~~~~~~~~~~ 3 | 4 | Fython allows to write Fortran code 5 | with Python syntax. 6 | No messy ``end xyz`` everywhere. 7 | No more ``%`` for object attributes, 8 | enjoy the ``car.color`` notation. 9 | No more concatenation puzzle, 10 | use multiline string ``"""xyz"""``. 11 | No more ``&`` for multiline instruction, 12 | simply use parenthesis 13 | 14 | .. code-block:: fython 15 | 16 | many( 17 | arguments, 18 | and, 19 | more, 20 | ) 21 | 22 | Write class with class, enjoying attribute getter and setter. 23 | 24 | .. code-block:: fython 25 | 26 | class Nucleon(Atom): 27 | real position = 1 28 | int weight = 10 29 | 30 | def pget fission: 31 | self inout 32 | self.weight /= 2 33 | 34 | Nucleon n 35 | n.fission 36 | print 'weight {:n.weight}' -------------------------------------------------------------------------------- /docs/overview/feature/template.rst: -------------------------------------------------------------------------------- 1 | Template 2 | ~~~~~~~~ 3 | 4 | Overload of a function or a class can be created with template interpolation 5 | 6 | .. code-block:: fython 7 | 8 | def temp f: 9 | T in x 10 | T res r 11 | r = x + 10 12 | 13 | def g = f(T=real) 14 | 15 | When this is not sufficient, a whole package can be templatized 16 | 17 | **quicksort.fy** 18 | 19 | .. code-block:: fython 20 | 21 | import type_provider(target_class=T) 22 | 23 | def quicksort(x): 24 | T x(:) 25 | int i 26 | int res r 27 | 28 | r = 0 29 | for i in [1, size(x)]: 30 | r += x[i].less_than(x[i+1]) 31 | 32 | 33 | **consumer.fy** 34 | 35 | .. code-block:: fython 36 | 37 | import quicksort(*) 38 | ||type_provider = maxwell, target_class = Atom || 39 | 40 | int r 41 | Atom a(10) 42 | r = quicksort(a) 43 | -------------------------------------------------------------------------------- /docs/overview/installation.rst: -------------------------------------------------------------------------------- 1 | Installation 2 | ------------ 3 | 4 | .. code-block:: shell 5 | 6 | git clone https://github.com/nicolasessisbreton/fython 7 | cd fython 8 | python3 setup.py install 9 | 10 | **Dependencies**: 11 | 12 | * Any Fortran compiler 13 | * `Python 3 `_ 14 | * `PLY `_ 15 | * `Tabulate `_ 16 | 17 | **Platform**: 18 | 19 | Linux -------------------------------------------------------------------------------- /docs/overview/license.rst: -------------------------------------------------------------------------------- 1 | License 2 | ------- 3 | 4 | Fython is released under an `Apache License 2.0 `_. 5 | -------------------------------------------------------------------------------- /docs/overview/overview.rst: -------------------------------------------------------------------------------- 1 | Overview 2 | ======== 3 | 4 | .. include:: overview/pre.rst 5 | 6 | .. include:: overview/feature/feature.rst 7 | 8 | .. include:: overview/installation.rst 9 | 10 | .. include:: overview/contribute.rst 11 | 12 | .. include:: overview/support.rst 13 | 14 | .. include:: overview/license.rst -------------------------------------------------------------------------------- /docs/overview/pre.rst: -------------------------------------------------------------------------------- 1 | Fython is Fortran with a Python syntax. 2 | If performance requirements 3 | periodically forces you out of Python, 4 | with Fython you won't feel it 5 | 6 | **hello.fy** 7 | 8 | .. code-block:: fython 9 | 10 | real offset = 0 11 | 12 | def fast_sum: 13 | real in v(1e9) 14 | real res r 15 | 16 | r = 0 17 | for i in [1, 1e9]: 18 | r += v[i] + offset 19 | 20 | print 'The sum is {:sum(v)}' 21 | 22 | The loop above is automatically parallelized 23 | by the Fortran compiler that powers Fython. 24 | 25 | Usage in Python is as simple as 26 | 27 | **hello.py** 28 | 29 | .. code-block:: python 30 | 31 | import fython 32 | import numpy as np 33 | 34 | hello = fython.load('.hello') 35 | 36 | offset = hello.offset() 37 | v = fython.Real(shape=[1e9]) 38 | 39 | offset = 10 40 | v[:] = np.random.uniform(0, 1, 1e9) 41 | 42 | hello.fast_sum(v) 43 | -------------------------------------------------------------------------------- /docs/overview/support.rst: -------------------------------------------------------------------------------- 1 | Support 2 | ------- 3 | 4 | Questions, suggestions, improvements or bug fixes? 5 | Join the discussion `here `_. 6 | -------------------------------------------------------------------------------- /docs/toc.rst: -------------------------------------------------------------------------------- 1 | .. toctree:: 2 | :hidden: 3 | 4 | overview/overview 5 | installation 6 | getting_started/getting_started 7 | language_reference/language_reference -------------------------------------------------------------------------------- /example/select_real_kinds/a.fy: -------------------------------------------------------------------------------- 1 | # taken from: https://gcc.gnu.org/onlinedocs/gfortran/SELECTED_005fREAL_005fKIND.html 2 | 3 | integer cons p6 = selected_real_kind(6) 4 | integer cons p10r100 = selected_real_kind(10,100) 5 | integer cons r400 = selected_real_kind(r=400) 6 | 7 | real(kind=p6) x 8 | real(kind=p10r100) y 9 | real(kind=r400) z 10 | 11 | print '{:precision(x)} {:range(x)}' 12 | print '{:precision(y)} {:range(y)}' 13 | print '{:precision(z)} {:range(z)}' -------------------------------------------------------------------------------- /example/select_real_kinds/select_real_kinds_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | # taken from: https://gcc.gnu.org/onlinedocs/gfortran/SELECTED_005fREAL_005fKIND.html 4 | 5 | int cons p6 = selected_real_kind(6) 6 | int cons p10r100 = selected_real_kind(10,100) 7 | int cons r400 = selected_real_kind(r=400) 8 | 9 | real(kind=p6) x 10 | real(kind=p10r100) y 11 | real(kind=r400) z 12 | 13 | print '{:precision(x)} {:range(x)}' 14 | print '{:precision(y)} {:range(y)}' 15 | print '{:precision(z)} {:range(z)}' 16 | """ 17 | 18 | from fython.test import * 19 | 20 | shell('rm -rf a/ a.* b.*') 21 | 22 | writer(s) 23 | 24 | w = load('.a', release=1, verbose=0, run_main=1) 25 | print(open(w.module.url.fortran_path, 'r').read()) 26 | -------------------------------------------------------------------------------- /example/stat/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | setup( 4 | packages = find_packages(), 5 | name = 'stat', 6 | ) 7 | -------------------------------------------------------------------------------- /example/stat/stat/backus/backus.fy: -------------------------------------------------------------------------------- 1 | import .ritchie(*) 2 | 3 | c = 20 4 | 5 | compile() -------------------------------------------------------------------------------- /example/stat/stat/backus/brent.f90: -------------------------------------------------------------------------------- 1 | module brent 2 | integer, parameter :: tolerance = 1e-3 3 | 4 | contains 5 | 6 | function root(x) result(r) 7 | real, dimension(10) :: x 8 | real :: r 9 | integer :: i 10 | 11 | r = 0 12 | 13 | do i = 1, 10 14 | r = r + x(i) 15 | end do 16 | 17 | end function 18 | 19 | end module 20 | -------------------------------------------------------------------------------- /example/stat/stat/backus/brent_consummer.fy: -------------------------------------------------------------------------------- 1 | 2 | import .brent(*) 3 | 4 | real x(10) = 1 5 | 6 | print 'brent says {:root(x)}' -------------------------------------------------------------------------------- /example/stat/stat/backus/consummer.fy: -------------------------------------------------------------------------------- 1 | 2 | import .brent(*) 3 | 4 | real x(10) = 1 5 | 6 | print 'brent says {:root(x)}' -------------------------------------------------------------------------------- /example/stat/stat/backus/fortran.py: -------------------------------------------------------------------------------- 1 | from fython import * 2 | 3 | writer(""" 4 | .brent.f90 5 | module brent 6 | integer, parameter :: tolerance = 1e-3 7 | 8 | contains 9 | 10 | function root(x) result(r) 11 | real, dimension(10) :: x 12 | real :: r 13 | integer :: i 14 | 15 | r = 0 16 | 17 | do i = 1, 10 18 | r = r + x(i) 19 | end do 20 | 21 | end function 22 | 23 | end module 24 | 25 | 26 | .consummer.fy 27 | 28 | import .brent(*) 29 | 30 | real x(10) = 1 31 | 32 | print 'brent says {:root(x)}' 33 | """) 34 | 35 | load('.consummer') -------------------------------------------------------------------------------- /example/stat/stat/backus/ritchie.f90: -------------------------------------------------------------------------------- 1 | module ritchie 2 | real, bind(c) :: c = 10 3 | 4 | contains 5 | 6 | subroutine compile() bind(c) 7 | write(*, *) 'c is ', c 8 | end subroutine 9 | 10 | end module -------------------------------------------------------------------------------- /example/stat/stat/backus/so.py: -------------------------------------------------------------------------------- 1 | import os 2 | from fython import * 3 | 4 | writer(""" 5 | .ritchie.f90 6 | module ritchie 7 | real, bind(c) :: c = 10 8 | 9 | contains 10 | 11 | subroutine compile() bind(c) 12 | write(*, *) 'c is ', c 13 | end subroutine 14 | 15 | end module 16 | 17 | .backus.fy 18 | import .ritchie(*) 19 | 20 | c = 20 21 | 22 | compile() 23 | """) 24 | 25 | os.system('gfortran ritchie.f90 -shared -fpic -o ritchie.so') 26 | 27 | load('.backus') -------------------------------------------------------------------------------- /example/stat/stat/baygon/baygon.fy: -------------------------------------------------------------------------------- 1 | def boom: 2 | real x 3 | subboom(x) 4 | 5 | def subboom: 6 | real inout x 7 | x = 1 / 0 8 | -------------------------------------------------------------------------------- /example/stat/stat/baygon/baygon_test.py: -------------------------------------------------------------------------------- 1 | from fython import * 2 | 3 | m = load('.baygon') 4 | 5 | # shocking hazard 6 | m.boom() -------------------------------------------------------------------------------- /example/stat/stat/baygon/force_test.py: -------------------------------------------------------------------------------- 1 | from fython import * 2 | 3 | m = load('.baygon', force=1) 4 | 5 | m.boom() -------------------------------------------------------------------------------- /example/stat/stat/baygon/release_test.py: -------------------------------------------------------------------------------- 1 | from fython import * 2 | 3 | m = load('.baygon', release=1) 4 | 5 | m.boom() 6 | 7 | print('a bad idea here as the division by zero will go unseen') -------------------------------------------------------------------------------- /example/stat/stat/baygon/verbose_test.py: -------------------------------------------------------------------------------- 1 | from fython import * 2 | 3 | m = load('.baygon') 4 | 5 | m.verbose() 6 | 7 | m.boom() -------------------------------------------------------------------------------- /example/stat/stat/class/class.fy: -------------------------------------------------------------------------------- 1 | class Magnetism: 2 | real maxwell = 8 3 | real pointer tesla(:) => null() 4 | real allocatable bohr(:) 5 | 6 | def energy: 7 | self in # first argument is always self 8 | real res r 9 | r = self.maxwell + sum(self.tesla) 10 | 11 | def pget courant: 12 | self in 13 | real res r 14 | r = self.maxwell + sum(self.bohr) 15 | 16 | def pset courant: 17 | s inout # any name is allow for the self argument 18 | real in value 19 | s.bohr = value 20 | 21 | real target x(10) = 1 22 | Magnetism m 23 | 24 | m.tesla => x # pointer assignment 25 | print 'energy {:m.energy()}' 26 | 27 | # happy allocation 28 | alloc m.bohr(8) 29 | print 'bohr {v:m.bohr}' 30 | 31 | # getter/setter 32 | m.courant = 4. 33 | print 'courant {:m.courant}' 34 | 35 | # happy deallocation 36 | dealloc m.bohr 37 | -------------------------------------------------------------------------------- /example/stat/stat/class/class_test.py: -------------------------------------------------------------------------------- 1 | from fython import * 2 | 3 | m = load('.class') -------------------------------------------------------------------------------- /example/stat/stat/imports/__init__.fy: -------------------------------------------------------------------------------- 1 | import iso_c_binding(*) 2 | print 'package export' -------------------------------------------------------------------------------- /example/stat/stat/imports/imports.fy: -------------------------------------------------------------------------------- 1 | import ..mean.mean(*) 2 | 3 | import ..variance.variance = v 4 | 5 | import ..newspaper.print( 6 | i = counter, # aliasing name i 7 | x, # no alias 8 | ) 9 | 10 | import ..imports = package_import # when the directory as a __init__.fy file 11 | 12 | print 'mean boltzman {:boltzman}' 13 | 14 | counter = 1 15 | v.variance(1., 2., 3., x[counter]) 16 | print 'variance {:x[counter]}' 17 | 18 | # triggering package main code 19 | package_import.main() 20 | -------------------------------------------------------------------------------- /example/stat/stat/imports/imports_test.py: -------------------------------------------------------------------------------- 1 | from fython import * 2 | 3 | load('.imports') -------------------------------------------------------------------------------- /example/stat/stat/mean/mean_test.py: -------------------------------------------------------------------------------- 1 | from fython import * 2 | 3 | m = load('.mean') 4 | 5 | # accessing a global variable 6 | p = m.plank() 7 | 8 | # setting a global variable 9 | p[:] = 6 10 | 11 | # cube mean 12 | print('cube mean') 13 | x = Real(value=1) 14 | y = Real(value=2) 15 | z = Real(value=3) 16 | r = Real() 17 | 18 | m.cube_mean(x, y, z, r) 19 | 20 | print(' result in python', r[:]) 21 | 22 | # moving mean 23 | print('\nmoving mean 1') 24 | 25 | n = Int(value=5) 26 | x = Real(value=[1, 2, 3, 4, 5]) 27 | m.moving_mean(n, x) 28 | 29 | print(' result in python', x[:]) 30 | 31 | # an other time 32 | print('\nmoving mean 2') 33 | x[0] = 10 34 | x[1] = 20 35 | m.moving_mean(n, x) 36 | 37 | print(' result in python', x[:]) 38 | 39 | # string mean 40 | x = Char(size=3, value=['abc', 'xyz', 'ijk']) 41 | m.string_mean(x, r) 42 | 43 | print('string mean', r[:]) -------------------------------------------------------------------------------- /example/stat/stat/newspaper/print.fy: -------------------------------------------------------------------------------- 1 | int i 2 | real x(10) 3 | 4 | for i in [1, 10]: 5 | x[i] = i 6 | print 'x({:i}) = {:x[i]}' 7 | 8 | print .x_final 'x is {v:x}' 9 | 10 | # string to specify the path 11 | print './x_transformed.out' """ 12 | x+10 is: {vc:x+10} 13 | x-10 is : {vc:x-10} 14 | """ 15 | 16 | # Yes, Python multiline string 17 | -------------------------------------------------------------------------------- /example/stat/stat/newspaper/print_test.py: -------------------------------------------------------------------------------- 1 | import os 2 | from fython import * 3 | 4 | os.system('rm *.out') # cleaning any previous run 5 | 6 | m = load('.print', force=1) 7 | 8 | print('\nfinal x') 9 | print(open('./x_final.out', 'r').read()) 10 | 11 | print('\nx transformed') 12 | print(open('./x_transformed.out', 'r').read()) -------------------------------------------------------------------------------- /example/stat/stat/newspaper/read.fy: -------------------------------------------------------------------------------- 1 | int: x y z 2 | int u(3) 3 | 4 | print .data mode(w) '1, 2, 3' # explicitly creating a new file with the mode modifier 5 | 6 | read .data: x y z 7 | 8 | print 'x {:x}' 9 | print 'y {:y}' 10 | print 'z {:z}' 11 | 12 | # vectors too 13 | read .data u 14 | print 'u is {v:u}' -------------------------------------------------------------------------------- /example/stat/stat/newspaper/read_test.py: -------------------------------------------------------------------------------- 1 | from fython import * 2 | 3 | m = load('.read') -------------------------------------------------------------------------------- /example/stat/stat/pycessor/pycessor.fy: -------------------------------------------------------------------------------- 1 | import os 2 | import numpy 3 | # or any python module on your path 4 | 5 | real pi = |numpy.pi| # atan what? no more 6 | 7 | # lazy initialization of exotic random variate 8 | real v(1e3) 9 | 10 | | 11 | x = numpy.random.uniform(0, 1, 1000) 12 | 13 | for i in range(1000): 14 | write('v[i] = {:f}'.format(x[i])) 15 | | 16 | 17 | # running a make file 18 | |os.system("echo 'compiling boost ... done'")| # for real? isn't it 2 hours -------------------------------------------------------------------------------- /example/stat/stat/pycessor/pycessor_test.py: -------------------------------------------------------------------------------- 1 | from fython import * 2 | 3 | load('.pycessor') -------------------------------------------------------------------------------- /example/stat/stat/template/class.fy: -------------------------------------------------------------------------------- 1 | class temp Atom: 2 | T x 3 | 4 | def lt: 5 | self in 6 | self in other 7 | bool res r 8 | r = self.x > other.x 9 | 10 | def Electron = Atom(T = real) 11 | 12 | Electron e 13 | Electron p 14 | 15 | e.x = 10 16 | p.x = 1 17 | 18 | print '{:e.lt(p)}' -------------------------------------------------------------------------------- /example/stat/stat/template/class_test.py: -------------------------------------------------------------------------------- 1 | from fython import * 2 | load('.class') -------------------------------------------------------------------------------- /example/stat/stat/template/function.fy: -------------------------------------------------------------------------------- 1 | def temp f: 2 | T in x 3 | print 'x is {:x}' 4 | 5 | def f_real = f(T=real) 6 | def f_int = f(T=int) 7 | 8 | 9 | f_real(1.5) 10 | f_int(1) -------------------------------------------------------------------------------- /example/stat/stat/template/function_test.py: -------------------------------------------------------------------------------- 1 | from fython import * 2 | load('.function') -------------------------------------------------------------------------------- /example/stat/stat/template/package.fy: -------------------------------------------------------------------------------- 1 | import .class(*) 2 | import .quicksort(*) 3 | ||type_provider=.class, target_class=Electron|| 4 | 5 | Electron e(10) 6 | int i 7 | 8 | for i in [10, 1, -1]: 9 | e.x = i 10 | 11 | quicksort(e) 12 | 13 | 14 | -------------------------------------------------------------------------------- /example/stat/stat/template/package_test.py: -------------------------------------------------------------------------------- 1 | from fython import * 2 | load('.package') -------------------------------------------------------------------------------- /example/stat/stat/template/quicksort.fy: -------------------------------------------------------------------------------- 1 | import asis type_provider(target_class=T) 2 | 3 | def quicksort: 4 | T dimension(10) in x 5 | int: i r 6 | for i in [1, 9]: 7 | r = x[i].lt( x[i+1] ) 8 | print 'i {:r}' 9 | -------------------------------------------------------------------------------- /example/stat/stat/variance/explicit_spec_interpolation.fy: -------------------------------------------------------------------------------- 1 | 2 | def f: 3 | real in x 4 | real out y 5 | y = x + 2 6 | 7 | def spec(f) g: 8 | y = x * 10 -------------------------------------------------------------------------------- /example/stat/stat/variance/explicit_spec_interpolation_test.py: -------------------------------------------------------------------------------- 1 | from fython import * 2 | 3 | m = load('.explicit_spec_interpolation') 4 | 5 | print('calling f') 6 | x = Real(value=1) 7 | y = Real() 8 | m.f(x, y) 9 | 10 | print(' result in python', y[:]) 11 | 12 | print('calling g') 13 | x = Real(value=1) 14 | y = Real() 15 | m.g(x, y) 16 | 17 | print(' result in python', y[:]) -------------------------------------------------------------------------------- /example/stat/stat/variance/variance.fy: -------------------------------------------------------------------------------- 1 | import .variance_spec(*) 2 | 3 | def variance: 4 | cube_mean(x, y, z, u) 5 | r = x - u + maxwell # this is the official formula on planet kawabunga 6 | -------------------------------------------------------------------------------- /example/stat/stat/variance/variance_spec.fy: -------------------------------------------------------------------------------- 1 | import stat.mean.mean(*) 2 | 3 | def variance: 4 | real in: x y z 5 | real out r 6 | real u 7 | int cons maxwell = 8 -------------------------------------------------------------------------------- /example/stat/stat/variance/variance_test.py: -------------------------------------------------------------------------------- 1 | from fython import * 2 | 3 | m = load('.variance') 4 | 5 | # cube mean 6 | print('calling variance') 7 | x = Real(value=1) 8 | y = Real(value=2) 9 | z = Real(value=3) 10 | r = Real() 11 | 12 | m.variance(x, y, z, r) 13 | 14 | print(' result in python', r[:]) -------------------------------------------------------------------------------- /exp/a: -------------------------------------------------------------------------------- 1 | 2 | a: 3 | x 4 | 5 | y 6 | -------------------------------------------------------------------------------- /exp/args_kwargs.py: -------------------------------------------------------------------------------- 1 | def f(*args, **kwargs): 2 | print(args) 3 | print(kwargs) 4 | 5 | 6 | f(1) 7 | f(x=1, y=1, z=2) -------------------------------------------------------------------------------- /exp/class_method_at_runtime.py: -------------------------------------------------------------------------------- 1 | class A: 2 | pass 3 | 4 | def f(s, x): 5 | s.g(s, x) 6 | 7 | def g(s, x): 8 | print(type(s)) 9 | print(1, x) 10 | 11 | a = A() 12 | 13 | a.g = g 14 | 15 | a.x = g 16 | a.f(3) 17 | 18 | a.x(1, 5) -------------------------------------------------------------------------------- /exp/ctype_crash/multiprocessing_ctype_from_address.py: -------------------------------------------------------------------------------- 1 | from multiprocessing import * 2 | from ctypes import * 3 | 4 | x = c_int(1) 5 | a = addressof(x) 6 | 7 | print(x.value) 8 | 9 | def f(): 10 | print('a') 11 | x = cast(a, POINTER(c_int)) 12 | x = x.contents 13 | print('b', x.value) 14 | x.value *= 10 15 | print(x.value) 16 | print('c') 17 | 18 | if __name__ == '__main__': 19 | p = Process(target=f) 20 | p.start() 21 | p.join() 22 | print(3, x.value, p.exitcode) 23 | -------------------------------------------------------------------------------- /exp/ctype_crash/multiprocessing_wall_pool.py: -------------------------------------------------------------------------------- 1 | from multiprocessing import * 2 | from ctypes import * 3 | 4 | def f(x): 5 | print(1) 6 | string_at(1) 7 | print(2) 8 | 9 | if __name__ == '__main__': 10 | p = Pool(1) 11 | p.apply(f, [0]) 12 | print(3) -------------------------------------------------------------------------------- /exp/ctype_crash/multiprocessing_wall_process.py: -------------------------------------------------------------------------------- 1 | from multiprocessing import * 2 | from ctypes import * 3 | 4 | def f(): 5 | print(1) 6 | # string_at(1) 7 | print(2) 8 | 9 | if __name__ == '__main__': 10 | p = Process(target=f) 11 | p.start() 12 | p.join() 13 | print(3, p.exitcode) 14 | -------------------------------------------------------------------------------- /exp/ctype_crash/multiprocessing_wall_process_fytype.py: -------------------------------------------------------------------------------- 1 | from multiprocessing import * 2 | from ctypes import * 3 | from fython.fytypes import * 4 | 5 | x = Real(value=1) 6 | 7 | print(x[:]) 8 | 9 | def f(): 10 | print(1) 11 | print(x[:]) 12 | x[:] *= 10 13 | print(x[:]) 14 | print(2) 15 | 16 | if __name__ == '__main__': 17 | p = Process(target=f) 18 | p.start() 19 | p.join() 20 | print(3, x[:], p.exitcode) 21 | -------------------------------------------------------------------------------- /exp/ctypes_exp/a.f90: -------------------------------------------------------------------------------- 1 | 2 | module a 3 | 4 | contains 5 | subroutine f(x) 6 | integer x 7 | write(*, *) 1, 2, x 8 | end subroutine 9 | end module 10 | -------------------------------------------------------------------------------- /exp/ctypes_exp/ctypes_dict_access.py: -------------------------------------------------------------------------------- 1 | import os 2 | from ctypes import * 3 | from numpy import * 4 | 5 | c = """ 6 | module a 7 | 8 | contains 9 | subroutine f(x) 10 | int x 11 | write(*, *) 1, 2, x 12 | end subroutine 13 | end module 14 | """ 15 | open('a.f90','w').write(c) 16 | 17 | os.system('ifort a.f90 -shared -fpic -o a.so') 18 | 19 | m = cdll.LoadLibrary('./a.so') 20 | 21 | m.__getattr__('a_mp_f_')(byref(c_int(10))) -------------------------------------------------------------------------------- /exp/ctypes_exp/global_int.py: -------------------------------------------------------------------------------- 1 | import os 2 | from ctypes import * 3 | from numpy import * 4 | 5 | 6 | def f(s): 7 | global m 8 | c = """ 9 | module a 10 | {:s} 11 | end module 12 | """ 13 | c = c.format(s) 14 | open('a.f90','w').write(c) 15 | 16 | os.system('ifort a.f90 -shared -fpic -o a.so') 17 | 18 | os.system('nm -D a.so') 19 | 20 | m = cdll.LoadLibrary('./a.so') 21 | 22 | f(""" 23 | integer :: x = 10 24 | integer, dimension(2) :: y = [20, 30] 25 | """) 26 | x = c_int.in_dll(m, 'a_mp_x_') 27 | print(x.value) 28 | x.value = 100 29 | x = c_int.in_dll(m, 'a_mp_x_') 30 | print(x.value) 31 | 32 | 33 | t = c_int*2 34 | x = t.in_dll(m, 'a_mp_y_') 35 | print(x[0], x[1]) 36 | x[0] = 200 37 | x[1] = 300 38 | x = t.in_dll(m, 'a_mp_y_') 39 | print(x[0], x[1]) 40 | 41 | 42 | -------------------------------------------------------------------------------- /exp/ctypes_exp/numpy_char.py: -------------------------------------------------------------------------------- 1 | from ctypes import * 2 | from numpy.ctypeslib import as_array 3 | from numpy import array 4 | 5 | t = c_char * 3 6 | tv = t * 2 7 | 8 | x = tv(t(b'a', b'b', b'c'), t(b'd', b'e', b'f')) 9 | 10 | x.__array_interface__ = { 11 | 'version': 3, 12 | '__ref': x, 13 | 'shape': (2,), 14 | 'typestr': 'S3', 15 | 'data': (addressof(x), False), 16 | 'strides': None, 17 | } 18 | 19 | y = array(x,copy=0) 20 | 21 | 22 | y[0] = 'xyz' 23 | print(y, y[0], x[0].raw) -------------------------------------------------------------------------------- /exp/ctypes_exp/numpy_char_2.py: -------------------------------------------------------------------------------- 1 | from ctypes import * 2 | from numpy import array 3 | 4 | t = c_char * 3 5 | x = t(b'a', b'b', b'c') 6 | 7 | x.__array_interface__ = { 8 | 'shape': (), 9 | 'typestr': 'S3', 10 | 'data': (addressof(x), 0), 11 | } 12 | 13 | y = array(x,copy=0) 14 | 15 | print(y) 16 | print(repr(y)) 17 | print(x) -------------------------------------------------------------------------------- /exp/ctypes_exp/numpy_exp.py: -------------------------------------------------------------------------------- 1 | import os 2 | from ctypes import * 3 | from numpy import * 4 | 5 | 6 | def f(s): 7 | global m 8 | c = """ 9 | module a 10 | {:s} 11 | end module 12 | """ 13 | c = c.format(s) 14 | open('a.f90','w').write(c) 15 | 16 | os.system('ifort a.f90 -shared -fpic -o a.so') 17 | 18 | os.system('nm -D a.so') 19 | 20 | m = cdll.LoadLibrary('./a.so') 21 | 22 | f(""" 23 | integer :: x = 10 24 | integer, dimension(2) :: y = [20, 30] 25 | """) 26 | x = c_int.in_dll(m, 'a_mp_x_') 27 | xx = ctypeslib.as_array(x) 28 | xx += 10 29 | print(xx, type(xx)) 30 | x = c_int.in_dll(m, 'a_mp_x_') 31 | print(x.value) -------------------------------------------------------------------------------- /exp/ctypes_exp/numpy_string_exp.py: -------------------------------------------------------------------------------- 1 | import os 2 | from ctypes import * 3 | from numpy import * 4 | 5 | 6 | def f(s): 7 | global m 8 | c = """ 9 | module a 10 | {:s} 11 | end module 12 | """ 13 | c = c.format(s) 14 | open('a.f90','w').write(c) 15 | 16 | os.system('ifort a.f90 -shared -fpic -o a.so') 17 | 18 | os.system('nm -D a.so') 19 | 20 | m = cdll.LoadLibrary('./a.so') 21 | 22 | f(""" 23 | character(3), dimension(2) :: x = ['abc', 'def'] 24 | """) 25 | t = (c_char*3)*2 26 | print(t) 27 | x = t.in_dll(m, 'a_mp_x_') 28 | print(x[0].value, x[1].value) 29 | xx = ctypeslib.as_array(x) -------------------------------------------------------------------------------- /exp/ctypes_exp/numpy_string_multi_dimensional_exp.py: -------------------------------------------------------------------------------- 1 | import os 2 | from ctypes import * 3 | from numpy import * 4 | 5 | 6 | def f(s): 7 | global m 8 | c = """ 9 | module a 10 | {:s} 11 | end module 12 | """ 13 | c = c.format(s) 14 | open('a.f90','w').write(c) 15 | 16 | os.system('ifort a.f90 -shared -fpic -o a.so') 17 | 18 | os.system('nm -D a.so') 19 | 20 | m = cdll.LoadLibrary('./a.so') 21 | 22 | f(""" 23 | character(3), dimension(2, 2) :: x = ['abc', 'def', 'xyz', 'uvw'] 24 | """) 25 | t = ((c_char*3)*2)*2 26 | x = t.in_dll(m, 'a_mp_x_') 27 | print(x[0][0].value, x[0][1].value) -------------------------------------------------------------------------------- /exp/ctypes_exp/vector_passing.py: -------------------------------------------------------------------------------- 1 | import os 2 | from ctypes import * 3 | from numpy import * 4 | 5 | c = """ 6 | module a 7 | 8 | contains 9 | 10 | function f(x) result(r) bind(c) 11 | integer, dimension(2), intent(in) :: x 12 | integer, dimension(2) :: r 13 | write(*, *) 'entering f' 14 | r = x * 10 15 | write(*, *) 'exiting f' 16 | end function 17 | 18 | end module 19 | """ 20 | 21 | open('a.f90','w').write(c) 22 | 23 | os.system('ifort a.f90 -shared -fpic -o a.so') 24 | 25 | # os.system('nm -D a.so') 26 | 27 | m = cdll.LoadLibrary('./a.so') 28 | 29 | # f = m.a_mp_f_ 30 | f = m.f 31 | 32 | t = c_float*2 33 | p = POINTER(t) 34 | 35 | f.argstype = [p] 36 | # f.restype = c_void_p 37 | 38 | x = t(1, 2) 39 | 40 | print( f( byref(x) ) ) 41 | -------------------------------------------------------------------------------- /exp/ctypes_exp/vector_passing_sub.py: -------------------------------------------------------------------------------- 1 | import os 2 | from ctypes import * 3 | from numpy import * 4 | 5 | c = """ 6 | module a 7 | 8 | contains 9 | 10 | subroutine f(x) 11 | integer, dimension(2), intent(inout) :: x 12 | write(*, *) 'entering f' 13 | write(*, *) 'x at entry', x 14 | x = x * 10 15 | write(*, *) 'x before exit', x 16 | write(*, *) 'exiting f' 17 | end subroutine 18 | 19 | end module 20 | """ 21 | 22 | open('a.f90','w').write(c) 23 | 24 | os.system('ifort a.f90 -shared -fpic -o a.so') 25 | 26 | os.system('nm -D a.so') 27 | 28 | m = cdll.LoadLibrary('./a.so') 29 | 30 | f = m.a_mp_f_ 31 | 32 | t = c_int*2 33 | 34 | x = t(1, 1) 35 | print(x[0], x[1]) 36 | f( byref(x) ) 37 | print(x[0], x[1]) -------------------------------------------------------------------------------- /exp/ctypes_exp/vector_string.py: -------------------------------------------------------------------------------- 1 | import os 2 | from ctypes import * 3 | from numpy import * 4 | 5 | c = """ 6 | module a 7 | character(3), dimension(2) :: x = ['abc', 'def'] 8 | end module 9 | """ 10 | open('a.f90','w').write(c) 11 | 12 | os.system('ifort a.f90 -shared -fpic -o a.so') 13 | 14 | os.system('nm -D a.so') 15 | 16 | m = cdll.LoadLibrary('./a.so') 17 | 18 | t = (c_char*3)*2 19 | x = t.in_dll(m, 'a_mp_x_') 20 | print(x[0].value, x[1].value) 21 | print('{:s}'.format(x[0].value.decode('utf-8'))) -------------------------------------------------------------------------------- /exp/def_order.py: -------------------------------------------------------------------------------- 1 | class B: 2 | a = A() 3 | 4 | 5 | class A: 6 | pass 7 | 8 | b = B() -------------------------------------------------------------------------------- /exp/dependency.py: -------------------------------------------------------------------------------- 1 | import networkx as nx 2 | 3 | t = nx.DiGraph() 4 | 5 | t.add_edge(2, 1) 6 | t.add_edge(3, 1) 7 | t.add_edge(4, 3) 8 | 9 | 10 | print( 11 | nx.topological_sort(t) 12 | ) 13 | 14 | class A: 15 | def __init__(s, a): 16 | s.a = a 17 | 18 | def __hash__(s): 19 | return hash(s.a) 20 | 21 | def __eq__(s, other): 22 | return s.a == other.a 23 | 24 | def __repr__(s): 25 | return str(s.a) 26 | 27 | 28 | 29 | a = A(1) 30 | b = A(2) 31 | c = A(3) 32 | 33 | t = nx.DiGraph() 34 | t.add_edge(b, a) 35 | t.add_edge(c, b) 36 | 37 | print( 38 | nx.topological_sort(t) 39 | ) -------------------------------------------------------------------------------- /exp/dict_update.py: -------------------------------------------------------------------------------- 1 | a = {1:1, 2:2} 2 | b = {3:3} 3 | 4 | a.update(b) 5 | 6 | print(a) 7 | b[3] = 10 8 | print(a) 9 | print(b) -------------------------------------------------------------------------------- /exp/dill_pickling.py: -------------------------------------------------------------------------------- 1 | # from dill import * 2 | from pickle import * 3 | 4 | class A: 5 | @property 6 | def x(s): 7 | return 1 8 | 9 | a = A() 10 | a.q = A() 11 | print(a.x) 12 | 13 | print( 14 | 15 | dumps(a, protocol=0) 16 | 17 | ) -------------------------------------------------------------------------------- /exp/dynamic_module.py: -------------------------------------------------------------------------------- 1 | from types import ModuleType 2 | 3 | m = ModuleType('interpolant') 4 | 5 | m.x = 1 6 | m.y = lambda : 1 7 | 8 | print(m.x, m.y()) 9 | 10 | exec('from numpy import *', m.__dict__) 11 | 12 | print(m.array([1,2])) 13 | 14 | print(eval('x + y() + array([1,2])',m.__dict__)) -------------------------------------------------------------------------------- /exp/exception_handling.py: -------------------------------------------------------------------------------- 1 | class A(Exception): 2 | def __init__(s, err, *args): 3 | s.err = err 4 | s.d = 2323 5 | 6 | @property 7 | def message(s): 8 | return 'kawabunga' 9 | 10 | 11 | def __str__(s): 12 | return s.message 13 | 14 | class B(A): 15 | pass 16 | 17 | try: 18 | raise A('hh', 89) 19 | 20 | except B as e: 21 | print(1) -------------------------------------------------------------------------------- /exp/exception_handling_dynamic_creation.py: -------------------------------------------------------------------------------- 1 | a = type('a_fyerr', (Exception,), {}) 2 | 3 | try: 4 | raise a('aa') 5 | 6 | except Exception as e: 7 | print(type(e)) -------------------------------------------------------------------------------- /exp/execution.py: -------------------------------------------------------------------------------- 1 | class A: 2 | x = 1 3 | def run(s, c): 4 | print(eval(c, {}, A.__dict__)) 5 | 6 | def g(s, t): 7 | return 2*t 8 | 9 | a = A() 10 | 11 | f = getattr(a, 'g') 12 | 13 | print( eval('f(2)') ) -------------------------------------------------------------------------------- /exp/fortran/a.f90: -------------------------------------------------------------------------------- 1 | 2 | module a 3 | 4 | contains 5 | subroutine f(x, y) 6 | real :: x, y 7 | end subroutine 8 | 9 | subroutine g() 10 | call f(y=1., x=x) 11 | end subroutine 12 | end module 13 | -------------------------------------------------------------------------------- /exp/fortran/array_syntax.py: -------------------------------------------------------------------------------- 1 | import os 2 | from ctypes import * 3 | from numpy import * 4 | 5 | c = """ 6 | module a 7 | 8 | type AA 9 | real x(10) 10 | end type 11 | 12 | type(AA) y(10) 13 | contains 14 | 15 | subroutine f() 16 | write(*, *) y(1)%x(1) 17 | 18 | end subroutine 19 | 20 | end module 21 | """ 22 | 23 | open('a.f90','w').write(c) 24 | 25 | os.system('ifort a.f90 -shared -fpic -o a.so') 26 | 27 | os.system('nm -D a.so') 28 | 29 | m = cdll.LoadLibrary('./a.so') 30 | 31 | m.a_mp_f_() 32 | 33 | -------------------------------------------------------------------------------- /exp/fortran/compilation_linking/a.f90: -------------------------------------------------------------------------------- 1 | 2 | module a 3 | 4 | end module 5 | -------------------------------------------------------------------------------- /exp/fortran/compilation_linking/b.f90: -------------------------------------------------------------------------------- 1 | 2 | module b 3 | use a 4 | end module 5 | -------------------------------------------------------------------------------- /exp/fortran/compilation_linking/c.f90: -------------------------------------------------------------------------------- 1 | 2 | submodule (b) c 3 | 4 | end submodule 5 | -------------------------------------------------------------------------------- /exp/fortran/compilation_linking/comp_link_exp.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | os.system('rm -rf *.o *.so *.mod *.smod *.f90') 4 | 5 | def f(**kwargs): 6 | for key, code in kwargs.items(): 7 | if key == 'cmd': 8 | continue 9 | 10 | open(key+'.f90', 'w').write(code) 11 | 12 | os.system(kwargs['cmd']) 13 | f( 14 | a = """ 15 | module a 16 | 17 | end module 18 | """, 19 | 20 | b = """ 21 | module b 22 | use a 23 | end module 24 | """, 25 | 26 | c = """ 27 | submodule (b) c 28 | 29 | end submodule 30 | """, 31 | 32 | cmd=""" 33 | ifort -c a.f90 34 | ifort -c b.f90 35 | ifort -c c.f90 36 | ifort -shared -fpic -o out.so b.o 37 | """ 38 | ) -------------------------------------------------------------------------------- /exp/fortran/if_with_integer.py: -------------------------------------------------------------------------------- 1 | import os 2 | from ctypes import * 3 | from numpy import * 4 | 5 | c = """ 6 | module a 7 | 8 | contains 9 | 10 | subroutine f() 11 | int x 12 | x = 0 13 | if (.not. x) then 14 | write(*, *) 1 15 | else 16 | write(*, *) 2 17 | end if 18 | end subroutine 19 | 20 | end module 21 | """ 22 | 23 | open('a.f90','w').write(c) 24 | 25 | os.system('ifort a.f90 -shared -fpic -o a.so') 26 | 27 | os.system('nm -D a.so') 28 | 29 | m = cdll.LoadLibrary('./a.so') 30 | 31 | m.a_mp_f_() 32 | 33 | -------------------------------------------------------------------------------- /exp/fortran/implicit_none.py: -------------------------------------------------------------------------------- 1 | import os 2 | from ctypes import * 3 | from numpy import * 4 | 5 | c = """ 6 | module a 7 | ;implicit none 8 | 9 | end module 10 | """ 11 | 12 | open('a.f90','w').write(c) 13 | 14 | os.system('ifort a.f90 -shared -fpic -o a.so') 15 | -------------------------------------------------------------------------------- /exp/fortran/keyword_argument.py: -------------------------------------------------------------------------------- 1 | import os 2 | from ctypes import * 3 | from numpy import * 4 | 5 | c = """ 6 | module a 7 | 8 | contains 9 | subroutine f(x, y) 10 | real :: x, y 11 | end subroutine 12 | 13 | subroutine g() 14 | call f(y=1., x=x) 15 | end subroutine 16 | end module 17 | """ 18 | 19 | open('a.f90','w').write(c) 20 | 21 | os.system('ifort a.f90 -shared -fpic -o a.so') 22 | -------------------------------------------------------------------------------- /exp/fortran/module_def_order.py: -------------------------------------------------------------------------------- 1 | import os 2 | from ctypes import * 3 | from numpy import * 4 | 5 | c = """ 6 | module a 7 | 8 | 9 | type B 10 | real x 11 | end type 12 | 13 | type(B) y 14 | 15 | 16 | contains 17 | 18 | subroutine f(n, x) 19 | interface 20 | function f() 21 | real f 22 | end function 23 | end interface 24 | 25 | real x(n) 26 | int n 27 | write(*, *) 11, g() 28 | contains 29 | end subroutine 30 | 31 | function g() 32 | real g 33 | g = 22 34 | end function 35 | 36 | end module 37 | """ 38 | 39 | open('a.f90','w').write(c) 40 | 41 | os.system('ifort a.f90 -shared -fpic -o a.so') 42 | 43 | os.system('nm -D a.so') 44 | 45 | m = cdll.LoadLibrary('./a.so') 46 | 47 | m.a_mp_f_() 48 | 49 | -------------------------------------------------------------------------------- /exp/fortran/module_import.py: -------------------------------------------------------------------------------- 1 | import os 2 | from ctypes import * 3 | from numpy import * 4 | 5 | c = """ 6 | module b 7 | integer :: xb = 3 8 | end module 9 | 10 | module a 11 | use b 12 | integer :: xa = 2 13 | end module 14 | 15 | module c 16 | use b 17 | use a 18 | integer :: xc = 1 19 | contains 20 | subroutine f() 21 | write(*, *) xc, xa, xb 22 | end subroutine 23 | end module 24 | """ 25 | 26 | open('a.f90','w').write(c) 27 | 28 | os.system('ifort a.f90 -shared -fpic -o a.so') 29 | 30 | os.system('nm -D a.so') 31 | 32 | m = cdll.LoadLibrary('./a.so') 33 | 34 | m.c_mp_f_() 35 | 36 | -------------------------------------------------------------------------------- /exp/fortran/module_with_empty_contains.py: -------------------------------------------------------------------------------- 1 | import os 2 | from ctypes import * 3 | from numpy import * 4 | 5 | c = """ 6 | module a 7 | 8 | contains 9 | 10 | subroutine f() 11 | write(*, *) 11 12 | contains 13 | end subroutine 14 | 15 | end module 16 | """ 17 | 18 | open('a.f90','w').write(c) 19 | 20 | os.system('ifort a.f90 -shared -fpic -o a.so') 21 | 22 | os.system('nm -D a.so') 23 | 24 | m = cdll.LoadLibrary('./a.so') 25 | 26 | m.a_mp_f_() 27 | 28 | -------------------------------------------------------------------------------- /exp/fortran/name_mangling/a.f90: -------------------------------------------------------------------------------- 1 | 2 | module a 3 | integer :: x 4 | 5 | end module 6 | -------------------------------------------------------------------------------- /exp/fortran/name_mangling/b.f90: -------------------------------------------------------------------------------- 1 | 2 | module b 3 | use a._ 4 | 5 | ! integer :: x 6 | 7 | contains 8 | 9 | subroutine f() 10 | integer y 11 | y = a_mp_x_ + 1 + x 12 | end subroutine 13 | 14 | end module 15 | -------------------------------------------------------------------------------- /exp/fortran/name_mangling/name_mangling.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | os.system('rm -rf *.mod *.o *.so') 4 | 5 | c = """ 6 | module a 7 | integer :: x 8 | 9 | end module 10 | """ 11 | open('a.f90','w').write(c) 12 | os.system('ifort a.f90 -c -fpic') 13 | 14 | c=""" 15 | module b 16 | use a 17 | 18 | contains 19 | 20 | subroutine f() 21 | int y 22 | y = a_mp_x_ + 1 23 | end subroutine 24 | 25 | end module 26 | """ 27 | open('b.f90','w').write(c) 28 | os.system('ifort b.f90 -c -fpic') 29 | 30 | os.system('ifort -shared a.o b.o -o a.so') 31 | 32 | 33 | os.system('nm -D a.so') 34 | 35 | -------------------------------------------------------------------------------- /exp/fortran/name_mangling/name_mangling_2.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | os.system('rm -rf *.mod *.o *.so') 4 | 5 | c = """ 6 | module a 7 | integer :: x 8 | 9 | end module 10 | """ 11 | open('a.f90','w').write(c) 12 | os.system('ifort a.f90 -c -fpic') 13 | 14 | c=""" 15 | module b 16 | use a 17 | 18 | integer :: x 19 | 20 | contains 21 | 22 | subroutine f() 23 | int y 24 | y = a_mp_x_ + 1 + x 25 | end subroutine 26 | 27 | end module 28 | """ 29 | open('b.f90','w').write(c) 30 | os.system('ifort b.f90 -c -fpic') 31 | 32 | os.system('ifort -shared a.o b.o -o a.so') 33 | 34 | 35 | os.system('nm -D a.so') 36 | 37 | -------------------------------------------------------------------------------- /exp/fortran/nested_type.py: -------------------------------------------------------------------------------- 1 | import os 2 | from ctypes import * 3 | from numpy import * 4 | 5 | c = """ 6 | module a 7 | character(3), dimension(2) :: x = ['abc', 'def'] 8 | type, bind(c) :: x 9 | type, bind(c) :: y 10 | int u 11 | end type 12 | end type 13 | end module 14 | """ 15 | open('a.f90','w').write(c) 16 | 17 | os.system('ifort a.f90 -shared -fpic -o a.so') 18 | 19 | os.system('nm -D a.so') 20 | 21 | m = cdll.LoadLibrary('./a.so') 22 | 23 | t = (c_char*3)*2 24 | x = t.in_dll(m, 'a_mp_x_') 25 | print(x[0].value, x[1].value) 26 | print('{:s}'.format(x[0].value.decode('utf-8'))) -------------------------------------------------------------------------------- /exp/fortran/object_name_given.py: -------------------------------------------------------------------------------- 1 | import os 2 | from ctypes import * 3 | from numpy import * 4 | 5 | c = """ 6 | module aa 7 | 8 | contains 9 | 10 | subroutine f() 11 | write(*, *) 11 12 | contains 13 | end subroutine 14 | 15 | end module 16 | """ 17 | 18 | open('a.f90','w').write(c) 19 | 20 | os.system('ifort a.f90 -c -fpic -o b.o') 21 | 22 | 23 | -------------------------------------------------------------------------------- /exp/fortran/print_to_file/a.f90: -------------------------------------------------------------------------------- 1 | 2 | program a 3 | 4 | integer :: u = 10 5 | 6 | integer, dimension(3) :: x = 2 7 | 8 | open(u, file='a.tmp', status='replace') 9 | 10 | ! write(u, '(a, *(g0), a, (g0), a)') 'a', x, 'b', x, 'c' 11 | 12 | ! write(u, "(a, (3(g0,', '),'null'), a, 3(g0), a)") 'a', x, 'b', x, 'c' 13 | 14 | write(u, "(a, 3(g0,', '), tl2, a)") 'a', x, 'b' 15 | 16 | ! write(u, "(3(g0,:,', '))") x 17 | 18 | ! write(u, "(*(g0,:', '))") x 19 | 20 | 21 | close(u) 22 | 23 | end program 24 | -------------------------------------------------------------------------------- /exp/fortran/print_to_file/print_empty.py: -------------------------------------------------------------------------------- 1 | import os 2 | c = """ 3 | program a 4 | 5 | integer :: u = 10 6 | 7 | open(u, file='a.tmp', status='replace') 8 | 9 | write(u, '()') 10 | 11 | close(u) 12 | 13 | end program 14 | """ 15 | 16 | open('a.f90','w').write(c) 17 | 18 | os.system(""" 19 | ifort a.f90 -o a.b 20 | ./a.b 21 | """) 22 | 23 | print(open('a.tmp', 'r').read()) 24 | -------------------------------------------------------------------------------- /exp/fortran/print_to_file/print_format.py: -------------------------------------------------------------------------------- 1 | import os 2 | c = """ 3 | program a 4 | 5 | integer :: u = 10 6 | 7 | open(u, file='a.tmp', status='replace') 8 | 9 | write(u, '(f6.2)') 100.5678 10 | 11 | 12 | close(u) 13 | 14 | end program 15 | """ 16 | 17 | open('a.f90','w').write(c) 18 | 19 | os.system(""" 20 | ifort a.f90 -o a.b 21 | ./a.b 22 | """) 23 | 24 | print(open('a.tmp', 'r').read()) 25 | -------------------------------------------------------------------------------- /exp/fortran/print_to_file/print_to_file.py: -------------------------------------------------------------------------------- 1 | import os 2 | c = """ 3 | program a 4 | 5 | integer :: u = 10 6 | 7 | integer, dimension(1e3) :: x = 2 8 | 9 | open(u, file='a.tmp', status='replace') 10 | 11 | write(u, '(a, *(g0), a, (g0), a)') 'a', x, 'b', x, 'c' 12 | 13 | 14 | close(u) 15 | 16 | end program 17 | """ 18 | 19 | open('a.f90','w').write(c) 20 | 21 | os.system(""" 22 | ifort a.f90 -o a.b 23 | ./a.b 24 | """) 25 | 26 | print(open('a.tmp', 'r').read()) 27 | -------------------------------------------------------------------------------- /exp/fortran/print_to_file/print_vector.py: -------------------------------------------------------------------------------- 1 | import os 2 | c = """ 3 | program a 4 | 5 | integer :: u = 10 6 | 7 | integer, dimension(3) :: x = 2 8 | 9 | open(u, file='a.tmp', status='replace') 10 | 11 | ! write(u, '(a, *(g0), a, (g0), a)') 'a', x, 'b', x, 'c' 12 | 13 | ! write(u, "(a, (3(g0,', '),'null'), a, 3(g0), a)") 'a', x, 'b', x, 'c' 14 | 15 | write(u, "(a, 3(g0,', '), tl2, a)") 'a', x, 'b' 16 | 17 | ! write(u, "(3(g0,:,', '))") x 18 | 19 | ! write(u, "(*(g0,:', '))") x 20 | 21 | 22 | close(u) 23 | 24 | end program 25 | """ 26 | 27 | open('a.f90','w').write(c) 28 | 29 | os.system(""" 30 | ifort a.f90 -o a.b 31 | ./a.b 32 | """) 33 | 34 | print(open('a.tmp', 'r').read()) 35 | -------------------------------------------------------------------------------- /exp/fortran/read_from_file/a.f90: -------------------------------------------------------------------------------- 1 | 2 | program a 3 | 4 | integer :: u = 10 5 | 6 | integer :: x, y ,z 7 | 8 | open(u, file='a.tmp', status='old') 9 | 10 | namelist /list/ x, y, z 11 | 12 | read(u, list) 13 | 14 | close(u) 15 | 16 | print *, x, y, z 17 | 18 | end program 19 | -------------------------------------------------------------------------------- /exp/fortran/read_from_file/read_from_file.py: -------------------------------------------------------------------------------- 1 | import os 2 | open('a.tmp','w').write( 3 | """ 4 | 1, 10, 20 5 | 2 6 | 3 7 | """ 8 | ) 9 | 10 | c = """ 11 | program a 12 | 13 | integer :: u = 10 14 | 15 | integer :: x, y ,z 16 | 17 | open(u, file='a.tmp', status='old') 18 | 19 | read(u, *) x 20 | read(u, *) y 21 | read(u, *) z 22 | 23 | close(u) 24 | 25 | print *, x, y, z 26 | 27 | end program 28 | """ 29 | 30 | open('a.f90','w').write(c) 31 | 32 | os.system(""" 33 | ifort a.f90 -o a.b 34 | ./a.b 35 | """) 36 | 37 | -------------------------------------------------------------------------------- /exp/fortran/read_from_file/read_list_directed.py: -------------------------------------------------------------------------------- 1 | import os 2 | open('a.tmp','w').write( 3 | """ 4 | 1, 10, 20 5 | 2 6 | 3 7 | """ 8 | ) 9 | 10 | c = """ 11 | program a 12 | 13 | integer :: u = 10 14 | 15 | integer :: x, y ,z 16 | 17 | open(u, file='a.tmp', status='old') 18 | 19 | read(u, *) x, y, z 20 | 21 | close(u) 22 | 23 | print *, x, y, z 24 | 25 | end program 26 | """ 27 | 28 | open('a.f90','w').write(c) 29 | 30 | os.system(""" 31 | ifort a.f90 -o a.b 32 | ./a.b 33 | """) 34 | -------------------------------------------------------------------------------- /exp/fortran/read_from_file/read_name_list.py: -------------------------------------------------------------------------------- 1 | import os 2 | open('a.tmp','w').write( 3 | """ 4 | &LIST 5 | x = 1, 6 | y = 2, 7 | z = 3 8 | / 9 | """ 10 | ) 11 | 12 | c = """ 13 | program a 14 | 15 | integer :: u = 10 16 | 17 | integer :: x, y ,z 18 | 19 | open(u, file='a.tmp', status='old') 20 | 21 | namelist /list/ x, y, z 22 | 23 | read(u, list) 24 | 25 | close(u) 26 | 27 | print *, x, y, z 28 | 29 | end program 30 | """ 31 | 32 | open('a.f90','w').write(c) 33 | 34 | os.system(""" 35 | ifort a.f90 -o a.b 36 | ./a.b 37 | """) 38 | 39 | -------------------------------------------------------------------------------- /exp/fortran/scope_access.py: -------------------------------------------------------------------------------- 1 | import os 2 | from ctypes import * 3 | from numpy import * 4 | 5 | c = """ 6 | module a 7 | 8 | 9 | type B 10 | real x 11 | end type 12 | 13 | type(B) y 14 | 15 | 16 | contains 17 | 18 | function f() result(r) 19 | type(B) r 20 | r.x = 10 21 | end function 22 | 23 | function g() result(r) 24 | type(B) x 25 | real r 26 | x = f() 27 | r = x.x 28 | write(*, *) r 29 | end function 30 | 31 | end module 32 | """ 33 | 34 | open('a.f90','w').write(c) 35 | 36 | os.system('ifort a.f90 -shared -fpic -o a.so') 37 | 38 | os.system('nm -D a.so') 39 | 40 | m = cdll.LoadLibrary('./a.so') 41 | 42 | m.a_mp_g_() 43 | 44 | -------------------------------------------------------------------------------- /exp/fortran/scope_access_2.py: -------------------------------------------------------------------------------- 1 | import os 2 | from ctypes import * 3 | from numpy import * 4 | 5 | c = """ 6 | module a 7 | 8 | 9 | type B 10 | real x 11 | end type 12 | 13 | contains 14 | 15 | function g() result(r) 16 | type(B), dimension(10) :: x 17 | x(1).x = 10 18 | r = x(1).x 19 | write(*, *) r 20 | end function 21 | 22 | end module 23 | """ 24 | 25 | open('a.f90','w').write(c) 26 | 27 | os.system('ifort a.f90 -shared -fpic -o a.so') 28 | 29 | os.system('nm -D a.so') 30 | 31 | m = cdll.LoadLibrary('./a.so') 32 | 33 | m.a_mp_g_() 34 | 35 | -------------------------------------------------------------------------------- /exp/fortran/size.py: -------------------------------------------------------------------------------- 1 | import os 2 | from ctypes import * 3 | from numpy import * 4 | 5 | c = """ 6 | module a 7 | 8 | contains 9 | 10 | subroutine g() 11 | integer x(10) 12 | write(*, *) size(x), size(x+10+8) 13 | end subroutine 14 | 15 | end module 16 | """ 17 | 18 | open('a.f90','w').write(c) 19 | 20 | os.system('ifort a.f90 -shared -fpic -o a.so') 21 | 22 | m = cdll.LoadLibrary('./a.so') 23 | 24 | m.a_mp_g_() 25 | 26 | -------------------------------------------------------------------------------- /exp/fortran/submodule/123.f90: -------------------------------------------------------------------------------- 1 | module 123 2 | 3 | interface 4 | 5 | module function f(x) result(r) 6 | use iso_c_binding 7 | integer :: x 8 | integer :: r 9 | integer :: y 10 | end function 11 | 12 | module function g(x) result(r) 13 | integer :: x 14 | integer :: r 15 | integer :: y 16 | end function 17 | 18 | end interface 19 | 20 | end module -------------------------------------------------------------------------------- /exp/fortran/submodule/a.f90: -------------------------------------------------------------------------------- 1 | module a 2 | 3 | interface 4 | 5 | module function f(x) result(r) 6 | use iso_c_binding 7 | integer :: x 8 | integer :: r 9 | integer :: y 10 | end function 11 | 12 | module function g(x) result(r) 13 | integer :: x 14 | integer :: r 15 | integer :: y 16 | end function 17 | 18 | end interface 19 | 20 | end module -------------------------------------------------------------------------------- /exp/fortran/submodule/b.f90: -------------------------------------------------------------------------------- 1 | submodule(a) b 2 | 3 | contains 4 | 5 | module procedure f 6 | y = 1 7 | r = x + y 8 | end procedure 9 | 10 | end submodule -------------------------------------------------------------------------------- /exp/fortran/submodule/c.f90: -------------------------------------------------------------------------------- 1 | program c 2 | 3 | use a 4 | 5 | print *, f(1), g(1) 6 | 7 | end program -------------------------------------------------------------------------------- /exp/fortran/submodule/d.f90: -------------------------------------------------------------------------------- 1 | submodule(a) d 2 | 3 | contains 4 | 5 | module procedure g 6 | y = 1 7 | r = x + y + f(1) 8 | end procedure 9 | 10 | end submodule -------------------------------------------------------------------------------- /exp/fortran/submodule/out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicolasessisbreton/fython/988f5a94cee8b16b0000501a22239195c73424a1/exp/fortran/submodule/out -------------------------------------------------------------------------------- /exp/fortran/submodule_2/m1.f90: -------------------------------------------------------------------------------- 1 | module m1 2 | 3 | contains 4 | 5 | subroutine cube_mean(x, y, z, r) 6 | real, intent(in) :: x 7 | real, intent(in) :: y 8 | real, intent(in) :: z 9 | real, intent(out) :: r 10 | 11 | r=x+y+z 12 | r = r / (3) 13 | r = r * (3) 14 | 15 | 16 | end subroutine 17 | 18 | end module -------------------------------------------------------------------------------- /exp/fortran/submodule_2/m2.f90: -------------------------------------------------------------------------------- 1 | module m2 2 | 3 | use m1 4 | 5 | interface 6 | 7 | module subroutine std_deviation(x, y, z, r) 8 | real, intent(in) :: x, y, z 9 | real, intent(out) :: r 10 | real :: u 11 | 12 | 13 | end subroutine 14 | 15 | 16 | end interface 17 | 18 | end module -------------------------------------------------------------------------------- /exp/fortran/submodule_2/m3.f90: -------------------------------------------------------------------------------- 1 | submodule (m2) m3 2 | 3 | contains 4 | 5 | module procedure std_deviation 6 | call cube_mean(x, y, z, u) 7 | r=x-u 8 | 9 | end procedure 10 | 11 | 12 | end submodule -------------------------------------------------------------------------------- /exp/fortran/submodule_2/m4.f90: -------------------------------------------------------------------------------- 1 | module m4 2 | use m2 3 | 4 | contains 5 | 6 | subroutine call_std_deviation(x, y, z, r) 7 | real, intent(in) :: x, y, z 8 | real, intent(out) :: r 9 | call std(x, y, z, r) 10 | 11 | end subroutine 12 | 13 | 14 | end module -------------------------------------------------------------------------------- /exp/fortran/submodule_2/mx.f90: -------------------------------------------------------------------------------- 1 | module mx 2 | 3 | interface 4 | 5 | module subroutine std_deviation(x, y, z, r) 6 | real, intent(in) :: x, y, z 7 | real, intent(out) :: r 8 | real :: u 9 | 10 | 11 | end subroutine 12 | 13 | 14 | end interface 15 | 16 | contains 17 | 18 | module procedure std_deviation 19 | call cube_mean(x, y, z, u) 20 | r=x-u 21 | 22 | end procedure 23 | 24 | 25 | end module -------------------------------------------------------------------------------- /exp/fortran/submodule_2/submodule_compilation_order.py: -------------------------------------------------------------------------------- 1 | import os 2 | c = """ 3 | rm -rf *.mod *.so *.o 4 | 5 | ifort m1.f90 -c -fpic 6 | ifort m2.f90 -c -fpic 7 | ifort m3.f90 -c -fpic 8 | ifort m4.f90 -c -fpic 9 | 10 | ifort -shared -o a.so m1.o m2.o m3.o m4.o 11 | 12 | """ 13 | 14 | os.system(c) 15 | 16 | # os.system('nm -D a.so') 17 | -------------------------------------------------------------------------------- /exp/fortran/submodule_2/submodule_compilation_order_mx.py: -------------------------------------------------------------------------------- 1 | import os 2 | c = """ 3 | rm -rf *.mod *.so *.o 4 | 5 | 6 | ifort -shared -fpic mx.f90 7 | 8 | """ 9 | 10 | os.system(c) 11 | 12 | # os.system('nm -D a.so') 13 | -------------------------------------------------------------------------------- /exp/fortran/submodule_3/m1.f90: -------------------------------------------------------------------------------- 1 | module m1 2 | 3 | contains 4 | 5 | subroutine cube_mean(x, y, z, r) 6 | real, intent(in) :: x 7 | real, intent(in) :: y 8 | real, intent(in) :: z 9 | real, intent(out) :: r 10 | 11 | r=x+y+z 12 | r = r / (3) 13 | r = r * (3) 14 | 15 | 16 | end subroutine 17 | 18 | end module -------------------------------------------------------------------------------- /exp/fortran/submodule_3/m2.f90: -------------------------------------------------------------------------------- 1 | module m2 2 | 3 | use m1 4 | 5 | interface 6 | 7 | module subroutine std_deviation(x, y, z, r) 8 | real, intent(in) :: x, y, z 9 | real, intent(out) :: r 10 | real :: u 11 | 12 | 13 | end subroutine 14 | 15 | 16 | end interface 17 | contains 18 | module procedure std_deviation 19 | call cube_mean(x, y, z, u) 20 | r=x-u 21 | 22 | end procedure 23 | 24 | 25 | end module -------------------------------------------------------------------------------- /exp/fortran/submodule_3/m3.f90: -------------------------------------------------------------------------------- 1 | submodule (m2) m3 2 | 3 | contains 4 | 5 | module procedure std_deviation 6 | call cube_mean(x, y, z, u) 7 | r=x-u 8 | 9 | end procedure 10 | 11 | 12 | end submodule -------------------------------------------------------------------------------- /exp/fortran/submodule_3/m4.f90: -------------------------------------------------------------------------------- 1 | module m4 2 | use m2 3 | 4 | contains 5 | 6 | subroutine call_std_deviation(x, y, z, r) 7 | real, intent(in) :: x, y, z 8 | real, intent(out) :: r 9 | call std(x, y, z, r) 10 | 11 | end subroutine 12 | 13 | 14 | end module -------------------------------------------------------------------------------- /exp/fortran/submodule_3/mx.f90: -------------------------------------------------------------------------------- 1 | module mx 2 | 3 | interface 4 | 5 | module subroutine std_deviation(x, y, z, r) 6 | real, intent(in) :: x, y, z 7 | real, intent(out) :: r 8 | real :: u 9 | 10 | 11 | end subroutine 12 | 13 | 14 | end interface 15 | 16 | contains 17 | 18 | module procedure std_deviation 19 | call cube_mean(x, y, z, u) 20 | r=x-u 21 | 22 | end procedure 23 | 24 | 25 | end module -------------------------------------------------------------------------------- /exp/fortran/submodule_3/submodule_compilation_order.py: -------------------------------------------------------------------------------- 1 | import os 2 | c = """ 3 | rm -rf *.mod *.so *.o 4 | 5 | ifort m1.f90 -c -fpic 6 | ifort m2.f90 -c -fpic 7 | ifort m4.f90 -c -fpic 8 | 9 | ifort -shared -o a.so m1.o m2.o m4.o 10 | 11 | """ 12 | 13 | os.system(c) 14 | 15 | # os.system('nm -D a.so') 16 | -------------------------------------------------------------------------------- /exp/fortran/submodule_4/compilation.py: -------------------------------------------------------------------------------- 1 | import os 2 | c = """ 3 | rm -rf *.mod *.so *.o 4 | 5 | ifort m1.f90 -c -fpic 6 | ifort m2.f90 -c -fpic 7 | 8 | ifort -shared -o a.so m1.o m2.o 9 | 10 | """ 11 | 12 | os.system(c) 13 | 14 | # os.system('nm -D a.so') 15 | -------------------------------------------------------------------------------- /exp/fortran/submodule_4/m1.f90: -------------------------------------------------------------------------------- 1 | module m1 2 | 3 | interface 4 | module subroutine add(x, y, r) 5 | real, intent(in) :: x 6 | real, intent(in) :: y 7 | real, intent(out) :: r 8 | end subroutine 9 | end interface 10 | 11 | end module -------------------------------------------------------------------------------- /exp/fortran/submodule_4/m2.f90: -------------------------------------------------------------------------------- 1 | submodule(m1) m2 2 | 3 | contains 4 | module procedure add 5 | r = x + y 6 | end subroutine 7 | 8 | end submodule -------------------------------------------------------------------------------- /exp/fortran/use_iso_c.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | c = """ 4 | module z6e229112f 5 | 6 | use iso_c_binding, only: c_float, c_int 7 | 8 | contains 9 | subroutine z6e229112f_main() 10 | write(*, "(a)") '1' 11 | end subroutine 12 | end module 13 | """ 14 | 15 | open('a.f90','w').write(c) 16 | 17 | os.system('ifort a.f90 -shared -fpic -o a.so') 18 | 19 | 20 | -------------------------------------------------------------------------------- /exp/fortran/var_init_in_function.py: -------------------------------------------------------------------------------- 1 | import os 2 | from ctypes import * 3 | from numpy import * 4 | 5 | c = """ 6 | module a 7 | 8 | contains 9 | 10 | subroutine f() 11 | integer, parameter :: x = 10 12 | integer :: y = 100 13 | write(*, *) x, y 14 | end subroutine 15 | 16 | end module 17 | """ 18 | 19 | open('a.f90','w').write(c) 20 | 21 | os.system('ifort a.f90 -shared -fpic -o a.so') 22 | 23 | os.system('nm -D a.so') 24 | 25 | m = cdll.LoadLibrary('./a.so') 26 | 27 | m.a_mp_f_() 28 | 29 | -------------------------------------------------------------------------------- /exp/fortran/variable_access.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | c = """ 4 | module a 5 | 6 | int x 7 | int y 8 | 9 | public :: x 10 | private :: y 11 | 12 | end module 13 | """ 14 | 15 | open('a.f90','w').write(c) 16 | 17 | os.system('ifort a.f90 -shared -fpic -o a.so') 18 | 19 | os.system('nm -D a.so') 20 | 21 | -------------------------------------------------------------------------------- /exp/fython/a.fy: -------------------------------------------------------------------------------- 1 | int x 2 | 3 | if 1>2: 4 | x = 1 5 | elif 1>2: 6 | x = 1 7 | 8 | elif 1>2: 9 | x = 1 10 | -------------------------------------------------------------------------------- /exp/fython/exp_profiling.py: -------------------------------------------------------------------------------- 1 | import pstats 2 | 3 | p = pstats.Stats('/home/neb/temp') 4 | 5 | p.sort_stats('tottime') 6 | 7 | p.print_stats(.1) 8 | 9 | # p.print_callees() 10 | 11 | # p.print_callers('_io.FileIO') 12 | # p.print_callees('_io.FileIO') 13 | # p.print_callers('load') -------------------------------------------------------------------------------- /exp/fython/for_loop.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | int x 4 | 5 | if 1>2: 6 | x = 1 7 | elif 1>2: 8 | x = 1 9 | 10 | elif 1>2: 11 | x = 1 12 | 13 | """ 14 | 15 | from fython.test import * 16 | 17 | shell('rm -rf a/ a.* b.*') 18 | 19 | writer(s) 20 | 21 | w = load('.a', force=1, release=0, verbose=0, run_main=0) 22 | print(open(w.module.url.fortran_path, 'r').read()) 23 | -------------------------------------------------------------------------------- /exp/fython/less_equal.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | if 1 >= 2: 4 | print '1' 5 | """ 6 | 7 | from fython.test import * 8 | 9 | shell('rm -rf a/ a.* b.*') 10 | 11 | writer(s) 12 | 13 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 14 | # print(open(w.module.url.fortran_path, 'r').read()) 15 | -------------------------------------------------------------------------------- /exp/fython/mkl_import.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | # |import sys; sys.path.append('/opt/intel')| 4 | 5 | # import sys # sys not in standard pythonpath ; not supported for the moment 6 | # |sys.path.append('/opt/intel')| 7 | 8 | import mkl.include.mkl_vsl(*) 9 | import mkl.lib.intel64.libmkl_intel_lp64(*) 10 | 11 | """ 12 | 13 | from fython.test import * 14 | 15 | shell('rm -rf a/ a.* b.*') 16 | 17 | writer(s) 18 | 19 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 20 | print(open(w.module.url.fortran_path, 'r').read()) 21 | -------------------------------------------------------------------------------- /exp/getattr.py: -------------------------------------------------------------------------------- 1 | class A: 2 | def __getattr__(s, n): 3 | print(n) 4 | return s.call 5 | 6 | def call(s): 7 | print(1) 8 | 9 | 10 | 11 | a = A() 12 | 13 | # a.x 14 | 15 | a.y() -------------------------------------------------------------------------------- /exp/globals_for_keyword.py: -------------------------------------------------------------------------------- 1 | globals()['pass'] = pass -------------------------------------------------------------------------------- /exp/importing.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | class Test(object): 4 | PATH_TRIGGER = 'fython' 5 | 6 | def __init__(s, path): 7 | print(0, path) 8 | if path != s.PATH_TRIGGER: 9 | print(1, path) 10 | raise ImportError() 11 | 12 | def find_module(self, fullname, path=None): 13 | print(11, fullname, 22, path) 14 | 15 | sys.path_hooks.append(Test) 16 | 17 | sys.path.insert(0, Test.PATH_TRIGGER) 18 | 19 | import fython.a.b 20 | 21 | 22 | """ 23 | system is 24 | 25 | import fython.work.module 26 | 27 | use a 28 | meta_path hook 29 | 30 | collision with fython internal is guarded by the structure 31 | fython.sys 32 | 33 | use ctypes to call binary 34 | carefull extract all interface code 35 | in separate facade module 36 | """ -------------------------------------------------------------------------------- /exp/package_name.py: -------------------------------------------------------------------------------- 1 | import inspect 2 | 3 | f = inspect.currentframe() 4 | 5 | print(f.f_globals) 6 | 7 | x = inspect.getfile(f) 8 | print(inspect.getmodulename(x)) 9 | 10 | print(inspect.getmodule(f).__name__) -------------------------------------------------------------------------------- /exp/property.py: -------------------------------------------------------------------------------- 1 | class A: 2 | def f(s): 3 | return 9 4 | x = property(f) 5 | 6 | 7 | a = A() 8 | 9 | print(a.x) 10 | 11 | 12 | @property 13 | def x(): 14 | return a 15 | 16 | print(x) -------------------------------------------------------------------------------- /exp/py_exec_exp.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | for i in [1, 2]: 3 | print("print '{:d}'".format(i)) 4 | """ 5 | 6 | x = exec(s, {'i':1}) 7 | 8 | print(x) 9 | -------------------------------------------------------------------------------- /exp/py_exec_exp_2.py: -------------------------------------------------------------------------------- 1 | import inspect 2 | class A: 3 | def f(s, x): 4 | return x 5 | 6 | a=A() 7 | 8 | print( 9 | eval('f(1)', getmembers(a)) 10 | ) -------------------------------------------------------------------------------- /exp/py_import_exp.py: -------------------------------------------------------------------------------- 1 | import fython.test.importpec.a -------------------------------------------------------------------------------- /exp/python_c3_class_mro/activate_state_mro_run.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicolasessisbreton/fython/988f5a94cee8b16b0000501a22239195c73424a1/exp/python_c3_class_mro/activate_state_mro_run.py -------------------------------------------------------------------------------- /exp/regex.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | code = """XabX 4 | """ 5 | 6 | p = r'a(?:b)(X)' 7 | 8 | print( 9 | # re.findall(p, code) 10 | ) 11 | 12 | m = re.match(p, code) 13 | print( 14 | # m.group 15 | ) 16 | 17 | def f(m): 18 | print(11, m.group(1)) 19 | 20 | print( 21 | re.sub(p, f, code) 22 | ) 23 | 24 | -------------------------------------------------------------------------------- /exp/regex_2.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | code = """XabX 4 | --------^ 5 | """ 6 | 7 | p = r'^-*\^$' 8 | 9 | print( 10 | # re.findall(p, code) 11 | ) 12 | 13 | m = re.match(p, code) 14 | print( 15 | # m.group 16 | ) 17 | 18 | def f(m): 19 | print(11, m.group(0)) 20 | 21 | print( 22 | re.sub(p, 'aa', code, re.M) 23 | ) 24 | 25 | -------------------------------------------------------------------------------- /exp/trying_globals_for_keyword.py: -------------------------------------------------------------------------------- 1 | from . import globals_for_keyword as a 2 | 3 | print(a.pass) -------------------------------------------------------------------------------- /exp/variable_with_same_name_as_module.py: -------------------------------------------------------------------------------- 1 | variable_with_same_name_as_module = 1 2 | 3 | print(variable_with_same_name_as_module) -------------------------------------------------------------------------------- /exp/wrapping_w_ctypes/b.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) { 4 | int i=0; 5 | increment(&i); 6 | printf("%d\n", i); 7 | return; 8 | } -------------------------------------------------------------------------------- /exp/wrapping_w_ctypes_2/b.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) { 4 | int i=0; 5 | increment(&i); 6 | printf("%d\n", i); 7 | return; 8 | } -------------------------------------------------------------------------------- /fython/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = '1.0' 2 | 3 | from fython.load import * 4 | from fython.fytypes import * 5 | from fython.hello import * 6 | from fython.config import set_compiler, find_compiler, use_ifort, use_gfortran, use_mkl 7 | from fython.test.writer import writer 8 | 9 | find_compiler() -------------------------------------------------------------------------------- /fython/code/__init__.py: -------------------------------------------------------------------------------- 1 | from .linecod import LineCod 2 | from .childcod import ChildCod 3 | from .code import Code -------------------------------------------------------------------------------- /fython/code/code.py: -------------------------------------------------------------------------------- 1 | from fython.unit import * 2 | 3 | class Code(Unit): 4 | unit = l.code 5 | 6 | def __init__(s, bofx): 7 | s.module = bofx.module 8 | s.lineno = bofx.lineno 9 | 10 | s.raw = [] 11 | s.lexem = [] 12 | 13 | s.linecod = [] 14 | 15 | s ^ bofx 16 | 17 | # +: add linecod 18 | def __add__(s, other): 19 | s ^ other 20 | 21 | if not other.is_eofx: 22 | s.linecod.append(other) 23 | 24 | if s.nb_linecod > 1: 25 | a, b = s.linecod[-2:] 26 | a.next_linecod = b 27 | b.previous_linecod = a 28 | 29 | return s 30 | 31 | def clone(s, module): 32 | bofx = s.raw[0].clone(module) 33 | 34 | c = Code(bofx) 35 | 36 | for n in s.raw[1:]: 37 | c + n 38 | 39 | return c -------------------------------------------------------------------------------- /fython/config/__init__.py: -------------------------------------------------------------------------------- 1 | import re 2 | from .buffer import * 3 | from .debugging import * 4 | from .compilation import * 5 | from .data import Data 6 | from . import exception as err 7 | from . import extension as exts 8 | from .gen_guid import gen_guid 9 | from .get_frame_dir import get_frame_dir 10 | from . import language as l 11 | from .md5 import md5 12 | from .mkdir import mkdir 13 | from .path import * 14 | from .pickling import * 15 | from .shell import shell 16 | from . import traceback as fytbk 17 | from .trim import trim 18 | from .url import Url 19 | from . import verbose as vb -------------------------------------------------------------------------------- /fython/config/data.py: -------------------------------------------------------------------------------- 1 | class Data: 2 | def __init__(s, **kwargs): 3 | s.__dict__.update(kwargs) 4 | 5 | def __repr__(s): 6 | r = s.__class__.__name__+'\n' 7 | for key, item in s.__dict__.items(): 8 | r += '\t{:s} {:s}\n'.format(key, repr(item)) 9 | return r 10 | -------------------------------------------------------------------------------- /fython/config/debugging.py: -------------------------------------------------------------------------------- 1 | def xip(*args): 2 | for a in args: 3 | print(a, end=' ') 4 | print('') 5 | 6 | def xep(*args): 7 | for a in args: 8 | print(repr(a), end=' ') 9 | print('') 10 | 11 | 12 | def xfo(*args): 13 | for a in args: 14 | if hasattr(a, 'nfo'): 15 | print(a.nfo, end=' ') 16 | else: 17 | print(repr(a), end=' ') 18 | print('') 19 | -------------------------------------------------------------------------------- /fython/config/extension.py: -------------------------------------------------------------------------------- 1 | fy_init = ['__init__.fy'] 2 | fy_module = ['.fy'] 3 | 4 | fy = [ 5 | '/__init__.fy', 6 | '.fy', 7 | ] 8 | 9 | fort = [ 10 | '.f', 11 | '.fort', 12 | '.f77', 13 | '.f90', 14 | '.f95', 15 | '.f03', 16 | '.f08', 17 | '.F', 18 | '.F77', 19 | '.F90', 20 | '.F95', 21 | '.F03', 22 | '.F08', 23 | '.FORT', 24 | ] 25 | 26 | so = ['.so'] 27 | 28 | py_init = ['__init__.py'] 29 | py_module = ['.py'] 30 | 31 | py = [ 32 | '/__init__.py', 33 | '.py', 34 | ] 35 | 36 | importable = fy + fort + so + py 37 | 38 | out = ['.out'] -------------------------------------------------------------------------------- /fython/config/gen_guid.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | from string import ascii_lowercase as letters 3 | from random import choice 4 | from uuid import uuid4 5 | 6 | def gen_guid(): 7 | g = str(uuid4()) 8 | 9 | g = g.replace('-', '') 10 | g = g[:guid_length-1] 11 | 12 | g = choice(letters) + g 13 | 14 | return g 15 | -------------------------------------------------------------------------------- /fython/config/get_frame_dir.py: -------------------------------------------------------------------------------- 1 | import os 2 | import inspect 3 | 4 | def get_frame_dir(level=0): 5 | level += 1 6 | r = os.path.dirname( 7 | os.path.abspath( 8 | inspect.getfile( 9 | inspect.stack()[level][0] 10 | ) 11 | ) 12 | ) 13 | 14 | return r -------------------------------------------------------------------------------- /fython/config/md5.py: -------------------------------------------------------------------------------- 1 | from hashlib import md5 as m 2 | 3 | def md5(s): 4 | return m( s.encode('utf-8') ).hexdigest() -------------------------------------------------------------------------------- /fython/config/mkdir.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | def mkdir(path): 4 | if not os.path.exists(path): 5 | os.mkdir(path) -------------------------------------------------------------------------------- /fython/config/path.py: -------------------------------------------------------------------------------- 1 | from os.path import dirname 2 | from .get_frame_dir import get_frame_dir 3 | 4 | fython_root = dirname(dirname(get_frame_dir())) 5 | 6 | -------------------------------------------------------------------------------- /fython/config/pickling.py: -------------------------------------------------------------------------------- 1 | fypickling_recursion_limit = 5000 -------------------------------------------------------------------------------- /fython/config/shell.py: -------------------------------------------------------------------------------- 1 | from io import StringIO 2 | from subprocess import Popen, PIPE, STDOUT 3 | 4 | def shell(cmd): 5 | p = Popen( 6 | cmd, 7 | stdout = PIPE, 8 | stderr = STDOUT, 9 | shell = 1, 10 | universal_newlines = 1, 11 | ) 12 | 13 | out = StringIO() 14 | for line in iter(p.stdout.readline, ''): 15 | line = line.rstrip() 16 | out.write(line) 17 | out.write('\n') 18 | 19 | out = out.getvalue() 20 | 21 | error = p.poll() != 0 22 | 23 | return out, error 24 | -------------------------------------------------------------------------------- /fython/config/traceback.py: -------------------------------------------------------------------------------- 1 | dotted_size = 300 2 | max_depth = 300 3 | last_error_size = 300 4 | 5 | url = 'fython.traceback.traceback' 6 | 7 | init_frame = 'init_frame' 8 | del_frame = 'del_frame' 9 | advance_line = 'advance_line' 10 | int_to_char = 'int_to_char' 11 | 12 | init_frame_tag = '' 13 | del_frame_tag = '' 14 | advance_line_tag = '' 15 | int_to_char_tag = 'fytbk_int_to_char' 16 | 17 | 18 | -------------------------------------------------------------------------------- /fython/config/verbose.py: -------------------------------------------------------------------------------- 1 | from .data import Data 2 | from string import ascii_lowercase as alpha 3 | 4 | ndx = -1 5 | 6 | def x(): 7 | global ndx 8 | ndx += 1 9 | return alpha[ndx] 10 | 11 | 12 | class Verbose(Data): 13 | def __init__(s, level): 14 | s.level = level 15 | 16 | def __getattr__(s, name): 17 | if not s.level: 18 | return 0 19 | 20 | x = globals()[name] 21 | return x in s.level 22 | 23 | 24 | # verbosity level 25 | fml = x() 26 | lex = x() 27 | mark_newlinex = x() 28 | source_with_invisible = x() 29 | source_with_invisible_and_fml = x() 30 | unsafe_interpolation_lexem = x() 31 | yacc = x() 32 | 33 | all = alpha[:ndx] 34 | 35 | 36 | -------------------------------------------------------------------------------- /fython/fml/__init__.py: -------------------------------------------------------------------------------- 1 | from .fml import fml -------------------------------------------------------------------------------- /fython/fml/fml.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | from .fml_yacc import yacc 3 | 4 | fmt_re = re.compile('\{.*:.+\}') 5 | 6 | def fml(module, string, to_trim=0): 7 | if not fmt_re.search(string): 8 | return string 9 | 10 | elif to_trim: 11 | string = trim(string[3:-3]) 12 | 13 | string = string.lstrip('\'') 14 | string = string.rstrip('\'') 15 | 16 | fmt, args = yacc(module, string) 17 | 18 | fmt = ','.join(fmt) 19 | 20 | if fmt.endswith(',"'): 21 | fmt = fmt[:-2] + '"' 22 | 23 | fmt = '"(",{:s},")"'.format(fmt) 24 | 25 | args = ','.join(args) 26 | 27 | r = 'format({:s}) = args({:s})'.format(fmt, args) 28 | 29 | return r 30 | -------------------------------------------------------------------------------- /fython/fml/fml_desc: -------------------------------------------------------------------------------- 1 | 2 | # for string in print statement 3 | 4 | 'value of x is {:x}' 5 | 6 | # before the colon is any fortran format 7 | 8 | # other avaible format 9 | # dot '.' denotes result 10 | 11 | 'vector {v:x}' . vector [1, 2, 3] 12 | 13 | 'vector content {vc:x}' . vector 1, 2, 3 -------------------------------------------------------------------------------- /fython/fml/fml_grammar: -------------------------------------------------------------------------------- 1 | start : bofx 2 | | start eofx 3 | | start code 4 | 5 | code : newline 6 | | tab 7 | | lce 8 | | rce 9 | | string 10 | | interpolant -------------------------------------------------------------------------------- /fython/fytypes/__init__.py: -------------------------------------------------------------------------------- 1 | from .fytypes import ( 2 | fycallback, 3 | 4 | Real, 5 | Real8, 6 | Int, 7 | Int8, 8 | Char, 9 | 10 | IntS, 11 | RealS, 12 | Real8S, 13 | CharS, 14 | 15 | IntV, 16 | RealV, 17 | Real8V, 18 | CharV, 19 | 20 | IntL, 21 | RealL, 22 | Real8L, 23 | CharL, 24 | 25 | IntP, 26 | RealP, 27 | Int8P, 28 | Real8P, 29 | CharP, 30 | ) -------------------------------------------------------------------------------- /fython/hello/__init__.py: -------------------------------------------------------------------------------- 1 | from .hello import * -------------------------------------------------------------------------------- /fython/hello/hello.fy: -------------------------------------------------------------------------------- 1 | char(100) hello = 'Welcome to Fython. See the build products in' -------------------------------------------------------------------------------- /fython/hello/hello.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | from ..load import * 3 | 4 | def hello(): 5 | m = load( 6 | url = 'fython.hello.hello', 7 | force = 0, 8 | release = 0, 9 | ) 10 | 11 | prefix = m.hello(size=100, shape=[]) 12 | 13 | r = '{:s} {:s}/fython/hello/__pycache__/fycache'.format( 14 | prefix[:].decode('utf-8').strip(), 15 | fython_root, 16 | ) 17 | 18 | return r 19 | -------------------------------------------------------------------------------- /fython/import_py/__init__.py: -------------------------------------------------------------------------------- 1 | from .import_py import import_py -------------------------------------------------------------------------------- /fython/import_py/get_imported.py: -------------------------------------------------------------------------------- 1 | def get_imported(funbol): 2 | imported = [] 3 | for a in funbol.args: 4 | if a.is_namex: 5 | name = a.value 6 | alias = a.value 7 | 8 | elif a.is_opbol: 9 | name = a.modifier[0].value 10 | alias = a.modifier[2].value 11 | 12 | else: 13 | funbol.throw(err.cannot_resolve_modifier) 14 | 15 | imported.append([name, alias]) 16 | 17 | return imported -------------------------------------------------------------------------------- /fython/import_py/resolution: -------------------------------------------------------------------------------- 1 | """ 2 | only three kinds of import are possible 3 | star import 4 | import a(*) 5 | 6 | aliased namespace import 7 | import a.b = c 8 | exception 9 | import a . import a = a 10 | 11 | slice import 12 | import a(b, c=d) 13 | """ 14 | 15 | import namex . namespace import ( namex = namex ) 16 | 17 | import funbol 18 | funbol(arg0 arg1 ...) 19 | arg0 20 | * . star import 21 | ? . slice import 22 | 23 | import dotbol 24 | m0.m1. ... .mN 25 | mN 26 | funbol 27 | funbol(arg0 arg1 ...) 28 | arg0 29 | * . star import 30 | ? . slice import 31 | 32 | import ibol 33 | target = alias . namespace alias import 34 | -------------------------------------------------------------------------------- /fython/instruction/allocruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | 3 | def allocruc(linecod): 4 | s = linecod 5 | b = s.i 6 | 7 | default_size = get_default_size(linecod) 8 | 9 | for t in s.atomic_target: 10 | b != t.tbk_mark 11 | 12 | b != 'allocate( {:s} )'.format( adjust(t, default_size) ) 13 | 14 | b != t.newline 15 | 16 | b != t.tbk_emark 17 | 18 | 19 | def get_default_size(linecod): 20 | s = linecod.modifier[0] # alloc 21 | 22 | if s.is_namex: 23 | return '' 24 | 25 | elif s.is_funbol: 26 | return s.args[0] 27 | 28 | else: 29 | s.throw(err.cannot_resolve_modifier) 30 | 31 | def adjust(t, default_size): 32 | if default_size: 33 | if t.is_namex: 34 | return '{:s}({:s})'.format(t, default_size) 35 | 36 | elif t.unit in [l.slicebol, l.funbol]: 37 | return t 38 | 39 | else: 40 | t.throw(err.cannot_resolve_modifier) 41 | 42 | else: 43 | return t 44 | -------------------------------------------------------------------------------- /fython/instruction/breakruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | 3 | def breakruc(linecod): 4 | s = linecod 5 | b = s.i 6 | 7 | b != s.tbk_mark 8 | 9 | b != 'exit' 10 | b != s.newline 11 | 12 | b != s.tbk_emark -------------------------------------------------------------------------------- /fython/instruction/continueruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | 3 | def continueruc(linecod): 4 | s = linecod 5 | b = s.i 6 | 7 | b != s.tbk_mark 8 | 9 | b != 'cycle' 10 | b != s.newline 11 | 12 | b != s.tbk_emark -------------------------------------------------------------------------------- /fython/instruction/criticalruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | from ..resolve import * 3 | 4 | def criticalruc(linecod): 5 | s = linecod 6 | b = s.i 7 | 8 | b != s.tbk_mark 9 | 10 | b != 'critical' 11 | b != s.newline 12 | 13 | s.indent 14 | 15 | for x in s.childcod_target: 16 | resolve(x) 17 | 18 | s.dedent 19 | 20 | b != 'end critical' 21 | b != s.newline 22 | b != s.tbk_emark -------------------------------------------------------------------------------- /fython/instruction/deallocruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | 3 | def deallocruc(linecod): 4 | s = linecod 5 | b = s.i 6 | 7 | for t in s.atomic_target: 8 | b != t.tbk_mark 9 | 10 | b != 'deallocate( {:s} )'.format(t) 11 | 12 | b != t.newline 13 | 14 | b != t.tbk_emark 15 | -------------------------------------------------------------------------------- /fython/instruction/elementruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | 3 | intrinsic_subroutine = [ 4 | 'open', 5 | 'close', 6 | 'inquire', 7 | ] 8 | 9 | def elementruc(linecod): 10 | s = linecod 11 | b = s.i 12 | 13 | b != s.tbk_mark 14 | 15 | m = s.modifier[0] 16 | ruc = str(m) 17 | 18 | if m.is_dotbol: 19 | if m.need_call: 20 | b != 'call ' 21 | 22 | elif s.has_funbol: 23 | if s.modifier[0].value not in intrinsic_subroutine: 24 | b != 'call ' 25 | 26 | b != ruc 27 | 28 | b != s.newline 29 | 30 | b != s.tbk_emark 31 | -------------------------------------------------------------------------------- /fython/instruction/elifruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | from ..resolve import * 3 | 4 | def elifruc(linecod): 5 | s = linecod 6 | b = s.i 7 | 8 | b != 'else if ({:s}) then'.format(s.modifier_only_direct_production) 9 | b != s.newline 10 | 11 | s.indent 12 | 13 | for x in s.childcod_target: 14 | resolve(x) 15 | 16 | s.dedent 17 | 18 | if not s.next_linecod_is_elif_or_else: 19 | b != 'end if' 20 | b != s.newline 21 | b != s.tbk_emark -------------------------------------------------------------------------------- /fython/instruction/elseruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | from ..resolve import * 3 | 4 | def elseruc(linecod): 5 | s = linecod 6 | b = s.i 7 | 8 | if s.previous_linecod_is_if_or_elif: 9 | b != 'else' 10 | b != s.newline 11 | end = 'end if' 12 | 13 | elif s.previous_linecod_is_where_or_elwhere: 14 | b != 'else where' 15 | b != s.newline 16 | end = 'end where' 17 | 18 | else: 19 | s.throw(err.else_without_if_elif_where_or_elwhere) 20 | 21 | s.indent 22 | 23 | for x in s.childcod_target: 24 | resolve(x) 25 | 26 | s.dedent 27 | 28 | b != end 29 | b != s.newline 30 | 31 | if s.previous_linecod_is_where_or_elwhere: 32 | s.tbk_mark_enable() 33 | 34 | b != s.tbk_emark -------------------------------------------------------------------------------- /fython/instruction/elwhereruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | from ..resolve import * 3 | 4 | def elwhereruc(linecod): 5 | s = linecod 6 | b = s.i 7 | 8 | b != 'else where ({:s})'.format(s.modifier_only_direct_production) 9 | b != s.newline 10 | 11 | s.indent 12 | 13 | for x in s.childcod_target: 14 | resolve(x) 15 | 16 | s.dedent 17 | 18 | if not s.next_linecod_is_elwhere_or_else: 19 | b != 'end where' 20 | b != s.newline 21 | s.tbk_mark_enable() 22 | b != s.tbk_emark -------------------------------------------------------------------------------- /fython/instruction/errorruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | from ..resolve import * 3 | 4 | def errorruc(linecod): 5 | s = linecod 6 | b = s.i 7 | 8 | b != s.tbk_mark 9 | 10 | for m in s.modifier: 11 | b != m 12 | b != ' ' 13 | 14 | b != s.newline 15 | 16 | b != s.tbk_emark -------------------------------------------------------------------------------- /fython/instruction/fopruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | from ..resolve import * 3 | 4 | def fopruc(linecod): 5 | s = linecod 6 | b = s.i 7 | 8 | counter = s.modifier[-4] 9 | ketbol = s.modifier[-2] 10 | 11 | b != s.tbk_mark 12 | b != 'do concurrent ({:s}={:s}:{:s})'.format( 13 | counter, 14 | ketbol.modifier[1], 15 | ketbol.modifier[3], 16 | ) 17 | 18 | b != s.newline 19 | 20 | s.indent 21 | 22 | for x in s.childcod_target: 23 | resolve(x) 24 | 25 | s.dedent 26 | 27 | b += 'end do' 28 | 29 | b != s.tbk_emark -------------------------------------------------------------------------------- /fython/instruction/forruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | from ..resolve import * 3 | 4 | def forruc(linecod): 5 | s = linecod 6 | b = s.i 7 | 8 | counter = s.modifier[-4] 9 | ketbol = s.modifier[-2] 10 | 11 | b != s.tbk_mark 12 | b != 'do ' 13 | 14 | for m in s.modifier[1:-4]: 15 | b != m 16 | b != ' ' 17 | 18 | b != '{:s} = '.format(counter) 19 | for x in ketbol.modifier[1:-1]: 20 | b != x 21 | 22 | b != s.newline 23 | 24 | s.indent 25 | 26 | for x in s.childcod_target: 27 | resolve(x) 28 | 29 | s.dedent 30 | 31 | b += 'end do' 32 | 33 | b != s.tbk_emark -------------------------------------------------------------------------------- /fython/instruction/ifruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | from ..resolve import * 3 | 4 | def ifruc(linecod): 5 | s = linecod 6 | b = s.i 7 | 8 | b != s.tbk_mark 9 | 10 | b != 'if ({:s}) then'.format(s.modifier_only_direct_production) 11 | b != s.newline 12 | 13 | s.indent 14 | 15 | for x in s.childcod_target: 16 | resolve(x) 17 | 18 | s.dedent 19 | 20 | if not s.next_linecod_is_elif_or_else: 21 | b != 'end if' 22 | b != s.newline 23 | b != s.tbk_emark -------------------------------------------------------------------------------- /fython/instruction/ompruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | 3 | def ompruc(linecod): 4 | s = linecod 5 | b = s.i 6 | 7 | b != '!$omp' 8 | 9 | for t in s.modifier_and_atomic_target: 10 | if t.is_namex: 11 | if t.value == l.fork: 12 | b &= 'do' 13 | 14 | else: 15 | b &= t 16 | 17 | else: 18 | b &= t 19 | 20 | b != linecod.newline -------------------------------------------------------------------------------- /fython/instruction/passruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | 3 | def passruc(linecod): 4 | pass -------------------------------------------------------------------------------- /fython/instruction/printruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | from fython.printruc import printruc as fprintruc 3 | 4 | def printruc(linecod): 5 | s = linecod 6 | 7 | b = s.i 8 | 9 | b != s.tbk_mark 10 | 11 | b += fprintruc(s) 12 | 13 | b != s.tbk_emark -------------------------------------------------------------------------------- /fython/instruction/privateruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | 3 | def privateruc(linecod): 4 | s = linecod 5 | b = s.b 6 | 7 | b != 'private :: ' 8 | 9 | for t in s.atomic_target: 10 | b != t 11 | b != ', ' 12 | 13 | b.rstrip(', ') 14 | 15 | b != s.newline -------------------------------------------------------------------------------- /fython/instruction/publicruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | 3 | def publicruc(linecod): 4 | s = linecod 5 | b = s.b 6 | 7 | b != 'public :: ' 8 | 9 | for t in s.atomic_target: 10 | b != t 11 | b != ', ' 12 | 13 | b.rstrip(', ') 14 | 15 | b != s.newline -------------------------------------------------------------------------------- /fython/instruction/readruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | from fython.readruc import readruc as process_readruc 3 | 4 | def readruc(linecod): 5 | s = linecod 6 | 7 | b = s.i 8 | 9 | b != s.tbk_mark 10 | 11 | b *= process_readruc(s) 12 | 13 | b != s.tbk_emark 14 | 15 | -------------------------------------------------------------------------------- /fython/instruction/returnruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | 3 | def returnruc(linecod): 4 | s = linecod 5 | b = s.i 6 | 7 | b != s.tbk_eframe 8 | 9 | b != l.riturn 10 | 11 | b != s.newline 12 | -------------------------------------------------------------------------------- /fython/instruction/stopruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | 3 | def stopruc(linecod): 4 | s = linecod 5 | b = s.i 6 | 7 | b != s.tbk_mark 8 | 9 | b != 'stop' 10 | b != s.newline 11 | 12 | b != s.tbk_emark -------------------------------------------------------------------------------- /fython/instruction/syncruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | 3 | def syncruc(linecod): 4 | s = linecod 5 | b = s.i 6 | 7 | b != s.tbk_mark 8 | 9 | for m in s.modifier: 10 | b != m 11 | b != ' ' 12 | 13 | b != s.newline 14 | 15 | b != s.tbk_emark -------------------------------------------------------------------------------- /fython/instruction/templateruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | 3 | def templateruc(linecod): 4 | linecod.module.is_template = 1 -------------------------------------------------------------------------------- /fython/instruction/whereruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | from ..resolve import * 3 | 4 | def whereruc(linecod): 5 | s = linecod 6 | 7 | b = s.i 8 | 9 | b != s.tbk_mark 10 | 11 | b != 'where ({:s})'.format(s.modifier_only_direct_production) 12 | b != s.newline 13 | 14 | s.indent 15 | 16 | s.tbk_mark_disable() 17 | 18 | for x in s.childcod_target: 19 | resolve(x) 20 | 21 | s.dedent 22 | 23 | if not s.next_linecod_is_elwhere_or_else: 24 | b != 'end where' 25 | b != s.newline 26 | s.tbk_mark_enable() 27 | b != s.tbk_emark -------------------------------------------------------------------------------- /fython/instruction/whileruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | from ..resolve import * 3 | 4 | def whileruc(linecod): 5 | s = linecod 6 | 7 | b = s.i 8 | 9 | b != s.tbk_mark 10 | 11 | b != 'do while ({:s})'.format(s.modifier_only_direct_production) 12 | b != s.newline 13 | 14 | s.indent 15 | 16 | for x in s.childcod_target: 17 | resolve(x) 18 | 19 | s.dedent 20 | 21 | b += 'end do' 22 | 23 | b != s.tbk_emark -------------------------------------------------------------------------------- /fython/instruction/xipruc.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | from .printruc import printruc 3 | 4 | def xipruc(linecod): 5 | s = linecod 6 | 7 | if s.debug: 8 | printruc(s) -------------------------------------------------------------------------------- /fython/interpolant/interpolant.py: -------------------------------------------------------------------------------- 1 | from fython.config.trim import trim as _trim 2 | 3 | _write_cache = '' 4 | 5 | def write(source, *args, end='\n', **kwargs): 6 | global _write_cache 7 | source = _trim(source) 8 | _write_cache += source.format(*args, **kwargs) 9 | _write_cache += end 10 | return _write_cache 11 | 12 | def _reset_cache(): 13 | global _write_cache 14 | _write_cache = '' 15 | -------------------------------------------------------------------------------- /fython/kompile/__init__.py: -------------------------------------------------------------------------------- 1 | from .kompile import kompile -------------------------------------------------------------------------------- /fython/kompile/kompile.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | from .stack import Stack 3 | 4 | def kompile( 5 | url, 6 | cwd, 7 | release, 8 | force, 9 | verbose, 10 | ): 11 | stack = Stack(release, cwd, force, verbose) 12 | 13 | stack.load(fytbk.url, cwd) 14 | 15 | stack.load(url, cwd, is_target=1) 16 | 17 | if stack.need_link: 18 | stack.link() 19 | 20 | return stack.target -------------------------------------------------------------------------------- /fython/lex/__init__.py: -------------------------------------------------------------------------------- 1 | from .lex import lex -------------------------------------------------------------------------------- /fython/lex/config.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | 3 | leading_space_re = re.compile('\s*') 4 | 5 | bofx = '' 6 | eofx = '' 7 | 8 | linefeedx = '' 9 | newlinex = '' 10 | 11 | indentx = '' 12 | dedentx = '' 13 | 14 | newlinex_mark = '<{:d}' 15 | 16 | len_newlinex = len(newlinex) 17 | pos_lineno_linefeedx = len('' is info avalaible at resolution node 6 | 7 | '?' is the else resolution 8 | when none of the previous resolution matched 9 | -------------------------------------------------------------------------------- /fython/resolve/__init__.py: -------------------------------------------------------------------------------- 1 | from .resolve import resolve -------------------------------------------------------------------------------- /fython/resolve/defr.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | 3 | def defR(linecod): 4 | m = linecod.modifier[-1] 5 | 6 | if m.is_ibol: 7 | return l.lexiruc 8 | 9 | else: 10 | return l.routpec -------------------------------------------------------------------------------- /fython/resolve/unaryr.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | 3 | def unaryR(linecod): 4 | s = linecod.modifier[0] # element 5 | 6 | if s.is_namex: 7 | if s.value in instruction: 8 | return instruction[s.value] 9 | 10 | else: 11 | return l.elementruc 12 | else: 13 | return l.elementruc 14 | 15 | instruction = { 16 | l.breakk : l.breakruc, 17 | l.continuek : l.continueruc, 18 | l.passk : l.passruc, 19 | l.stop : l.stopruc, 20 | l.riturn : l.returnruc, 21 | } -------------------------------------------------------------------------------- /fython/spec/importpec_resolution: -------------------------------------------------------------------------------- 1 | import element 2 | element.url 3 | fy . fyR 4 | fort . fortR 5 | so . so import 6 | not found . fortR 7 | 8 | fyR 9 | > import element 10 | element 11 | ibol . fy aliased namespace import 12 | 13 | namex . fy aliased namespace import 14 | 15 | funbol(arg0 arg1 ...) 16 | arg0 17 | * . fy star import 18 | ? . fy slice import 19 | 20 | fortR 21 | > import element 22 | element 23 | funbol(arg0 arg1 ...) 24 | arg0 25 | * . fort star import 26 | ? . fort slice import ; use only -------------------------------------------------------------------------------- /fython/spec/interfacepec.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | from ..resolve import * 3 | 4 | def interfacepec(linecod): 5 | s = linecod 6 | b = s.b 7 | 8 | for m in s.modifier_only: 9 | b != m 10 | b != ' ' 11 | 12 | b += 'interface' 13 | 14 | b.indent 15 | 16 | s.add_frame() 17 | 18 | s.contains_disable 19 | 20 | for x in s.childcod_target: 21 | resolve(x) 22 | 23 | s.pop_frame() 24 | 25 | b.dedent 26 | 27 | b += 'end interface' -------------------------------------------------------------------------------- /fython/symbol/__init__.py: -------------------------------------------------------------------------------- 1 | from .dotbol import DotBol 2 | from .enumbol import EnumBol 3 | from .funbol import FunBol 4 | from .ibol import IBol 5 | from .ketbol import KetBol 6 | from .bitbol import BitBol 7 | from .opbol import OpBol 8 | from .packagebol import PackageBol 9 | from .parbol import ParBol 10 | from .semibol import SemiBol 11 | from .slicebol import SliceBol -------------------------------------------------------------------------------- /fython/symbol/bitbol.py: -------------------------------------------------------------------------------- 1 | from fython.unit import * 2 | 3 | bitwise_function = { 4 | '<<' : 'shiftl', 5 | '&' : 'iand', 6 | '^' : 'ieor', 7 | '|' : 'ior', 8 | '>>' : 'shiftr', 9 | } 10 | 11 | class BitBol(Unit): 12 | unit = l.bitbol 13 | 14 | def __init__(s, left, op, right): 15 | s.module = left.module 16 | s.lineno = left.lineno 17 | s.value = '' 18 | 19 | s.raw = [left, op, right] 20 | s.lexem = [left, op, right] 21 | s.modifier = [left, op, right] 22 | 23 | s.left = left 24 | s.op = op 25 | s.right = right 26 | 27 | def clone(s, module): 28 | return BitBol(s.left, s.op, s.right) 29 | 30 | def __str__(s): 31 | b = Buffer(newline='') 32 | 33 | b += bitwise_function[s.op.value] 34 | b += '(' 35 | b += s.left 36 | b += ',' 37 | b += s.right 38 | b += ')' 39 | 40 | return str(b) 41 | 42 | -------------------------------------------------------------------------------- /fython/symbol/enumbol.py: -------------------------------------------------------------------------------- 1 | from fython.unit import * 2 | 3 | class EnumBol(Unit): 4 | unit = l.enumbol 5 | 6 | def __init__(s, colonx): 7 | s.module = colonx.module 8 | s.lineno = colonx.lineno 9 | 10 | s.raw = [] 11 | s.lexem = [] 12 | 13 | s.modifier = [] 14 | 15 | s ^ colonx 16 | 17 | # &: add modifier 18 | def __and__(s, other): 19 | s ^ other 20 | if other.is_semibol: 21 | s.modifier.extend(other.modifier) 22 | 23 | elif not other.is_newlinex: 24 | s.modifier.append(other) 25 | 26 | return s 27 | 28 | def clone(s, module): 29 | colonx = s.raw[0].clone(module) 30 | 31 | e = EnumBol(colonx) 32 | 33 | for m in s.raw[1:]: 34 | e & m.clone(module) 35 | 36 | return e -------------------------------------------------------------------------------- /fython/symbol/ketbol.py: -------------------------------------------------------------------------------- 1 | from fython.unit import * 2 | 3 | class KetBol(Unit): 4 | unit = l.ketbol 5 | 6 | def __init__(s, lketx): 7 | s.module = lketx.module 8 | s.lineno = lketx.lineno 9 | 10 | s.raw = [] 11 | s.lexem = [] 12 | 13 | s.modifier = [lketx] 14 | 15 | s ^ lketx 16 | 17 | s.is_array = 0 18 | 19 | # &: add modifier 20 | def __and__(s, other): 21 | s ^ other 22 | s.modifier.append(other) 23 | 24 | if other.is_commax: 25 | s.is_array = 1 26 | 27 | return s 28 | 29 | def clone(s, module): 30 | lketx = s.raw[0].clone(module) 31 | 32 | k = KetBol(lketx) 33 | 34 | for m in s.raw[1:]: 35 | k & m.clone(module) 36 | 37 | return k 38 | 39 | def __str__(s): 40 | b = Buffer(newline='') 41 | for m in s.modifier: 42 | b += m 43 | 44 | b = str(b) 45 | 46 | if not s.is_array: 47 | b = '({:s})'.format(b[1:-1]) 48 | 49 | return b 50 | 51 | -------------------------------------------------------------------------------- /fython/symbol/opbol.py: -------------------------------------------------------------------------------- 1 | from fython.unit import * 2 | 3 | class OpBol(Unit): 4 | unit = l.opbol 5 | 6 | def __init__(s, a, b, c=None): 7 | s.module = a.module 8 | s.lineno = a.lineno 9 | s.value = '' 10 | 11 | s.raw = [] 12 | s.lexem = [] 13 | 14 | s.modifier = [] 15 | 16 | s & a 17 | s & b 18 | if c: 19 | s & c 20 | 21 | # &: add modifier 22 | def __and__(s, other): 23 | s ^ other 24 | 25 | if other.is_opbol: 26 | s.modifier.extend(other.modifier) 27 | 28 | else: 29 | s.modifier.append(other) 30 | 31 | return s 32 | 33 | def clone(s, module): 34 | a = s.raw[0].clone(module) 35 | b = s.raw[1].clone(module) 36 | 37 | o = OpBol(a, b) 38 | 39 | for m in s.raw[2:]: 40 | o & m.clone(module) 41 | 42 | return o 43 | 44 | def __str__(s): 45 | b = Buffer(newline='') 46 | for m in s.modifier: 47 | b += m 48 | return str(b) 49 | 50 | -------------------------------------------------------------------------------- /fython/symbol/parbol.py: -------------------------------------------------------------------------------- 1 | from fython.unit import * 2 | 3 | class ParBol(Unit): 4 | unit = l.parbol 5 | 6 | def __init__(s, lparx): 7 | s.module = lparx.module 8 | s.lineno = lparx.lineno 9 | 10 | s.value = lparx.value 11 | 12 | s.raw = [] 13 | s.lexem = [] 14 | s.modifier = [lparx] 15 | 16 | s ^ lparx 17 | 18 | # &: add modifier 19 | def __and__(s, other): 20 | s ^ other 21 | s.modifier.append(other) 22 | return s 23 | 24 | def clone(s, module): 25 | lparx = s.raw[0].clone(module) 26 | 27 | k = ParBol(lparx) 28 | 29 | for m in s.raw[1:]: 30 | k & m.clone(module) 31 | 32 | return k 33 | 34 | def __str__(s): 35 | b = Buffer(newline='') 36 | for m in s.modifier: 37 | b += m 38 | return str(b) 39 | 40 | -------------------------------------------------------------------------------- /fython/symbol/semibol.py: -------------------------------------------------------------------------------- 1 | from fython.unit import * 2 | 3 | class SemiBol(Unit): 4 | unit = l.semibol 5 | 6 | def __init__(s, a, semix, b): 7 | s.module = a.module 8 | s.lineno = a.lineno 9 | 10 | s.raw = [] 11 | s.lexem = [] 12 | 13 | s.modifier = [] 14 | 15 | s & a & semix & b 16 | 17 | 18 | # &: add modifier 19 | def __and__(s, x): 20 | s ^ x 21 | 22 | if x.is_semibol: 23 | s.modifier.extend(x.modifier) 24 | 25 | elif not x.is_semix: 26 | s.modifier.append(x) 27 | 28 | return s 29 | 30 | def clone(s, module): 31 | a = s.raw[0].clone(module) 32 | semix = s.raw[1].clone(module) 33 | b = s.raw[2].clone(module) 34 | 35 | i = SemiBol(a, semix, b) 36 | 37 | for x in s.raw[3:]: 38 | i & x 39 | 40 | return i 41 | 42 | -------------------------------------------------------------------------------- /fython/test/__init__.py: -------------------------------------------------------------------------------- 1 | from numpy.testing import * 2 | from ..config import * 3 | from fython import * 4 | from .writer import writer 5 | from .imp import imp 6 | from .shell import shell -------------------------------------------------------------------------------- /fython/test/alltest.py: -------------------------------------------------------------------------------- 1 | import os 2 | from importlib import import_module 3 | from fython.config import * 4 | 5 | n = len(fython_root) 6 | cwd = get_frame_dir() 7 | 8 | for dirpath, dirnames, filenames in os.walk(cwd): 9 | for f in filenames: 10 | name, ext = os.path.splitext(f) 11 | 12 | path = os.path.abspath('{:s}/{:s}'.format(dirpath, name)) 13 | path = path[n+1:] 14 | dotted = path.replace('/', '.') 15 | 16 | if name.startswith('_'): 17 | continue 18 | if ext != '.py': 19 | continue 20 | if name[:3] != 'all' and 'test' in name: 21 | print('--', dotted, '--') 22 | import_module(dotted) 23 | print() 24 | 25 | print('---') 26 | print('All tests passed.') -------------------------------------------------------------------------------- /fython/test/callback/callback_test.py: -------------------------------------------------------------------------------- 1 | from mttc import * 2 | from ctypes import * 3 | import numpy as np 4 | 5 | m = load('.fy_caller', force = 1) 6 | 7 | @fycallback(Int, Real, Int, Int, Int, Real) 8 | def f(xint, xreal, nintv, nrealv, xintv, xrealv): 9 | x = IntP(xint) 10 | y = RealP(xreal) 11 | xv = IntP(xintv, nintv) 12 | yv = RealP(xrealv, nrealv) 13 | 14 | print('hello from python', x, y, xv, yv) 15 | 16 | x[:] *= 2 17 | y[:] *= 2 18 | xv[:] *= 2 19 | yv[:] *= 2 20 | 21 | 22 | m.f(py_fct_pointer_int = f.fy_address) -------------------------------------------------------------------------------- /fython/test/callback/fy_caller.fy: -------------------------------------------------------------------------------- 1 | import: 2 | iso_c_binding(*) 3 | 4 | interface: 5 | def iso(c) py_fct: 6 | int(c_int) inout: 7 | xint 8 | real(c_float) inout: 9 | xreal 10 | int(c_int) in: 11 | nintv 12 | nrealv 13 | int(c_int) inout: 14 | xintv(*) 15 | real(c_float) inout: 16 | xrealv(*) 17 | 18 | def f: 19 | int(8) in: 20 | py_fct_pointer_int 21 | c_funptr: 22 | py_fct_pointer 23 | proc(py_fct) pointer: 24 | pyf 25 | int: 26 | x 27 | xv(2) 28 | real: 29 | y 30 | yv(2) 31 | 32 | print 'fython start: {:py_fct_pointer_int}' 33 | py_fct_pointer = transfer(py_fct_pointer_int, py_fct_pointer) 34 | c_f_procpointer(py_fct_pointer, pyf) 35 | print 'pyf called' 36 | x = 1 37 | y = 0.5 38 | xv = 10 39 | yv = 5.5 40 | pyf(x, y, 2, 2, xv, yv) 41 | print 'fython: after call: {:x} {:y} {v:xv} {v:yv}' 42 | print 'fython exit' 43 | -------------------------------------------------------------------------------- /fython/test/classpec/a.fy: -------------------------------------------------------------------------------- 1 | int z 2 | 3 | class A: 4 | real x 5 | 6 | def pure f: 7 | self in 8 | real res r 9 | r = self.x + z 10 | 11 | def g: 12 | s inout 13 | real in x 14 | real res r 15 | r = x + 3 + s.h 16 | 17 | def pget h: 18 | s arg 19 | real res r 20 | r = 10 + s.x 21 | 22 | 23 | 24 | A a 25 | z = 1 26 | a.x = 1 27 | print '{:a.f() + a.g(1.) + a.h}' -------------------------------------------------------------------------------- /fython/test/classpec/class_nested_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | class A: 4 | real x 5 | class B: 6 | real y 7 | """ 8 | 9 | from fython.test import * 10 | 11 | shell('rm -rf a/ a.* b.*') 12 | 13 | writer(s) 14 | 15 | # w = load('.a', release=1, verbose=0, run_main=0) 16 | # print(open(w.module.url.fortran_path, 'r').read()) 17 | 18 | # not supported -------------------------------------------------------------------------------- /fython/test/classpec/class_self_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | class A: 4 | int x 5 | 6 | def f: 7 | s in 8 | print 'f from A {:s.x}' 9 | 10 | A a 11 | a.x = 10 12 | a.f() 13 | """ 14 | 15 | from fython.test import * 16 | 17 | shell('rm -rf a/ a.* b.*') 18 | 19 | writer(s) 20 | 21 | w = load('.a', release=1, verbose=0, run_main=0) 22 | # print(open(w.module.url.fortran_path, 'r').read()) 23 | -------------------------------------------------------------------------------- /fython/test/classpec/classpec_all_1_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | int z 4 | 5 | class A: 6 | real x 7 | 8 | def pure f: 9 | self in 10 | real res r 11 | r = self.x + z 12 | 13 | def pget h: 14 | s arg 15 | real res r 16 | r = 10 + s.x 17 | 18 | def g: 19 | s inout 20 | real in x 21 | real res r 22 | r = x + 3 + s.h 23 | 24 | 25 | A a 26 | z = 1 27 | a.x = 1 28 | print '{:a.f() + a.g(1.) + a.h}' 29 | """ 30 | 31 | from fython.test import * 32 | 33 | shell('rm -rf a/ a.* b.*') 34 | 35 | writer(s) 36 | 37 | w = load('.a', release=1, verbose=0, run_main=0) 38 | # print(open(w.module.url.fortran_path, 'r').read()) 39 | -------------------------------------------------------------------------------- /fython/test/classpec/classpec_all_2_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | int z 4 | 5 | class A: 6 | real x 7 | 8 | def pure f: 9 | self in 10 | real res r 11 | r = self.x + z 12 | 13 | def g: 14 | s inout 15 | real in x 16 | real res r 17 | r = x + 3 + s.h 18 | 19 | def pget h: 20 | s arg 21 | real res r 22 | r = 10 + s.x 23 | 24 | 25 | 26 | A a 27 | z = 1 28 | a.x = 1 29 | print '{:a.f() + a.g(1.) + a.h}' 30 | """ 31 | 32 | from fython.test import * 33 | 34 | shell('rm -rf a/ a.* b.*') 35 | 36 | writer(s) 37 | 38 | w = load('.a', release=1, verbose=0, run_main=0) 39 | # print(open(w.module.url.fortran_path, 'r').read()) 40 | 41 | -------------------------------------------------------------------------------- /fython/test/classpec/classpec_field_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | class A: 4 | real x 5 | int y 6 | """ 7 | 8 | from fython.test import * 9 | 10 | shell('rm -rf a/ a.* b.*') 11 | 12 | writer(s) 13 | 14 | w = load('.a', release=1, verbose=0, run_main=0) 15 | # print(open(w.module.url.fortran_path, 'r').read()) 16 | -------------------------------------------------------------------------------- /fython/test/classpec/classpec_inheritance_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | class A: 4 | int x 5 | 6 | class B(A): 7 | int y 8 | 9 | B b 10 | b.x = 1 11 | b.y = 2 12 | 13 | print '{:b.x} {:b.y}' 14 | """ 15 | 16 | from fython.test import * 17 | 18 | shell('rm -rf a/ a.* b.*') 19 | 20 | writer(s) 21 | 22 | w = load('.a', release=1, verbose=0, run_main=0) 23 | # print(open(w.module.url.fortran_path, 'r').read()) 24 | -------------------------------------------------------------------------------- /fython/test/classpec/classpec_method_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | class A: 4 | def f: 5 | self in 6 | print '1' 7 | 8 | A a 9 | a.f() 10 | """ 11 | 12 | from fython.test import * 13 | 14 | shell('rm -rf a/ a.* b.*') 15 | 16 | writer(s) 17 | 18 | w = load('.a', release=1, verbose=0, run_main=0) 19 | print(open(w.module.url.fortran_path, 'r').read()) 20 | -------------------------------------------------------------------------------- /fython/test/classpec/classpec_mro_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | class A: 4 | def f: 5 | self in 6 | print 'f from A' 7 | 8 | class B(A): 9 | pass 10 | 11 | B b 12 | b.f() 13 | """ 14 | 15 | from fython.test import * 16 | 17 | shell('rm -rf a/ a.* b.*') 18 | 19 | writer(s) 20 | 21 | w = load('.a', release=1, verbose=0, run_main=0) 22 | # print(open(w.module.url.fortran_path, 'r').read()) 23 | -------------------------------------------------------------------------------- /fython/test/classpec/classpec_pget_pset_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | class A: 4 | real z 5 | 6 | def pget x: 7 | s in 8 | real res r 9 | r = s.z 10 | 11 | def pset x: 12 | s inout 13 | real in value 14 | s.z = value 15 | 16 | A a 17 | a.x = 10. 18 | 19 | print '{:a.x}' 20 | """ 21 | 22 | from fython.test import * 23 | 24 | writer(s) 25 | 26 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 27 | print(open(w.module.url.fortran_path, 'r').read()) 28 | 29 | -------------------------------------------------------------------------------- /fython/test/classpec/classpec_pget_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | class A: 4 | def pget f: 5 | self in 6 | print '1' 7 | 8 | A a 9 | a.f 10 | """ 11 | 12 | from fython.test import * 13 | 14 | shell('rm -rf a/ a.* b.*') 15 | 16 | writer(s) 17 | 18 | w = load('.a', release=1, verbose=0, run_main=0) 19 | # print(open(w.module.url.fortran_path, 'r').read()) 20 | -------------------------------------------------------------------------------- /fython/test/classpec/classpec_pset_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | class A: 4 | def pset f: 5 | self in 6 | int in x 7 | print '{:x}' 8 | 9 | A a 10 | a.f = 10 11 | """ 12 | 13 | from fython.test import * 14 | 15 | shell('rm -rf a/ a.* b.*') 16 | 17 | writer(s) 18 | 19 | w = load('.a', release=1, verbose=0, run_main=0) 20 | # print(open(w.module.url.fortran_path, 'r').read()) 21 | -------------------------------------------------------------------------------- /fython/test/classpec/classpec_spec_interpolation_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | class A: 4 | int x 5 | 6 | .b.fy 7 | import .a(*) 8 | 9 | class A: 10 | int y 11 | 12 | A a 13 | a.x = 1 14 | a.y = 2 15 | 16 | print '{:a.x} {:a.y}' 17 | """ 18 | 19 | from fython.test import * 20 | 21 | shell('rm -rf a/ a.* b.*') 22 | 23 | writer(s) 24 | 25 | w = load('.b', release=1, verbose=0, run_main=0) 26 | # print(open(w.module.url.fortran_path, 'r').read()) 27 | -------------------------------------------------------------------------------- /fython/test/coarray/a.fy: -------------------------------------------------------------------------------- 1 | int a[*] 2 | 3 | critical: 4 | a = 1 5 | 6 | stop 7 | error stop -------------------------------------------------------------------------------- /fython/test/coarray/corray_1_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | int a[*] 4 | """ 5 | 6 | from fython.test import * 7 | 8 | shell('rm -rf a/ a.* b.*') 9 | 10 | writer(s) 11 | 12 | # w = load('.a', release=1, verbose=0, run_main=0) 13 | # print(open(w.module.url.fortran_path, 'r').read()) 14 | -------------------------------------------------------------------------------- /fython/test/coarray/corray_2_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | int a(10)[*] 4 | """ 5 | 6 | from fython.test import * 7 | 8 | shell('rm -rf a/ a.* b.*') 9 | 10 | writer(s) 11 | 12 | # w = load('.a', release=1, verbose=0, run_main=0) 13 | # print(open(w.module.url.fortran_path, 'r').read()) 14 | -------------------------------------------------------------------------------- /fython/test/coarray/corray_3_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | int i 4 | int a[*] 5 | 6 | if this_image() == 1: 7 | for i in [1, num_images()]: 8 | a[i] = i 9 | 10 | sync all 11 | """ 12 | 13 | from fython.test import * 14 | 15 | shell('rm -rf a/ a.* b.*') 16 | 17 | writer(s) 18 | 19 | # w = load('.a', release=1, verbose=0, run_main=1) 20 | # print(open(w.module.url.fortran_path, 'r').read()) 21 | -------------------------------------------------------------------------------- /fython/test/coarray/corray_4_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | int a[*] 4 | 5 | critical: 6 | a = 1 7 | 8 | stop 9 | error stop 10 | """ 11 | 12 | from fython.test import * 13 | 14 | shell('rm -rf a/ a.* b.*') 15 | 16 | writer(s) 17 | 18 | # w = load('.a', release=1, verbose=0, run_main=1) 19 | # print(open(w.module.url.fortran_path, 'r').read()) 20 | -------------------------------------------------------------------------------- /fython/test/config/a/b/c/d/a.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | def f(): 3 | return get_frame_dir(1) -------------------------------------------------------------------------------- /fython/test/config/b/b.py: -------------------------------------------------------------------------------- 1 | import fython.test.config.a.a as a -------------------------------------------------------------------------------- /fython/test/config/c.py: -------------------------------------------------------------------------------- 1 | from fython.test.config.b.b import * 2 | print(a.f()) 3 | -------------------------------------------------------------------------------- /fython/test/config/d.py: -------------------------------------------------------------------------------- 1 | import fython.test.config.a.b.c.d.a as a 2 | print(a.f()) 3 | -------------------------------------------------------------------------------- /fython/test/config/get_frame_dir_1_test.py: -------------------------------------------------------------------------------- 1 | from fython.test import * 2 | 3 | shell('rm -rf a/ a.py d.py') 4 | 5 | writer(""" 6 | .a.b.c.d.a.py 7 | from ..config import * 8 | def f(): 9 | return get_frame_dir(1) 10 | 11 | .d.py 12 | import ~.a.b.c.d.a.py as a 13 | print(a.f()) 14 | 15 | """) 16 | 17 | 18 | # imp('.d') -------------------------------------------------------------------------------- /fython/test/config/get_frame_dir_2_test.py: -------------------------------------------------------------------------------- 1 | from fython.test import * 2 | 3 | shell('rm -rf a/ b/ a.py b.py c.py') 4 | 5 | writer(""" 6 | .a.a.py 7 | from fython.config import * 8 | def f(): 9 | return get_frame_dir(1) 10 | 11 | .b.b.py 12 | import ~..a.a.py as a 13 | 14 | .c.py 15 | from ~.b.b.py import * 16 | print(a.f()) 17 | 18 | """) 19 | 20 | 21 | # imp('.c') -------------------------------------------------------------------------------- /fython/test/config/trim_test.py: -------------------------------------------------------------------------------- 1 | from fython.config import * 2 | from numpy.testing import * 3 | 4 | def p(s, e): 5 | r = trim(s) 6 | print(repr(r)) 7 | assert_equal(r, e) 8 | 9 | '\nis without\nleading space\nbeginning\nend\n' 10 | 11 | p(""" 12 | a 13 | b 14 | c 15 | """, 16 | 'a\nb\nc', 17 | ) 18 | 19 | 20 | p(""" 21 | a 22 | b 23 | c 24 | 25 | """, 26 | 'a\nb\nc\n' 27 | ) 28 | 29 | p(''' 30 | 31 | is without 32 | leading space 33 | beginning 34 | end 35 | 36 | ''', 37 | '\nis without\nleading space\nbeginning\nend\n' 38 | ) 39 | -------------------------------------------------------------------------------- /fython/test/dotbol/a.fy: -------------------------------------------------------------------------------- 1 | class A: 2 | real x 3 | 4 | A a 5 | 6 | print '{:a.x}' -------------------------------------------------------------------------------- /fython/test/dotbol/dotbol_1_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | class A: 4 | real x 5 | 6 | A a 7 | 8 | print '{:a.x}' 9 | """ 10 | 11 | from fython.test import * 12 | 13 | writer(s) 14 | 15 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 16 | # print(open(w.module.url.fortran_path, 'r').read()) 17 | 18 | -------------------------------------------------------------------------------- /fython/test/dotbol/dotbol_2_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | class A: 4 | real x 5 | 6 | class B: 7 | A a 8 | 9 | B b 10 | 11 | print '{:b.a.x}' 12 | """ 13 | 14 | from fython.test import * 15 | 16 | writer(s) 17 | 18 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 19 | # print(open(w.module.url.fortran_path, 'r').read()) 20 | 21 | -------------------------------------------------------------------------------- /fython/test/dotbol/dotbol_3_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | class A: 4 | real x 5 | 6 | class B: 7 | A a 8 | 9 | class C: 10 | B b 11 | 12 | class D: 13 | C c 14 | 15 | 16 | D d 17 | d.c.b.a.x = 10 18 | 19 | print '{:d.c.b.a.x}' 20 | """ 21 | 22 | from fython.test import * 23 | 24 | writer(s) 25 | 26 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 27 | # print(open(w.module.url.fortran_path, 'r').read()) 28 | 29 | -------------------------------------------------------------------------------- /fython/test/dotbol/dotbol_4_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | class A: 4 | real z 5 | 6 | def pget x: 7 | s in 8 | real res r 9 | r = s.z 10 | 11 | def pset x: 12 | s inout 13 | real in value 14 | s.z = value 15 | 16 | class B: 17 | A a 18 | 19 | class C: 20 | B b 21 | 22 | class D: 23 | C c 24 | 25 | 26 | D d 27 | d.c.b.a.x = 10. 28 | 29 | print '{:d.c.b.a.x}' 30 | """ 31 | 32 | from fython.test import * 33 | 34 | writer(s) 35 | 36 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 37 | # print(open(w.module.url.fortran_path, 'r').read()) 38 | 39 | -------------------------------------------------------------------------------- /fython/test/dotbol/dotbol_5_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | class A: 4 | real u = 1 5 | 6 | real z 7 | 8 | def pget x: 9 | s in 10 | real res r 11 | r = s.z 12 | 13 | def pset x: 14 | s inout 15 | real in value 16 | s.z = value 17 | 18 | class B: 19 | A a 20 | 21 | class C: 22 | B b 23 | 24 | class D: 25 | C c 26 | 27 | 28 | D d 29 | d.c.b.a.x = 10. 30 | 31 | print '{:d.c.b.a.u} {:d.c.b.a.x}' 32 | """ 33 | 34 | from fython.test import * 35 | 36 | writer(s) 37 | 38 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 39 | # print(open(w.module.url.fortran_path, 'r').read()) 40 | 41 | -------------------------------------------------------------------------------- /fython/test/file: -------------------------------------------------------------------------------- 1 | x3 8 2 | x4 8 3 | x5 8 4 | x8 5 | -------------------------------------------------------------------------------- /fython/test/fml/multiline_test.py: -------------------------------------------------------------------------------- 1 | from fython.test import * 2 | from fython.fml import * 3 | 4 | class module: 5 | def __getattr__(s, n): 6 | return 0 7 | 8 | m = module() 9 | m.verbose = m 10 | 11 | x = ''' 12 | {f:float} 13 | {i:int} 14 | {v:vector} 15 | {vc:list_vector_inside} 16 | {a:string} 17 | ''' 18 | x = trim(x) 19 | 20 | fa = fml(m, x) 21 | print(fa) 22 | f, a = fa.split(' = ') 23 | assert_equal(f, 'format("(","f,","a,","a,","i,","a,","a,","a,",trim(fytbk_int_to_char(size(vector))),"(g0,:,",achar(34),", ",achar(34),"),","a,","a,","a,",trim(fytbk_int_to_char(size(list_vector_inside))),"(g0,:,",achar(34),", ",achar(34),"),","a,","a",")")') 24 | assert_equal(a, "args(float,' ',char(10),int,' ',char(10),'[',vector,']',' ',char(10),list_vector_inside,char(10),string)") -------------------------------------------------------------------------------- /fython/test/fortran_compiler/a.fy: -------------------------------------------------------------------------------- 1 | import iso_c_binding(*) 2 | print '1' -------------------------------------------------------------------------------- /fython/test/fortran_compiler/gfortran_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | import iso_c_binding(*) 4 | print '1' 5 | """ 6 | 7 | from fython.test import * 8 | 9 | use_gfortran() 10 | 11 | writer(s) 12 | 13 | w = load('.a', force=1, release=1, verbose=0) 14 | 15 | use_ifort() # back to ifort -------------------------------------------------------------------------------- /fython/test/fortran_compiler/ifort_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | import iso_c_binding(*) 4 | print '1' 5 | """ 6 | 7 | from fython.test import * 8 | 9 | use_ifort() 10 | 11 | writer(s) 12 | 13 | w = load('.a', force=1, release=1, verbose=0) 14 | 15 | -------------------------------------------------------------------------------- /fython/test/fortran_compiler/set_compiler_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | import iso_c_binding(*) 4 | print '1' 5 | """ 6 | 7 | from fython.test import * 8 | 9 | set_compiler( 10 | cmd = 'ifort', 11 | prefix = '', 12 | infix = '_mp_', 13 | suffix = '_', 14 | debug = '', 15 | release = '', 16 | link = '', 17 | error_regex = 'error:', 18 | warning_regex = 'warnings:' 19 | ) 20 | 21 | writer(s) 22 | 23 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 24 | 25 | use_ifort() # back to ifort -------------------------------------------------------------------------------- /fython/test/funbol/a.fy: -------------------------------------------------------------------------------- 1 | real x(2) 2 | x[2:] = 1 -------------------------------------------------------------------------------- /fython/test/funbol/funbol_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | real x(2) 4 | x[2:] = 1 5 | """ 6 | 7 | from fython.test import * 8 | 9 | writer(s) 10 | 11 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 12 | # print(open(w.module.url.fortran_path, 'r').read()) 13 | 14 | -------------------------------------------------------------------------------- /fython/test/funbol/uopx_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | real x 4 | x = exp(-1.) 5 | """ 6 | 7 | from fython.test import * 8 | 9 | writer(s) 10 | 11 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 12 | # print(open(w.module.url.fortran_path, 'r').read()) 13 | 14 | -------------------------------------------------------------------------------- /fython/test/fython_module_access/a.fy: -------------------------------------------------------------------------------- 1 | int i = 1 2 | int dimension(2) iv = [1, 2] 3 | 4 | real r = 1 5 | real dimension(2) rv = [1, 2] 6 | 7 | char(3) c = 'abc' 8 | char(3) dimension(2) cv = ['abc', 'def'] -------------------------------------------------------------------------------- /fython/test/fytypes/character_test.py: -------------------------------------------------------------------------------- 1 | from ctypes import * 2 | from fython.fytypes import * 3 | 4 | x = Char(size=3, value='abc') 5 | print(x[:]) 6 | x[:] = 'xyz' 7 | print(x) 8 | 9 | x = Char(size=3, value=['abc','def','hij']) 10 | print(x[:]) 11 | x[:] = 'x' 12 | print(x) 13 | print(x.ref[0]) 14 | print(x.value) 15 | 16 | -------------------------------------------------------------------------------- /fython/test/fytypes/integer_test.py: -------------------------------------------------------------------------------- 1 | from ctypes import * 2 | from fython.fytypes import * 3 | 4 | x = Int(value=1) 5 | print(x[:]) 6 | x[:] = 10 7 | print(x) 8 | 9 | x = Int(value=[1,2,3]) 10 | print(x[:]) 11 | x[:] = 10 12 | print(x) 13 | print(x.ref[0]) 14 | print(x.value) 15 | 16 | -------------------------------------------------------------------------------- /fython/test/fytypes/real_test.py: -------------------------------------------------------------------------------- 1 | from ctypes import * 2 | from fython.fytypes import * 3 | 4 | x = Real(value=1) 5 | print(x[:]) 6 | x[:] = 10 7 | print(x) 8 | 9 | x = Real(value=[1,2,3]) 10 | print(x[:]) 11 | x[:] = 10 12 | print(x) 13 | print(x.ref[0]) 14 | print(x.value) 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /fython/test/hello/hello_test.py: -------------------------------------------------------------------------------- 1 | import fython 2 | 3 | print(fython.hello()) -------------------------------------------------------------------------------- /fython/test/imp.py: -------------------------------------------------------------------------------- 1 | from importlib import import_module 2 | from fython.config import * 3 | 4 | def imp(url): 5 | url = Url( 6 | url = url, 7 | cwd = get_frame_dir(1), 8 | ext = exts.py, 9 | ) 10 | return import_module(url.dotted) -------------------------------------------------------------------------------- /fython/test/importpec_fort/a.f90: -------------------------------------------------------------------------------- 1 | module a 2 | integer :: x_a = 10 3 | end module -------------------------------------------------------------------------------- /fython/test/importpec_fort/b.fy: -------------------------------------------------------------------------------- 1 | import .a(*) 2 | 3 | int x = 1 4 | 5 | print 'in b {:x} {:x_a}' 6 | -------------------------------------------------------------------------------- /fython/test/importpec_fort/c.fy: -------------------------------------------------------------------------------- 1 | import iso_c_binding(*) 2 | -------------------------------------------------------------------------------- /fython/test/importpec_fort/fort_funbol_intrinsic_import_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | import iso_c_binding(c_float, c_int) 4 | 5 | .b.fy 6 | import ifport(signalqq=signal) 7 | 8 | .c.fy 9 | import iso_c_binding(*) 10 | 11 | """ 12 | 13 | from fython.test import * 14 | 15 | writer(s) 16 | 17 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 18 | # print(open(w.module.url.fortran_path, 'r').read()) 19 | 20 | w = load('.b', force=1, release=1, verbose=0, run_main=0) 21 | # print(open(w.module.url.fortran_path, 'r').read()) 22 | 23 | w = load('.c', force=1, release=1, verbose=0, run_main=0) 24 | # print(open(w.module.url.fortran_path, 'r').read()) 25 | 26 | -------------------------------------------------------------------------------- /fython/test/importpec_fort/fort_namespace_import_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.f90 3 | module a 4 | integer :: x_a = 10 5 | end module 6 | 7 | .b.fy 8 | import .a(*) 9 | 10 | int x = 1 11 | 12 | print 'in b {:x} {:x_a}' 13 | 14 | """ 15 | 16 | from fython.test import * 17 | 18 | shell('rm -rf a/ a.* b.*') 19 | 20 | writer(s) 21 | 22 | w = load('.b', force=1, release=1, verbose=0, run_main=0) 23 | # print(open(w.module.url.fortran_path, 'r').read()) -------------------------------------------------------------------------------- /fython/test/importpec_fort/fort_namex_intrinsic_import_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | import iso_c_binding(*) 4 | """ 5 | 6 | from fython.test import * 7 | 8 | writer(s) 9 | 10 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 11 | # print(open(w.module.url.fortran_path, 'r').read()) 12 | 13 | -------------------------------------------------------------------------------- /fython/test/importpec_fort/fort_slice_import_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.f90 3 | module a 4 | integer :: x_a = 10 5 | integer :: y_a = 20 6 | end module 7 | 8 | .b.fy 9 | import .a( 10 | x_a, 11 | y_a = y, 12 | ) 13 | 14 | int x = 1 15 | 16 | print 'in b {:x} {:x_a} {:y}' 17 | 18 | """ 19 | 20 | from fython.test import * 21 | 22 | shell('rm -rf a/ a.* b.* c.*') 23 | 24 | writer(s) 25 | 26 | w = load('.b', force=1, release=1, verbose=0, run_main=0) 27 | # print(open(w.module.url.fortran_path, 'r').read()) 28 | -------------------------------------------------------------------------------- /fython/test/importpec_fort/fort_star_import_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.f90 3 | module a 4 | integer :: x_a = 10 5 | end module 6 | 7 | .b.fy 8 | import .a(*) 9 | 10 | int x = 1 11 | 12 | print 'in b {:x} {:x_a}' 13 | 14 | """ 15 | 16 | from fython.test import * 17 | 18 | shell('rm -rf a/ a.* b.*') 19 | 20 | writer(s) 21 | 22 | w = load('.b', force=1, release=1, verbose=0, run_main=0 ) 23 | # print(open(w.module.url.fortran_path, 'r').read()) 24 | -------------------------------------------------------------------------------- /fython/test/importpec_fy/a.fy: -------------------------------------------------------------------------------- 1 | int x_a = 10 -------------------------------------------------------------------------------- /fython/test/importpec_fy/b.fy: -------------------------------------------------------------------------------- 1 | import .a(*) 2 | 3 | int x = 1 4 | 5 | print 'in b {:x} {:x_a}' 6 | -------------------------------------------------------------------------------- /fython/test/importpec_fy/fy_alias_namespace_import_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | int x = 10 4 | 5 | .b.fy 6 | import .a = c 7 | 8 | int x = 1 9 | 10 | print 'in b {:x} {:c.x}' 11 | 12 | """ 13 | 14 | from fython.test import * 15 | 16 | shell('rm -rf a/ a.* b.*') 17 | 18 | writer(s) 19 | 20 | w = load('.b', force=1, release=1, verbose=0, run_main=0) 21 | # print(open(w.module.url.fortran_path, 'r').read()) 22 | -------------------------------------------------------------------------------- /fython/test/importpec_fy/fy_namex_aliased_namespace_import_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .temp_package.__init__.fy 3 | int x = 10 4 | print 'in a {:x}' 5 | 6 | .b.fy 7 | import temp_package 8 | 9 | int x = 1 10 | 11 | print 'in b {:x} {:temp_package.x}' 12 | 13 | """ 14 | from fython.test import * 15 | 16 | shell('rm -rf a/ a.* b.*') 17 | 18 | writer(s) 19 | 20 | import sys 21 | sys.path.append(get_frame_dir()) 22 | 23 | w = load('.b', force=1, release=1, verbose=0, run_main=0) 24 | print(open(w.module.url.fortran_path, 'r').read()) 25 | 26 | sys.path.pop(0) 27 | -------------------------------------------------------------------------------- /fython/test/importpec_fy/fy_slice_import_1_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | int x_a = 10 4 | int y_a = 20 5 | 6 | .b.fy 7 | import .a( 8 | x_a, 9 | y_a = y, 10 | ) 11 | 12 | int x = 1 13 | 14 | print 'in b {:x} {:x_a} {:y}' 15 | 16 | """ 17 | 18 | from fython.test import * 19 | 20 | shell('rm -rf a/ a.* b.* c.*') 21 | 22 | writer(s) 23 | 24 | w = load('.b', force=1, release=1, verbose=0, run_main=0) 25 | # print(open(w.module.url.fortran_path, 'r').read()) 26 | -------------------------------------------------------------------------------- /fython/test/importpec_fy/fy_slice_import_2_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.a.fy 3 | int x_a = 10 4 | int y_a = 20 5 | 6 | .b.fy 7 | import .a.a( 8 | x_a, 9 | y_a = y, 10 | ) 11 | 12 | int x = 1 13 | 14 | print 'in b {:x} {:x_a} {:y}' 15 | 16 | """ 17 | 18 | from fython.test import * 19 | 20 | shell('rm -rf a/ a.* b.* c.*') 21 | 22 | writer(s) 23 | 24 | w = load('.b', force=1, release=1, verbose=0, run_main=0) 25 | # print(open(w.module.url.fortran_path, 'r').read()) 26 | -------------------------------------------------------------------------------- /fython/test/importpec_fy/fy_star_import_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | int x_a = 10 4 | 5 | .b.fy 6 | import .a(*) 7 | 8 | int x = 1 9 | 10 | print 'in b {:x} {:x_a}' 11 | 12 | """ 13 | 14 | from fython.test import * 15 | 16 | shell('rm -rf a/ a.* b.* c.*') 17 | 18 | writer(s) 19 | 20 | w = load('.b', force=1, release=1, verbose=0, run_main=0) 21 | # print(open(w.module.url.fortran_path, 'r').read()) 22 | -------------------------------------------------------------------------------- /fython/test/importpec_fy/import_throw_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | int x_a = 10 4 | 5 | .b.fy 6 | import: 7 | .aa(*) 8 | 9 | """ 10 | 11 | from fython.test import * 12 | 13 | shell('rm -rf a/ a.* b.* c.*') 14 | 15 | writer(s) 16 | 17 | # w = load('.b', force=1, release=1, verbose=0, run_main=0) 18 | # print(open(w.module.url.fortran_path, 'r').read()) 19 | -------------------------------------------------------------------------------- /fython/test/importpec_fy/temp_package/__init__.fy: -------------------------------------------------------------------------------- 1 | int x = 10 2 | print 'in a {:x}' -------------------------------------------------------------------------------- /fython/test/importpec_py/a.py: -------------------------------------------------------------------------------- 1 | x = 10 -------------------------------------------------------------------------------- /fython/test/importpec_py/b.fy: -------------------------------------------------------------------------------- 1 | import .a = c 2 | 3 | int x = |c.x| 4 | 5 | 6 | print 'in b {:x}' 7 | -------------------------------------------------------------------------------- /fython/test/importpec_py/c/a.py: -------------------------------------------------------------------------------- 1 | x = 10 2 | y = 20 -------------------------------------------------------------------------------- /fython/test/importpec_py/py_namespace_alias_import_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.py 3 | x = 10 4 | 5 | .b.fy 6 | import .a = c 7 | 8 | int x = |c.x| 9 | 10 | 11 | print 'in b {:x}' 12 | 13 | """ 14 | 15 | from fython.test import * 16 | 17 | shell('rm -rf a/ a.* b.*') 18 | 19 | writer(s) 20 | 21 | w = load('.b', force=1, release=1, verbose=0, run_main=0) 22 | # print(open(w.module.url.fortran_path, 'r').read()) 23 | -------------------------------------------------------------------------------- /fython/test/importpec_py/py_namespace_import_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | import numpy 4 | 5 | int x = |numpy.pi| 6 | 7 | 8 | print 'in b {:x}' 9 | 10 | """ 11 | 12 | from fython.test import * 13 | 14 | shell('rm -rf a/ a.*') 15 | 16 | writer(s) 17 | 18 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 19 | # print(open(w.module.url.fortran_path, 'r').read()) 20 | -------------------------------------------------------------------------------- /fython/test/importpec_py/py_slice_import_1_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.py 3 | x = 10 4 | y = 20 5 | 6 | .b.fy 7 | import .a(x, y=z) 8 | 9 | int x = |x| + |z| 10 | 11 | 12 | print 'in b {:x}' 13 | 14 | """ 15 | 16 | from fython.test import * 17 | 18 | shell('rm -rf a/ a.* b.*') 19 | 20 | writer(s) 21 | 22 | w = load('.b', release=1, verbose=0, run_main=0) 23 | # print(open(w.module.url.fortran_path, 'r').read()) 24 | -------------------------------------------------------------------------------- /fython/test/importpec_py/py_slice_import_2_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .c.a.py 3 | x = 10 4 | y = 20 5 | 6 | .b.fy 7 | import .c.a(x, y=z) 8 | 9 | int x = |x| + |z| 10 | 11 | 12 | print 'in b {:x}' 13 | 14 | """ 15 | 16 | from fython.test import * 17 | 18 | shell('rm -rf a c a.* b.*') 19 | 20 | writer(s) 21 | 22 | w = load('.b', force=1, release=1, verbose=0, run_main=0) 23 | # print(open(w.module.url.fortran_path, 'r').read()) 24 | -------------------------------------------------------------------------------- /fython/test/importpec_py/py_star_import_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.py 3 | x = 10 4 | 5 | .b.fy 6 | import .a(*) 7 | 8 | int x = |x| 9 | 10 | 11 | print 'in b {:x}' 12 | 13 | """ 14 | 15 | from fython.test import * 16 | 17 | shell('rm -rf a/ a.* b.*') 18 | 19 | writer(s) 20 | 21 | w = load('.b', force=1, release=1, verbose=0, run_main=0) 22 | # print(open(w.module.url.fortran_path, 'r').read()) 23 | -------------------------------------------------------------------------------- /fython/test/importpec_so/a.f90: -------------------------------------------------------------------------------- 1 | module a 2 | 3 | contains 4 | 5 | function x_a() result(r) bind(c) 6 | real r 7 | r = 10 8 | end function 9 | 10 | end module -------------------------------------------------------------------------------- /fython/test/importpec_so/b.fy: -------------------------------------------------------------------------------- 1 | import .a_so(*) 2 | 3 | interface: 4 | def iso(c) x_a: 5 | real res r 6 | 7 | int x = 1 8 | 9 | print 'in b {:x} {:x_a()}' 10 | -------------------------------------------------------------------------------- /fython/test/importpec_so/so_star_import_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.f90 3 | module a 4 | 5 | contains 6 | 7 | function x_a() result(r) bind(c) 8 | real r 9 | r = 10 10 | end function 11 | 12 | end module 13 | 14 | .b.fy 15 | import .a_so(*) 16 | 17 | interface: 18 | def iso(c) x_a: 19 | real res r 20 | 21 | int x = 1 22 | 23 | print 'in b {:x} {:x_a()}' 24 | 25 | """ 26 | 27 | from fython.test import * 28 | 29 | shell('rm -rf a.* *.so') 30 | 31 | writer(s) 32 | 33 | shell('ifort -shared -fpic a.f90 -o a_so.so') 34 | 35 | w = load('.b', force=1, release=1, verbose=0, run_main=0) 36 | print(open(w.module.url.fortran_path, 'r').read()) 37 | -------------------------------------------------------------------------------- /fython/test/inlineruc/a.fy: -------------------------------------------------------------------------------- 1 | class A: 2 | real x 3 | def g: 4 | print '1' 5 | 6 | class B: 7 | inline A 8 | 9 | B b 10 | b.g() -------------------------------------------------------------------------------- /fython/test/inlineruc/inlineruc_class_1_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | class A: 4 | real x 5 | def g: 6 | print '1' 7 | 8 | def f: 9 | inline A.g 10 | 11 | f() 12 | """ 13 | 14 | from fython.test import * 15 | 16 | shell('rm -rf a/ a.* b.*') 17 | 18 | writer(s) 19 | 20 | w = load('.a', release=1, verbose=0, run_main=0) 21 | # print(open(w.module.url.fortran_path, 'r').read()) 22 | -------------------------------------------------------------------------------- /fython/test/inlineruc/inlineruc_class_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | class A: 4 | real x 5 | def g: 6 | print '1' 7 | 8 | class B: 9 | inline A 10 | 11 | B b 12 | b.g() 13 | """ 14 | 15 | from fython.test import * 16 | 17 | shell('rm -rf a/ a.* b.*') 18 | 19 | writer(s) 20 | 21 | # w = load('.a', release=1, verbose=0, run_main=0) 22 | # print(open(w.module.url.fortran_path, 'r').read()) 23 | 24 | # not supported 25 | # breaks the class resolution algorithm 26 | -------------------------------------------------------------------------------- /fython/test/inlineruc/inlineruc_module_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | def f: 4 | print '1' 5 | 6 | def ff: 7 | print '2' 8 | 9 | .b.fy 10 | import .a = a 11 | 12 | inline: a.f a.ff 13 | """ 14 | 15 | from fython.test import * 16 | 17 | shell('rm -rf a/ a.* b.*') 18 | 19 | writer(s) 20 | 21 | w = load('.b', release=1, verbose=0, run_main=0) 22 | # print(open(w.module.url.fortran_path, 'r').read()) -------------------------------------------------------------------------------- /fython/test/inlineruc/inlineruc_rout_1_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | def f: 4 | print '1' 5 | 6 | .b.fy 7 | import .a(*) 8 | 9 | def g: 10 | inline f 11 | 12 | g() 13 | """ 14 | 15 | from fython.test import * 16 | 17 | shell('rm -rf a/ a.* b.*') 18 | 19 | writer(s) 20 | 21 | w = load('.b', release=1, verbose=0, run_main=0) 22 | # print(open(w.module.url.fortran_path, 'r').read()) 23 | -------------------------------------------------------------------------------- /fython/test/inlineruc/inlineruc_rout_2_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | def f: 4 | print '1' 5 | 6 | .b.fy 7 | import .a = a 8 | 9 | def g: 10 | inline a.f 11 | 12 | g() 13 | """ 14 | 15 | from fython.test import * 16 | 17 | shell('rm -rf a/ a.* b.*') 18 | 19 | writer(s) 20 | 21 | w = load('.b', release=1, verbose=0, run_main=0) 22 | # print(open(w.module.url.fortran_path, 'r').read()) -------------------------------------------------------------------------------- /fython/test/inlineruc/inlineruc_var_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | real x=10 4 | 5 | def f: 6 | inline x 7 | print 'x {:x}' 8 | 9 | f() 10 | """ 11 | 12 | from fython.test import * 13 | 14 | shell('rm -rf a/ a.* b.*') 15 | 16 | writer(s) 17 | 18 | w = load('.a', release=1, verbose=0, run_main=0) 19 | # print(open(w.module.url.fortran_path, 'r').read()) 20 | -------------------------------------------------------------------------------- /fython/test/instruction/a.fy: -------------------------------------------------------------------------------- 1 | real : x y z(10) 2 | int dimension(3) a = [1, 2, 3] 3 | 4 | x += 1 + 3 5 | 6 | x /= sum( 7 | x + 8 | y + 9 | z 10 | ) 11 | -------------------------------------------------------------------------------- /fython/test/instruction/allocruc_deallocruc_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | real dimension(:) allocatable: x y z 4 | integer: 5 | a=1 6 | b=1 7 | c=1 8 | n=1 9 | m=1 10 | 11 | alloc x(n) 12 | dealloc x 13 | 14 | alloc(n) x 15 | dealloc x 16 | 17 | 18 | alloc: x(a) y(b) z(c) 19 | dealloc: x y z 20 | 21 | alloc(n): x y(m) z 22 | dealloc: x y z 23 | 24 | alloc: 25 | x(a) 26 | y(b) 27 | z(c) 28 | 29 | dealloc: 30 | x 31 | y 32 | z 33 | 34 | alloc(n): 35 | x 36 | y(m) 37 | z 38 | 39 | dealloc: 40 | x 41 | y 42 | z 43 | """ 44 | 45 | from fython.test import * 46 | 47 | writer(s) 48 | 49 | w = load('.a', force=1, release=1, verbose=0) 50 | # print(open(w.module.url.fortran_path, 'r').read()) 51 | 52 | -------------------------------------------------------------------------------- /fython/test/instruction/elementruc_keyword_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | int i 4 | pass 5 | for i in [1, 2]: 6 | continue 7 | break 8 | 9 | """ 10 | 11 | from fython.test import * 12 | 13 | writer(s) 14 | 15 | w = load('.a', force=1, release=1, verbose=0) 16 | # print(open(w.module.url.fortran_path, 'r').read()) 17 | -------------------------------------------------------------------------------- /fython/test/instruction/forruc_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | integer: i j x y 4 | 5 | for i in [1, 2]: 6 | x += 1 7 | for j in [1, 2]: 8 | y -= 2 9 | 10 | # print '{:x} {:y}' 11 | """ 12 | 13 | from fython.test import * 14 | 15 | writer(s) 16 | 17 | w = load('.a', force=1, release=1, verbose=0) 18 | # print(open(w.module.url.fortran_path, 'r').read()) 19 | -------------------------------------------------------------------------------- /fython/test/instruction/ifruc_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | integer: x=1, y=3 4 | if x > 4 and y < 5: 5 | if x: 6 | y += 6 7 | 8 | elif x<7: 9 | x = 8 10 | 11 | else: 12 | x=9 13 | """ 14 | 15 | from fython.test import * 16 | 17 | writer(s) 18 | 19 | w = load('.a', force=1, release=1, verbose=0) 20 | # print(open(w.module.url.fortran_path, 'r').read()) 21 | -------------------------------------------------------------------------------- /fython/test/instruction/iruc_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | int dimension(10) target x 4 | int dimension(:) pointer y 5 | y => x[3:5] 6 | """ 7 | from fython.test import * 8 | 9 | writer(s) 10 | 11 | w = load('.a', force=1, release=1, verbose=0) 12 | # print(open(w.module.url.fortran_path, 'r').read()) 13 | -------------------------------------------------------------------------------- /fython/test/instruction/ompruc_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | integer: x r 4 | 5 | omp for reduction(+:r) 6 | 7 | omp: 8 | for, reduction(+:r) 9 | shared, private(x) 10 | """ 11 | 12 | from fython.test import * 13 | 14 | writer(s) 15 | 16 | w = load('.a', force=1, release=1, verbose=0) 17 | # print(open(w.module.url.fortran_path, 'r').read()) 18 | -------------------------------------------------------------------------------- /fython/test/instruction/privateruc_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | integer: x y z a b c d 4 | 5 | private x 6 | private: y z 7 | 8 | private: 9 | a 10 | b 11 | c, d 12 | """ 13 | 14 | from fython.test import * 15 | 16 | writer(s) 17 | 18 | w = load('.a', force=1, release=1, verbose=0) 19 | # print(open(w.module.url.fortran_path, 'r').read()) 20 | -------------------------------------------------------------------------------- /fython/test/instruction/publicruc_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | integer: x y z a b c d 4 | 5 | public x 6 | public: y z 7 | 8 | public: 9 | a 10 | b 11 | c, d 12 | """ 13 | 14 | from fython.test import * 15 | 16 | writer(s) 17 | 18 | w = load('.a', force=1, release=1, verbose=0) 19 | # print(open(w.module.url.fortran_path, 'r').read()) 20 | -------------------------------------------------------------------------------- /fython/test/instruction/stringx_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | char(100) x 4 | char(3) dimension(2) y = ['abc', 'def'] 5 | 6 | x = 'single line' 7 | 8 | x = "single line" 9 | 10 | x = ''' 11 | newline 12 | tab 13 | ''' 14 | 15 | # leading_space_trim 16 | x = ''' 17 | is without 18 | leading space 19 | beginning 20 | end 21 | ''' 22 | 23 | # if_want_begin_end_padding 24 | x = ''' 25 | 26 | is without 27 | leading space 28 | beginning 29 | end 30 | 31 | ''' 32 | # note above the consistent indentation, even for blank lines 33 | 34 | # multiline 35 | x = ''' 36 | a 37 | b 38 | ''' 39 | """ 40 | 41 | from fython.test import * 42 | 43 | writer(s) 44 | 45 | w = load('.a', force=1, release=1, verbose=0) 46 | # print(open(w.module.url.fortran_path, 'r').read()) 47 | -------------------------------------------------------------------------------- /fython/test/instruction/various_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | real : x y z(10) 4 | int dimension(3) a = [1, 2, 3] 5 | 6 | x += 1 + 3 7 | 8 | x /= sum( 9 | x + 10 | y + 11 | z 12 | ) 13 | 14 | """ 15 | 16 | from fython.test import * 17 | 18 | writer(s) 19 | 20 | w = load('.a', force=1, release=1, verbose=0) 21 | # print(open(w.module.url.fortran_path, 'r').read()) 22 | -------------------------------------------------------------------------------- /fython/test/instruction/whereruc_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | int x(10) 4 | 5 | where x >1: 6 | x += 1 7 | elwhere x < 0 : 8 | x-= 1 9 | else: 10 | x **= 8 11 | 12 | """ 13 | 14 | from fython.test import * 15 | 16 | writer(s) 17 | 18 | w = load('.a', force=1, release=1, verbose=0) 19 | # print(open(w.module.url.fortran_path, 'r').read()) 20 | -------------------------------------------------------------------------------- /fython/test/instruction/whileruc_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | int x=10 4 | while x >1: 5 | x += 1 6 | while x>1 and true or false and not False: 7 | x -= 2 8 | """ 9 | 10 | from fython.test import * 11 | 12 | writer(s) 13 | 14 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 15 | # print(open(w.module.url.fortran_path, 'r').read()) 16 | -------------------------------------------------------------------------------- /fython/test/interfacepec/a.fy: -------------------------------------------------------------------------------- 1 | interface: 2 | def f: 3 | real in x 4 | 5 | interface abstract: 6 | def g: 7 | int arg y 8 | real dimension(:) pointer inout z -------------------------------------------------------------------------------- /fython/test/interfacepec/interfacepec_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | interface: 4 | def f: 5 | real in x 6 | 7 | interface abstract: 8 | def g: 9 | int arg y 10 | real dimension(:) pointer inout z 11 | """ 12 | 13 | from fython.test import * 14 | 15 | writer(s) 16 | 17 | w = load('.a', force=1, release=1, verbose=0) 18 | print(open(w.module.url.fortran_path, 'r').read()) 19 | -------------------------------------------------------------------------------- /fython/test/interpolation/a.fy: -------------------------------------------------------------------------------- 1 | int x = |1| + |sum([1, 2, 3])| 2 | 3 | print 'x is {:x}' -------------------------------------------------------------------------------- /fython/test/interpolation/for_loop_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | | 4 | for i in [1, 2]: 5 | write("print '{:d}'", i) 6 | | 7 | """ 8 | 9 | from fython.test import * 10 | 11 | shell('rm -rf a/ a.* b.*') 12 | 13 | writer(s) 14 | 15 | w = load('.a', release=1, verbose=0, run_main=0) 16 | # print(open(w.module.url.fortran_path, 'r').read()) 17 | -------------------------------------------------------------------------------- /fython/test/interpolation/indent_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | | 4 | write(''' 5 | int x = 10 6 | if x > 0: 7 | print 'x is {{:x}}' 8 | else: 9 | print 'not reached' 10 | ''') 11 | | 12 | """ 13 | 14 | from fython.test import * 15 | 16 | shell('rm -rf a/ a.* b.*') 17 | 18 | writer(s) 19 | 20 | w = load('.a', release=1, verbose=0, run_main=0) 21 | # print(open(w.module.url.fortran_path, 'r').read()) 22 | -------------------------------------------------------------------------------- /fython/test/interpolation/inline_2_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | int x = |1| + |sum([1, 2, 3])| 4 | 5 | print 'x is {:x}' 6 | """ 7 | 8 | from fython.test import * 9 | 10 | shell('rm -rf a/ a.* b.*') 11 | 12 | writer(s) 13 | 14 | w = load('.a', release=1, verbose=0, run_main=0) 15 | # print(open(w.module.url.fortran_path, 'r').read()) 16 | -------------------------------------------------------------------------------- /fython/test/interpolation/inline_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | | 4 | "print '1'" 5 | | 6 | """ 7 | 8 | from fython.test import * 9 | 10 | shell('rm -rf a/ a.* b.*') 11 | 12 | writer(s) 13 | 14 | w = load('.a', release=1, verbose=0, run_main=0) 15 | # print(open(w.module.url.fortran_path, 'r').read()) 16 | -------------------------------------------------------------------------------- /fython/test/lex/a.fy: -------------------------------------------------------------------------------- 1 | #comment -------------------------------------------------------------------------------- /fython/test/lex/comment_eof_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | #comment""" 4 | 5 | from fython.test import * 6 | 7 | shell('rm -rf a/ a.* b.*') 8 | 9 | writer(s) 10 | 11 | w = load('.a', force=1, release=1, verbose=0) 12 | print(open(w.module.url.fortran_path, 'r').read()) 13 | -------------------------------------------------------------------------------- /fython/test/lex/eof_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | pass""" 4 | 5 | from fython.test import * 6 | 7 | shell('rm -rf a/ a.* b.*') 8 | 9 | writer(s) 10 | 11 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 12 | # print(open(w.module.url.fortran_path, 'r').read()) 13 | -------------------------------------------------------------------------------- /fython/test/lex/indent start:: -------------------------------------------------------------------------------- 1 | continued 2 | 3 | -------------------------------------------------------------------------------- /fython/test/lex/indent_1_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | indent start: 4 | but 5 | 6 | was stop previously 7 | incorrect indent 8 | """ 9 | 10 | from fython.test import * 11 | 12 | shell('rm -rf a/ a.* b.*') 13 | 14 | writer(s) 15 | 16 | 17 | try: 18 | w = load('.a', force=1, release=1, verbose=0) 19 | 20 | except Exception as e: 21 | print(e) 22 | assert_equal(1, 'indentation without colon' in str(e)) 23 | 24 | -------------------------------------------------------------------------------- /fython/test/lex/indent_2_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | real: # indent start 4 | x # continued 5 | 6 | #was skip previously 7 | """ 8 | 9 | from fython.test import * 10 | shell('rm -rf a/ a.* b.*') 11 | 12 | writer(s) 13 | 14 | w = load('.a', force=1, release=1, verbose=0) 15 | print(open(w.module.url.fortran_path, 'r').read()) 16 | -------------------------------------------------------------------------------- /fython/test/lex/indent_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | int i 4 | real: x(10) y(10, 10) 5 | 6 | if x[1]>1: 7 | x[2:1] = x[2:1] + y[2:1,6] 8 | for i in [1, 2]: 9 | print '2' 10 | print ''' 11 | a 12 | ''' 13 | 14 | print 'a' 15 | 16 | print "b" 17 | 18 | """ 19 | 20 | from fython.test import * 21 | shell('rm -rf a/ a.* b.*') 22 | 23 | writer(s) 24 | 25 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 26 | # print(open(w.module.url.fortran_path, 'r').read()) 27 | -------------------------------------------------------------------------------- /fython/test/lex/linefeed_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | real a 4 | real b 5 | real c 6 | """ 7 | 8 | from fython.test import * 9 | shell('rm -rf a/ a.* b.*') 10 | 11 | writer(s) 12 | 13 | w = load('.a', force=1, release=1, verbose=0) 14 | print(open(w.module.url.fortran_path, 'r').read()) 15 | -------------------------------------------------------------------------------- /fython/test/lex/trailing_tab_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | int cons max_depth = 100 4 | int cons dotted_length = 300 5 | 6 | char(dotted_length) dimension(max_depth) dotted 7 | int dimension(max_depth) lineno 8 | 9 | int ndx # frame index 10 | 11 | private: 12 | max_depth 13 | dotted_length 14 | dotted 15 | lineno 16 | ndx 17 | fytbk_reset 18 | 19 | def fytbk_reset: 20 | ndx = 0 21 | 22 | def fytbk_init_frame: 23 | char(dotted_length) in d 24 | ndx += 1 25 | dotted[ndx] = d 26 | 27 | def fytbk_del_frame: 28 | ndx -= 1 29 | 30 | def fytbk_advance_line: 31 | int in l 32 | lineno[ndx] = l 33 | """ 34 | 35 | from fython.test import * 36 | shell('rm -rf a/ a.* b.*') 37 | 38 | writer(s) 39 | 40 | w = load('.a', force=1, release=1, verbose=0) 41 | print(open(w.module.url.fortran_path, 'r').read()) 42 | -------------------------------------------------------------------------------- /fython/test/lexiruc/a.fy: -------------------------------------------------------------------------------- 1 | def f: 2 | print '1' 3 | 4 | def g = f() 5 | 6 | g() -------------------------------------------------------------------------------- /fython/test/lexiruc/lexiruc_1_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | def f: 4 | print '1' 5 | 6 | def g = f() 7 | 8 | g() 9 | """ 10 | 11 | from fython.test import * 12 | 13 | shell('rm -rf a/ a.* b.*') 14 | 15 | writer(s) 16 | 17 | w = load('.a', release=1, verbose=0, run_main=0) 18 | # print(open(w.module.url.fortran_path, 'r').read()) 19 | -------------------------------------------------------------------------------- /fython/test/lexiruc/lexiruc_2_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | def f: 4 | real in x 5 | print '{:x}' 6 | 7 | def g = f() 8 | 9 | g(9.) 10 | """ 11 | 12 | from fython.test import * 13 | 14 | shell('rm -rf a/ a.* b.*') 15 | 16 | writer(s) 17 | 18 | w = load('.a', release=1, verbose=0, run_main=0) 19 | # print(open(w.module.url.fortran_path, 'r').read()) 20 | -------------------------------------------------------------------------------- /fython/test/lexiruc/lexiruc_3_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | def temp f: 4 | real in x 5 | T r 6 | r = x + offset 7 | print '{:r}' 8 | 9 | def g = f( 10 | offset = 8+2.5, 11 | T = int, 12 | ) 13 | 14 | g(10.) 15 | """ 16 | 17 | from fython.test import * 18 | 19 | shell('rm -rf a/ a.* b.*') 20 | 21 | writer(s) 22 | 23 | w = load('.a', release=1, verbose=0, run_main=0) 24 | # print(open(w.module.url.fortran_path, 'r').read()) 25 | -------------------------------------------------------------------------------- /fython/test/lexiruc/lexiruc_4_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | def temp f: 4 | real in x 5 | T r 6 | r = x 7 | print '{:r}' 8 | 9 | def g = f( 10 | T = int, 11 | ) 12 | 13 | g(10.) 14 | """ 15 | 16 | from fython.test import * 17 | 18 | shell('rm -rf a/ a.* b.*') 19 | 20 | writer(s) 21 | 22 | w = load('.a', release=1, verbose=0, run_main=0) 23 | # print(open(w.module.url.fortran_path, 'r').read()) 24 | -------------------------------------------------------------------------------- /fython/test/lexiruc/lexiruc_classpec_2_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | class temp A: 4 | T x 5 | 6 | def pget f: 7 | s in 8 | U res r 9 | U scale 10 | r = s.x * scale 11 | 12 | def G = A( 13 | T = real, 14 | U = int, 15 | ) 16 | 17 | G g 18 | g.x = 10 19 | print '{:g.f}' 20 | 21 | """ 22 | 23 | from fython.test import * 24 | 25 | shell('rm -rf a/ a.* b.*') 26 | 27 | writer(s) 28 | 29 | w = load('.a', release=1, verbose=0, run_main=0) 30 | print(open(w.module.url.fortran_path, 'r').read()) 31 | -------------------------------------------------------------------------------- /fython/test/lexiruc/lexiruc_classpec_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | class temp A: 4 | T x 5 | 6 | def f: 7 | s in 8 | T in scale 9 | T res r 10 | r = s.x * scale 11 | 12 | def G = A( 13 | T = real, 14 | ) 15 | 16 | G g 17 | g.x = 10 18 | print '{:g.f(2.)}' 19 | 20 | """ 21 | 22 | from fython.test import * 23 | 24 | shell('rm -rf a/ a.* b.*') 25 | 26 | writer(s) 27 | 28 | w = load('.a', release=1, verbose=0, run_main=0) 29 | print(open(w.module.url.fortran_path, 'r').read()) 30 | -------------------------------------------------------------------------------- /fython/test/out: -------------------------------------------------------------------------------- 1 | x\n 2 | x\n 3 | x\n 4 | x\n 5 | x\n 6 | x\n 7 | x\n 8 | x\n 9 | x\n 10 | x\n 11 | x\n 12 | x\n 13 | x\n 14 | x\n 15 | x6 16 | x7 17 | x\n 18 | x6 19 | x7 20 | x\n 21 | x6 22 | x7 23 | x\n 24 | x6 25 | x7 26 | x\n 27 | x6 28 | x7 29 | x\n 30 | x6 31 | x7 32 | x\n 33 | x6 34 | x7 35 | x\n 36 | x6 37 | x7 38 | x\n 39 | x6 40 | x7 41 | x\n 42 | x6 43 | x7 44 | x\n 45 | x6 46 | x7 47 | x\n 48 | x6 49 | x7 50 | x\n 51 | -------------------------------------------------------------------------------- /fython/test/packagebol/a.fy: -------------------------------------------------------------------------------- 1 | class A: 2 | real x 3 | 4 | def lt: 5 | s in 6 | A in other 7 | bool res r 8 | r = s.x < other.x -------------------------------------------------------------------------------- /fython/test/packagebol/b.fy: -------------------------------------------------------------------------------- 1 | import asis type_provider(target_class=T) 2 | 3 | def quicksort: 4 | T dimension(10) in x 5 | int: i r 6 | for i in [1, 10]: 7 | r = x[i].lt( x[i+1] ) 8 | print 'i {:r}' -------------------------------------------------------------------------------- /fython/test/packagebol/c.fy: -------------------------------------------------------------------------------- 1 | import .a(*) 2 | 3 | import .b(*) 4 | || 5 | type_provider = .a 6 | target_class = A 7 | || 8 | 9 | A dimension(10) a 10 | int i 11 | 12 | for i in [1, 10]: 13 | a.x = i 14 | 15 | quicksort(a) -------------------------------------------------------------------------------- /fython/test/packagebol/packagebol_1_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | def f: 4 | T in x 5 | T res r 6 | r = x * 10 7 | 8 | .b.fy 9 | import .a(*) 10 | || T=real || 11 | 12 | print '{:f(10.)}' 13 | """ 14 | 15 | from fython.test import * 16 | 17 | shell('rm -rf a/ a.* b.*') 18 | 19 | writer(s) 20 | 21 | w = load('.b', release=1, verbose=0, run_main=0) 22 | # print(open(w.module.url.fortran_path, 'r').read()) 23 | -------------------------------------------------------------------------------- /fython/test/packagebol/packagebol_2_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | class A: 4 | real x 5 | 6 | def lt: 7 | s in 8 | A in other 9 | bool res r 10 | r = s.x < other.x 11 | 12 | .b.fy 13 | import type_provider(T) 14 | 15 | def quicksort: 16 | T dimension(10) in x 17 | int: i r 18 | for i in [1, 10]: 19 | r = x[i].lt( x[i+1] ) 20 | print 'i {:r}' 21 | 22 | .c.fy 23 | import .a(*) 24 | 25 | import .b(*) 26 | || type_provider=.a, T=A || 27 | 28 | A dimension(10) a 29 | int i 30 | 31 | for i in [1, 10]: 32 | a.x = i 33 | 34 | quicksort(a) 35 | """ 36 | 37 | from fython.test import * 38 | 39 | shell('rm -rf a/ a.* b.* c.*') 40 | 41 | writer(s) 42 | 43 | w = load('.c', force=1, release=1, verbose=0, run_main=0) 44 | # print(open(w.module.url.fortran_path, 'r').read()) 45 | -------------------------------------------------------------------------------- /fython/test/packagebol/packagebol_3_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | class A: 4 | real x 5 | 6 | def lt: 7 | s in 8 | A in other 9 | bool res r 10 | r = s.x < other.x 11 | 12 | .b.fy 13 | import asis type_provider(target_class=T) 14 | 15 | def quicksort: 16 | T dimension(10) in x 17 | int: i r 18 | for i in [1, 10]: 19 | r = x[i].lt( x[i+1] ) 20 | print 'i {:r}' 21 | 22 | .c.fy 23 | import .a(*) 24 | 25 | import .b(*) 26 | || 27 | type_provider = .a 28 | target_class = A 29 | || 30 | 31 | A dimension(10) a 32 | int i 33 | 34 | for i in [1, 10]: 35 | a.x = i 36 | 37 | quicksort(a) 38 | """ 39 | 40 | from fython.test import * 41 | 42 | shell('rm -rf a/ a.* b.* c.*') 43 | 44 | writer(s) 45 | 46 | w = load('.c', force=1, release=1, verbose=0, run_main=0) 47 | # print(open(w.module.url.fortran_path, 'r').read()) 48 | -------------------------------------------------------------------------------- /fython/test/printruc/a.fy: -------------------------------------------------------------------------------- 1 | print './out' 'x\n' -------------------------------------------------------------------------------- /fython/test/printruc/file: -------------------------------------------------------------------------------- 1 | x3 8 2 | x4 8 3 | x5 8 4 | x8 5 | -------------------------------------------------------------------------------- /fython/test/printruc/out: -------------------------------------------------------------------------------- 1 | x\n 2 | x\n 3 | x\n 4 | x\n 5 | x6 6 | x7 7 | -------------------------------------------------------------------------------- /fython/test/printruc/printruc_3_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | int x 4 | print 'in a {:x}' 5 | """ 6 | 7 | from fython.test import * 8 | 9 | writer(s) 10 | 11 | w = load('.a', force=1, release=1, verbose=0) 12 | # print(open(w.module.url.fortran_path, 'r').read()) 13 | -------------------------------------------------------------------------------- /fython/test/printruc/printruc_c_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | int x 4 | print c 'start ' 5 | print c 'in a {:x}' 6 | print ' end' 7 | print 'new' 8 | """ 9 | 10 | from fython.test import * 11 | 12 | writer(s) 13 | 14 | w = load('.a', force=1, release=1, verbose=0) 15 | # print(open(w.module.url.fortran_path, 'r').read()) 16 | -------------------------------------------------------------------------------- /fython/test/printruc/printruc_childcod_2_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | print './out' 'x\n' 4 | """ 5 | 6 | from fython.test import * 7 | 8 | writer(s) 9 | 10 | w = load('.a', force=1, release=1, verbose=0) 11 | # print(open(w.module.url.fortran_path, 'r').read()) 12 | -------------------------------------------------------------------------------- /fython/test/printruc/printruc_childcod_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | character(*) cons string = 'abc' 4 | print ''' 5 | {a:string} 6 | ''' 7 | """ 8 | 9 | from fython.test import * 10 | 11 | writer(s) 12 | 13 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 14 | # print(open(w.module.url.fortran_path, 'r').read()) 15 | -------------------------------------------------------------------------------- /fython/test/printruc/printruc_dotbol_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | int x 4 | print .file 'x {:x}' 5 | """ 6 | 7 | from fython.test import * 8 | 9 | writer(s) 10 | 11 | w = load('.a', force=1, release=1, verbose=0) 12 | # print(open(w.module.url.fortran_path, 'r').read()) 13 | -------------------------------------------------------------------------------- /fython/test/printruc/printruc_json_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | int: 4 | x 5 | 6 | real: 7 | y(2) 8 | 9 | x = 0 10 | y = .5 11 | 12 | print 'jn {jn:x}' 13 | print 'j {j:x}' 14 | print 'jv {jv:y}' 15 | print 'jvn {jvn:y}' 16 | print 'jn_a {jn_a:x}' 17 | print 'j_a {j_a:x}' 18 | print 'jv_a {jv_a:y}' 19 | print 'jvn_a {jvn_a:y}' 20 | """ 21 | 22 | from fython.test import * 23 | 24 | writer(s) 25 | 26 | w = load('.a', force=1, release=1, verbose=0, run_main=1) 27 | # print(open(w.module.url.fortran_path, 'r').read()) 28 | -------------------------------------------------------------------------------- /fython/test/printruc/printruc_multiline_test.py: -------------------------------------------------------------------------------- 1 | s = r''' 2 | .a.fy 3 | print """ 4 | {:1} 5 | {:2} 6 | {:3} 7 | """ 8 | ''' 9 | 10 | from fython.test import * 11 | 12 | writer(s) 13 | 14 | w = load('.a', force=1, release=1, verbose=0, run_main=1) 15 | # print(open(w.module.url.fortran_path, 'r').read()) 16 | -------------------------------------------------------------------------------- /fython/test/printruc/printruc_vc_format_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | int x(10) 4 | print 'x {vc:x} end' 5 | """ 6 | 7 | from fython.test import * 8 | 9 | writer(s) 10 | 11 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 12 | # print(open(w.module.url.fortran_path, 'r').read()) 13 | -------------------------------------------------------------------------------- /fython/test/printruc/string_expr_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | int x 4 | print 'x is {:x}' 5 | """ 6 | 7 | from fython.test import * 8 | 9 | writer(s) 10 | 11 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 12 | # print(open(w.module.url.fortran_path, 'r').read()) 13 | -------------------------------------------------------------------------------- /fython/test/readruc/a.fy: -------------------------------------------------------------------------------- 1 | char(10): variable_name='./file.out' 2 | int: x y z(2, 2) 3 | int: variable_without_dot any_variable 4 | 5 | # dotted 6 | # assumes file extension is '.out' 7 | read .file x 8 | read url(.file) x 9 | 10 | # path 11 | read './file.out' x 12 | read path('./file.out') x 13 | read path(variable_name) x 14 | 15 | open(unit=10, file='./file.out') 16 | variable_without_dot = 10 17 | any_variable = 10 18 | 19 | read 10 x # number 20 | read variable_without_dot x 21 | read unit(any_variable) x 22 | 23 | read .file x 24 | read .file : x y z 25 | read .file: 26 | x 27 | y 28 | z[:, 1] -------------------------------------------------------------------------------- /fython/test/readruc/readruc_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | char(10): variable_name='./file.out' 4 | int: x y z(2, 2) 5 | int: variable_without_dot any_variable 6 | 7 | # dotted 8 | # assumes file extension is '.out' 9 | read .file x 10 | read url(.file) x 11 | 12 | # path 13 | read './file.out' x 14 | read path('./file.out') x 15 | read path(variable_name) x 16 | 17 | open(unit=10, file='./file.out') 18 | variable_without_dot = 10 19 | any_variable = 10 20 | 21 | read 10 x # number 22 | read variable_without_dot x 23 | read unit(any_variable) x 24 | 25 | read .file x 26 | read .file : x y z 27 | read .file: 28 | x 29 | y 30 | z[:, 1] 31 | """ 32 | 33 | from fython.test import * 34 | 35 | writer(s) 36 | 37 | w = load('.a', force=1, release=0, verbose=0, run_main=0) 38 | # print(open(w.module.url.fortran_path, 'r').read()) 39 | -------------------------------------------------------------------------------- /fython/test/restore/a.fy: -------------------------------------------------------------------------------- 1 | int z 2 | -------------------------------------------------------------------------------- /fython/test/restore/b.fy: -------------------------------------------------------------------------------- 1 | import .a(*) 2 | 3 | print '{:z}' 4 | -------------------------------------------------------------------------------- /fython/test/restore/restore_1_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | int z 4 | 5 | """ 6 | 7 | from fython.test import * 8 | 9 | # shell('rm -rf a/ a.* b.*') 10 | # writer(s) 11 | 12 | w = load('.a', release=1, verbose=0, run_main=0) 13 | print(open(w.module.url.fortran_path, 'r').read()) 14 | -------------------------------------------------------------------------------- /fython/test/restore/restore_2_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | int z 4 | 5 | """ 6 | 7 | from fython.test import * 8 | # shell('rm -rf a/ a.* b.*') 9 | # writer(s) 10 | w = load('.a', release=1, verbose=0, run_main=0) 11 | print(open(w.module.url.fortran_path, 'r').read()) 12 | 13 | s = """ 14 | .b.fy 15 | import .a(*) 16 | 17 | print '{:z}' 18 | 19 | """ 20 | 21 | # writer(s) 22 | w = load('.b', release=1, verbose=0, run_main=0) 23 | print(open(w.module.url.fortran_path, 'r').read()) 24 | 25 | -------------------------------------------------------------------------------- /fython/test/routpec/a.fy: -------------------------------------------------------------------------------- 1 | print 'g {:g()}' 2 | 3 | def g: 4 | real res r 5 | r = 3 + f() 6 | 7 | def f: 8 | real res r 9 | r = 10 10 | -------------------------------------------------------------------------------- /fython/test/routpec/automatic_argument_completion_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | real x = 1 4 | real y = 10 5 | 6 | def f: 7 | real in x 8 | real in y 9 | print '{:x} {:y}' 10 | 11 | f(y=1.) 12 | f() 13 | """ 14 | 15 | from fython.test import * 16 | 17 | writer(s) 18 | 19 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 20 | # print(open(w.module.url.fortran_path, 'r').read()) 21 | 22 | -------------------------------------------------------------------------------- /fython/test/routpec/routpec_deferred_name_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | print 'g {:g()}' 4 | 5 | def g: 6 | real res r 7 | r = 3 + f() 8 | 9 | def f: 10 | real res r 11 | r = 10 12 | 13 | """ 14 | 15 | from fython.test import * 16 | 17 | writer(s) 18 | 19 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 20 | # print(open(w.module.url.fortran_path, 'r').read()) 21 | 22 | -------------------------------------------------------------------------------- /fython/test/routpec/routpec_nested_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | def pure f: 4 | real in r 5 | r = 0 6 | def g: 7 | real in x 8 | 9 | """ 10 | 11 | from fython.test import * 12 | 13 | writer(s) 14 | 15 | # w = load('.a', force=1, release=1, verbose=0) 16 | # print(open(w.module.url.fortran_path, 'r').read()) 17 | 18 | # not supported 19 | 20 | 21 | -------------------------------------------------------------------------------- /fython/test/routpec/routpec_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | def pure f: 4 | real in r 5 | 6 | def elemental g: 7 | real in x 8 | real res r 9 | r = x + 3 10 | 11 | def h: 12 | real res r 13 | """ 14 | 15 | from fython.test import * 16 | 17 | writer(s) 18 | 19 | w = load('.a', force=1, release=1, verbose=0) 20 | # print(open(w.module.url.fortran_path, 'r').read()) 21 | 22 | -------------------------------------------------------------------------------- /fython/test/routpec/spec_interpolation_1_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | def f: 4 | int in x 5 | int in y 6 | 7 | def spec(f) g: 8 | print 'x y {:x} {:y}' 9 | 10 | g(1, 2) 11 | 12 | """ 13 | 14 | from fython.test import * 15 | 16 | shell('rm -rf a/ a.* b.*') 17 | 18 | writer(s) 19 | 20 | w = load('.a', release=1, verbose=0, run_main=0) 21 | # print(open(w.module.url.fortran_path, 'r').read()) 22 | -------------------------------------------------------------------------------- /fython/test/routpec/spec_interpolation_2_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | def f: 4 | int in x 5 | int in y 6 | .b.fy 7 | import .a(*) 8 | 9 | def f: 10 | print 'x y {:x} {:y}' 11 | 12 | f(1, 2) 13 | 14 | """ 15 | 16 | from fython.test import * 17 | 18 | shell('rm -rf a/ a.* b.*') 19 | 20 | writer(s) 21 | 22 | w = load('.b', force=1, release=1, verbose=0, run_main=0) 23 | # print(open(w.module.url.fortran_path, 'r').read()) 24 | -------------------------------------------------------------------------------- /fython/test/shell.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | from os import system 3 | 4 | def shell(cmd): 5 | cwd = get_frame_dir(1) 6 | cmd = 'cd {:s} && {:s}'.format(cwd, cmd) 7 | system(cmd) -------------------------------------------------------------------------------- /fython/test/symbol/a.fy: -------------------------------------------------------------------------------- 1 | integer: x(10) y(10, 10, 10) 2 | x[3:5] = 2 3 | 4 | x[2:7] = sum( y[1:2, 2:5, 6:7] ) -------------------------------------------------------------------------------- /fython/test/symbol/semibol_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | integer: a=1, b=1, c=1, n=1, m=1 4 | """ 5 | 6 | from fython.test import * 7 | 8 | writer(s) 9 | 10 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 11 | # print(open(w.module.url.fortran_path, 'r').read()) 12 | 13 | -------------------------------------------------------------------------------- /fython/test/symbol/slicebol_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | integer: x(10) y(10, 10, 10) 4 | x[3:5] = 2 5 | 6 | x[2:7] = sum( y[1:2, 2:5, 6:7] ) 7 | """ 8 | 9 | from fython.test import * 10 | 11 | writer(s) 12 | 13 | w = load('.a', force=1, release=1, verbose=0) 14 | # print(open(w.module.url.fortran_path, 'r').read()) 15 | -------------------------------------------------------------------------------- /fython/test/test_helper: -------------------------------------------------------------------------------- 1 | fython.test.imp 2 | imp('dotted.python.name') 3 | import a python file 4 | usefull for relative import 5 | that needs to be runnable 6 | 7 | fython.test.writer 8 | writer(""" >> first line ignore << 9 | dotted.name.where.to.copy.content.with.extension 10 | file content 11 | indented by at least one level 12 | 13 | useful.py 14 | import cut operator 15 | ~.a.py 16 | replace tilde '~' 17 | with good package root 18 | relative to writer function caller folder 19 | """) -------------------------------------------------------------------------------- /fython/test/traceback/a.fy: -------------------------------------------------------------------------------- 1 | def boom: 2 | real x 3 | subboom(x) 4 | 5 | def subboom: 6 | real inout x 7 | x = 1 / 0 -------------------------------------------------------------------------------- /fython/test/traceback/traceback_2_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | def boom: 4 | real x 5 | subboom(x) 6 | 7 | def subboom: 8 | real inout x 9 | x = 1 / 0 10 | """ 11 | from fython.test import * 12 | 13 | shell('rm -rf a/ a.* b.*') 14 | 15 | writer(s) 16 | 17 | w = load('.a', force=1, release=0, verbose=0, run_main=1) 18 | 19 | w.verbose() 20 | 21 | try: 22 | w.boom() 23 | except Exception as e: 24 | print(e) 25 | assert 'sigfpe' in str(e) 26 | 27 | 28 | -------------------------------------------------------------------------------- /fython/test/traceback/traceback_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | def boom: 4 | real x 5 | subboom(x) 6 | 7 | def subboom: 8 | real inout x 9 | x = 1 / 0 10 | """ 11 | from fython.test import * 12 | 13 | shell('rm -rf a/ a.* b.*') 14 | 15 | writer(s) 16 | 17 | w = load('.a', force=1, release=0, verbose=0, run_main=1) 18 | 19 | try: 20 | w.boom() 21 | except Exception as e: 22 | print(e) 23 | assert 'sigfpe' in str(e) 24 | 25 | 26 | -------------------------------------------------------------------------------- /fython/test/varpec/a.fy: -------------------------------------------------------------------------------- 1 | integer: 2 | a=1 3 | b=1 4 | c=1 5 | n=1 6 | m=1 -------------------------------------------------------------------------------- /fython/test/varpec/varpec_1_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | class employee: 4 | int x 5 | 6 | employee y 7 | """ 8 | 9 | from fython.test import * 10 | 11 | writer(s) 12 | 13 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 14 | # print(open(w.module.url.fortran_path, 'r').read()) 15 | -------------------------------------------------------------------------------- /fython/test/varpec/varpec_2_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | class employee: 4 | int x 5 | 6 | def f: 7 | real in dimension(:) x 8 | employee inout z 9 | real pointer : a b c 10 | int cons n=10 11 | real: 12 | u 13 | v(n) 14 | w 15 | real res r 16 | r += u 17 | """ 18 | 19 | from fython.test import * 20 | 21 | writer(s) 22 | 23 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 24 | # print(open(w.module.url.fortran_path, 'r').read()) 25 | -------------------------------------------------------------------------------- /fython/test/varpec/varpec_3_test.py: -------------------------------------------------------------------------------- 1 | s = """ 2 | .a.fy 3 | integer: 4 | a=1 5 | b=1 6 | c=1 7 | n=1 8 | m=1 9 | """ 10 | 11 | from fython.test import * 12 | 13 | writer(s) 14 | 15 | w = load('.a', force=1, release=1, verbose=0) 16 | 17 | # print(open(w.module.url.fortran_path, 'r').read()) 18 | 19 | -------------------------------------------------------------------------------- /fython/test/varpec/varpec_4_test.py: -------------------------------------------------------------------------------- 1 | s = r""" 2 | .a.fy 3 | char(10): variable_name='./file', string = 'abcdef' 4 | """ 5 | 6 | from fython.test import * 7 | 8 | writer(s) 9 | 10 | w = load('.a', force=1, release=1, verbose=0, run_main=0) 11 | print(open(w.module.url.fortran_path, 'r').read()) 12 | -------------------------------------------------------------------------------- /fython/test/varpec/varpec_test.py: -------------------------------------------------------------------------------- 1 | s=""" 2 | .a.fy 3 | int x = 10 4 | 5 | """ 6 | 7 | from fython.test import * 8 | 9 | writer(s) 10 | 11 | w = load('.a', force=1, release=1, verbose=0) 12 | # print(open(w.module.url.fortran_path, 'r').read()) 13 | -------------------------------------------------------------------------------- /fython/traceback/__init__.py: -------------------------------------------------------------------------------- 1 | from .frame import init_frame, del_frame 2 | from .open_close_line import open_line, close_line 3 | from .stack_trace import stack_trace 4 | -------------------------------------------------------------------------------- /fython/traceback/frame.py: -------------------------------------------------------------------------------- 1 | from ..config import * 2 | 3 | init = "\ncall ('{:s}:{:s}')\n" 4 | delete = '\ncall ()\n' 5 | 6 | def init_frame(module_url, routine_name): 7 | r = init.format(module_url, routine_name) 8 | return r 9 | 10 | def del_frame(): 11 | return delete 12 | -------------------------------------------------------------------------------- /fython/traceback/open_close_line.py: -------------------------------------------------------------------------------- 1 | opener = '\nif ( ({:d}) ) then\n' 2 | closer = '\nend if\n' 3 | 4 | def open_line(lineno): 5 | return opener.format(lineno) 6 | 7 | def close_line(): 8 | return closer 9 | -------------------------------------------------------------------------------- /fython/unit/__init__.py: -------------------------------------------------------------------------------- 1 | from .unit import * -------------------------------------------------------------------------------- /fython/unit/lexem.py: -------------------------------------------------------------------------------- 1 | class Lexem: 2 | def __init__(s, type, lineno, unit): 3 | s.type = type 4 | s.lineno = lineno 5 | s.value = unit 6 | 7 | def __repr__(s): 8 | return 'Lexem({:d}, {:s})'.format(s.lineno, repr(s.value.value)) 9 | 10 | @property 11 | def nfo(s): 12 | r = repr(s) + '\n' 13 | for key, item in s.__dict__.items(): 14 | r += '\t{:s} {:s}\n'.format(key, repr(item)) 15 | 16 | return r 17 | 18 | @property 19 | def rep(s): 20 | return s.__repr__() 21 | 22 | 23 | def clone(s, module): 24 | unit = s.value.clone(module) 25 | x = Lexem(s.type, s.lineno, unit) 26 | return x -------------------------------------------------------------------------------- /fython/yacc/__init__.py: -------------------------------------------------------------------------------- 1 | from .yacc import yacc -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | setup( 4 | packages = find_packages(), 5 | name = 'fython', 6 | description = 'Fython is Fortran with a Python syntax.', 7 | 8 | author = 'Nicolas Essis-Breton', 9 | author_email = 'nicolasessisbreton@gmail.com', 10 | 11 | url = 'https://github.com/nicolasessisbreton/fython', 12 | 13 | license = 'Apache License 2.0', 14 | 15 | platform = 'Linux', 16 | 17 | install_requires = ['ply >=3.7', 'networkx >=1.10', 'tabulate >=0.7.5'], 18 | 19 | version = '1.0', 20 | ) --------------------------------------------------------------------------------