UtilityCode put_code protocol
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Thu, 21 May 2009 19:39:47 +0000 (21:39 +0200)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Thu, 21 May 2009 19:39:47 +0000 (21:39 +0200)
Cython/Compiler/Code.py
Cython/Compiler/DebugFlags.py
Cython/Compiler/ModuleNode.py
Cython/Compiler/Symtab.py

index deb4954864c9a5d4951b7cf58eab0ba6fe968eca..8ac936105d0a9634eb46d7f85951094aab38dce8 100644 (file)
@@ -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):
index d6d52189437a03b80c76443274e963ec4a9fb1cb..f7f5a0eb20590069d9ea74584d94538cf67249d8 100644 (file)
@@ -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
index 2bb0c0a47c3e9329cf87fc54fe9adba1803c5df1..5985af08998270b8fb0f8b50e2b3718a24068493 100644 (file)
@@ -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)
index 87a696d1d5c3519bd9cd7ac400e3aa676c6dfd86..e0f584af0f6e2532ca72b0c99de26fc22a033a3c 100644 (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,