Commit cd6fb6ad authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Moved cached builtin init to Code.py for consistency

parent d65fd747
...@@ -168,8 +168,13 @@ class GlobalState(object): ...@@ -168,8 +168,13 @@ class GlobalState(object):
self.utildefwriter = rootwriter.new_writer() self.utildefwriter = rootwriter.new_writer()
self.decls_writer = rootwriter.new_writer() self.decls_writer = rootwriter.new_writer()
self.pystring_table = rootwriter.new_writer() self.pystring_table = rootwriter.new_writer()
self.init_cached_builtins_writer = rootwriter.new_writer()
self.initwriter = rootwriter.new_writer() self.initwriter = rootwriter.new_writer()
if Options.cache_builtins:
self.init_cached_builtins_writer.enter_cfunc_scope()
self.init_cached_builtins_writer.putln("static int __Pyx_InitCachedBuiltins(void) {")
self.initwriter.enter_cfunc_scope() self.initwriter.enter_cfunc_scope()
self.initwriter.putln("").putln("static int __Pyx_InitGlobals(void) {") self.initwriter.putln("").putln("static int __Pyx_InitGlobals(void) {")
...@@ -197,19 +202,28 @@ class GlobalState(object): ...@@ -197,19 +202,28 @@ class GlobalState(object):
Naming.stringtab_cname, Naming.stringtab_cname,
self.initwriter.error_goto(self.module_pos))) self.initwriter.error_goto(self.module_pos)))
if Options.cache_builtins:
(self.init_cached_builtins_writer
.putln("return 0;")
.put_label(self.init_cached_builtins_writer.error_label)
.putln("return -1;")
.putln("}")
.exit_cfunc_scope()
)
(self.initwriter (self.initwriter
.putln("return 0;") .putln("return 0;")
.put_label(self.initwriter.error_label) .put_label(self.initwriter.error_label)
.putln("return -1;") .putln("return -1;")
.putln("}") .putln("}")
.exit_cfunc_scope()
) )
self.initwriter.exit_cfunc_scope()
def insert_py_string_table_into(self, code): def insert_initcode_into(self, code):
if self.pystring_table_needed: if self.pystring_table_needed:
code.insert(self.pystring_table) code.insert(self.pystring_table)
if Options.cache_builtins:
def insert_initglobals_into(self, code): code.insert(self.init_cached_builtins_writer)
code.insert(self.initwriter) code.insert(self.initwriter)
def put_pyobject_decl(self, entry): def put_pyobject_decl(self, entry):
...@@ -268,8 +282,16 @@ class GlobalState(object): ...@@ -268,8 +282,16 @@ class GlobalState(object):
self.put_pyobject_decl(entry) self.put_pyobject_decl(entry)
def add_cached_builtin_decl(self, entry): def add_cached_builtin_decl(self, entry):
if self.should_declare(entry.cname, entry): if Options.cache_builtins:
self.put_pyobject_decl(entry) if self.should_declare(entry.cname, entry):
self.put_pyobject_decl(entry)
self.init_cached_builtins_writer.putln('%s = __Pyx_GetName(%s, %s); if (!%s) %s' % (
entry.cname,
Naming.builtins_cname,
entry.interned_cname,
entry.cname,
self.init_cached_builtins_writer.error_goto(entry.pos)))
# #
# File name state # File name state
......
...@@ -256,7 +256,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -256,7 +256,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.generate_cached_builtins_decls(env, code) self.generate_cached_builtins_decls(env, code)
self.body.generate_function_definitions(env, code, options.transforms) self.body.generate_function_definitions(env, code, options.transforms)
code.mark_pos(None) code.mark_pos(None)
self.generate_py_string_table(env, code)
self.generate_typeobj_definitions(env, code) self.generate_typeobj_definitions(env, code)
self.generate_method_table(env, code) self.generate_method_table(env, code)
self.generate_filename_init_prototype(code) self.generate_filename_init_prototype(code)
...@@ -1456,9 +1455,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1456,9 +1455,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln( code.putln(
"};") "};")
def generate_py_string_table(self, env, code):
code.globalstate.insert_py_string_table_into(code)
def generate_filename_init_prototype(self, code): def generate_filename_init_prototype(self, code):
code.putln(""); code.putln("");
code.putln("static void %s(void); /*proto*/" % Naming.fileinit_cname) code.putln("static void %s(void); /*proto*/" % Naming.fileinit_cname)
...@@ -1527,7 +1523,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1527,7 +1523,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
def generate_module_init_func(self, imported_modules, env, code): def generate_module_init_func(self, imported_modules, env, code):
# Insert code stream of __Pyx_InitGlobals # Insert code stream of __Pyx_InitGlobals
code.globalstate.insert_initglobals_into(code) code.globalstate.insert_initcode_into(code)
code.enter_cfunc_scope() code.enter_cfunc_scope()
code.putln("") code.putln("")
...@@ -1556,8 +1552,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1556,8 +1552,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if Options.cache_builtins: if Options.cache_builtins:
code.putln("/*--- Builtin init code ---*/") code.putln("/*--- Builtin init code ---*/")
self.generate_builtin_init_code(env, code) code.putln(code.error_goto_if_neg("__Pyx_InitCachedBuiltins()",
self.pos))
code.putln("%s = 0;" % Naming.skip_dispatch_cname); code.putln("%s = 0;" % Naming.skip_dispatch_cname);
code.putln("/*--- Global init code ---*/") code.putln("/*--- Global init code ---*/")
...@@ -1714,19 +1711,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1714,19 +1711,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
Naming.preimport_cname, Naming.preimport_cname,
code.error_goto(self.pos))); code.error_goto(self.pos)));
def generate_builtin_init_code(self, env, code):
# Lookup and cache builtin objects.
if Options.cache_builtins:
for entry in env.cached_builtins:
#assert entry.interned_cname is not None
code.putln(
'%s = __Pyx_GetName(%s, %s); if (!%s) %s' % (
entry.cname,
Naming.builtins_cname,
entry.interned_cname,
entry.cname,
code.error_goto(entry.pos)))
def generate_global_init_code(self, env, code): def generate_global_init_code(self, env, code):
# Generate code to initialise global PyObject * # Generate code to initialise global PyObject *
# variables to None. # variables to None.
......
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