Commit bc40c5f4 authored by Stefan Behnel's avatar Stefan Behnel

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.
parent 58989a43
......@@ -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']
......
......@@ -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])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment