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

UtilityCode put_code protocol

parent 9875327a
......@@ -68,6 +68,18 @@ class UtilityCode(object):
self.specialize_list.append(s)
return s
def put_code(self, output):
if self.requires:
for dependency in self.requires:
output.use_utility_code(dependency)
if self.proto:
output['utility_code_proto'].put(self.proto)
if self.impl:
output['utility_code_def'].put(self.impl)
self.write_init_code(output.initwriter, output.module_pos)
self.write_cleanup_code(output.cleanupwriter, output.module_pos)
class FunctionState(object):
# return_label string function return point label
# error_label string error catch point label
......@@ -691,28 +703,18 @@ class GlobalState(object):
# Utility code state
#
def use_utility_code(self, utility_code, name=None):
def use_utility_code(self, utility_code):
"""
Adds the given utility code to the C file if needed.
codetup should unpack into one prototype code part and one
definition code part, both strings inserted directly in C.
Adds code to the C file. utility_code should
a) implement __eq__/__hash__ for the purpose of knowing whether the same
code has already been included
b) implement put_code, which takes a globalstate instance
If name is provided, it is used as an identifier to avoid inserting
code twice. Otherwise, id(codetup) is used as such an identifier.
See UtilityCode.
"""
if name is None: name = id(utility_code)
if name not in self.utility_codes:
self.utility_codes.add(name)
if utility_code.requires:
for dependency in utility_code.requires:
self.use_utility_code(dependency)
if utility_code.proto:
self.parts['utility_code_proto'].put(utility_code.proto)
if utility_code.impl:
self.parts['utility_code_def'].put(utility_code.impl)
utility_code.write_init_code(self.initwriter, self.module_pos)
utility_code.write_cleanup_code(self.cleanupwriter, self.module_pos)
if utility_code not in self.utility_codes:
self.utility_codes.add(utility_code)
utility_code.put_code(self)
def funccontext_property(name):
......
......@@ -10,7 +10,7 @@ debug_temp_code_comments = 0
debug_trace_code_generation = 0
# Do not replace exceptions with user-friendly error messages
debug_no_exception_intercept = 0
debug_no_exception_intercept = 1
# Print a message each time a new stage in the pipeline is entered
debug_verbose_pipeline = 0
......@@ -285,8 +285,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.generate_declarations_for_modules(env, modules, globalstate)
h_code.write('\n')
for codetup, name in env.utility_code_list:
globalstate.use_utility_code(codetup, name)
for utilcode in env.utility_code_list:
globalstate.use_utility_code(utilcode)
globalstate.finalize_main_c_code()
f = open_new_file(result.c_file)
......
......@@ -527,8 +527,8 @@ class Scope(object):
if entry and entry.is_type:
return entry.type
def use_utility_code(self, new_code, name=None):
self.global_scope().use_utility_code(new_code, name)
def use_utility_code(self, new_code):
self.global_scope().use_utility_code(new_code)
def generate_library_function_declarations(self, code):
# Generate extern decls for C library funcs used.
......@@ -654,7 +654,7 @@ class ModuleScope(Scope):
# method_table_cname string C name of method table
# doc string Module doc string
# doc_cname string C name of module doc string
# utility_code_list [(UtilityCode, string)] Queuing utility codes for forwarding to Code.py
# utility_code_list [UtilityCode] Queuing utility codes for forwarding to Code.py
# python_include_files [string] Standard Python headers to be included
# include_files [string] Other C headers to be included
# string_to_entry {string : Entry} Map string const to entry
......@@ -829,9 +829,9 @@ class ModuleScope(Scope):
if not entry:
self.declare_var(name, py_object_type, pos)
def use_utility_code(self, new_code, name=None):
def use_utility_code(self, new_code):
if new_code is not None:
self.utility_code_list.append((new_code, name))
self.utility_code_list.append(new_code)
def declare_c_class(self, name, pos, defining = 0, implementing = 0,
module_name = None, base_type = None, objstruct_cname = 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