diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2020-04-26 19:00:58 +0200 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2020-04-26 19:25:04 +0200 |
commit | bc40c5f4873ad41a63de64c94331c45f0def148d (patch) | |
tree | 8805b638de0d132ef5e86a59b435003997bb971c | |
parent | 58989a4323d785a156efd32fe1341c7183b075a6 (diff) | |
download | cython-bc40c5f4873ad41a63de64c94331c45f0def148d.tar.gz |
Move the module state generation further down to the latest point before the module implementation.
Ideally, most of the code that is uninteresting for users should be out of the way and not reside before the translated user code.
Mark all code section name beginnings in the C code file to make them easier to follow and move around.
-rw-r--r-- | Cython/Compiler/Code.py | 16 | ||||
-rw-r--r-- | Cython/Compiler/ModuleNode.py | 10 |
2 files changed, 14 insertions, 12 deletions
diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index 999c40030..2a26284b1 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -1103,10 +1103,6 @@ class GlobalState(object): 'complex_type_declarations', # as the proper solution is to make a full DAG... 'type_declarations', # More coarse-grained blocks would simply hide 'utility_code_proto', # the ugliness, not fix it - 'module_state', - 'module_state_clear', - 'module_state_traverse', - 'module_state_defines', 'module_declarations', 'typeinfo', 'before_global_var', @@ -1114,7 +1110,11 @@ class GlobalState(object): 'string_decls', 'decls', 'late_includes', - 'all_the_rest', + 'module_state', + 'module_state_clear', + 'module_state_traverse', + 'module_state_defines', # redefines names used in module_state/_clear/_traverse + 'module_code', # user code goes here 'pystring_table', 'cached_builtins', 'cached_constants', @@ -1155,8 +1155,10 @@ class GlobalState(object): def initialize_main_c_code(self): rootwriter = self.rootwriter - for part in self.code_layout: - self.parts[part] = rootwriter.insertion_point() + for i, part in enumerate(self.code_layout): + w = self.parts[part] = rootwriter.insertion_point() + if i > 0: + w.putln("/* #### Code section: %s ### */" % part) if not Options.cache_builtins: del self.parts['cached_builtins'] diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index b67471eb4..1be6e7f27 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -400,16 +400,15 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln("/* Implementation of %s */" % env.qualified_name.as_c_string_literal()) code = globalstate['late_includes'] - code.putln("/* Late includes */") self.generate_includes(env, modules, code, early=False) - code = globalstate['all_the_rest'] + code = globalstate['module_code'] self.generate_cached_builtins_decls(env, code) - self.generate_lambda_definitions(env, code) + # generate normal variable and function definitions + self.generate_lambda_definitions(env, code) self.generate_variable_definitions(env, code) - self.body.generate_function_definitions(env, code) code.mark_pos(None) @@ -417,7 +416,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): self.generate_method_table(env, code) if env.has_import_star: self.generate_import_star(env, code) - self.generate_pymoduledef_struct(env, code) # initialise the macro to reduce the code size of one-time functionality code.putln(UtilityCode.load_as_string("SmallCodeConfig", "ModuleSetupCode.c")[0].strip()) @@ -2609,6 +2607,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): def generate_module_init_func(self, imported_modules, env, code): subfunction = self.mod_init_subfunction(self.scope, code) + self.generate_pymoduledef_struct(env, code) + code.enter_cfunc_scope(self.scope) code.putln("") code.putln(UtilityCode.load_as_string("PyModInitFuncType", "ModuleSetupCode.c")[0]) |