more compiler cythonization
authorRobert Bradshaw <robertwb@math.washington.edu>
Tue, 11 Nov 2008 13:36:07 +0000 (05:36 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Tue, 11 Nov 2008 13:36:07 +0000 (05:36 -0800)
more balancing needs to be done.

Cython/Compiler/Nodes.py
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/Parsing.py
Cython/Compiler/Scanning.pxd
Cython/Compiler/Scanning.py
Cython/Plex/Scanners.pxd

index 0d1273dbb09d8526aadaed69a0b79075795fdcb8..59f00c941278505de3117fa4d78a58c54a251fa8 100644 (file)
@@ -716,9 +716,11 @@ class CVarDefNode(StatNode):
     #  in_pxd        boolean
     #  api           boolean
     #  need_properties [entry]
+    #  pxd_locals    [CVarDefNode]  (used for functions declared in pxd)
 
     child_attrs = ["base_type", "declarators"]
     need_properties = ()
+    pxd_locals = []
     
     def analyse_declarations(self, env, dest_scope = None):
         if not dest_scope:
@@ -754,6 +756,7 @@ class CVarDefNode(StatNode):
                 entry = dest_scope.declare_cfunction(name, type, declarator.pos,
                     cname = cname, visibility = self.visibility, in_pxd = self.in_pxd,
                     api = self.api)
+                entry.pxd_locals = self.pxd_locals
             else:
                 if self.in_pxd and self.visibility != 'extern':
                     error(self.pos, 
@@ -890,10 +893,12 @@ class FuncDefNode(StatNode, BlockNode):
     #  #filename        string        C name of filename string const
     #  entry           Symtab.Entry
     #  needs_closure   boolean        Whether or not this function has inner functions/classes/yield
+    #  pxd_locals      [CVarDefNode]   locals defined in the pxd
     
     py_func = None
     assmt = None
     needs_closure = False
+    pxd_locals = []
     
     def analyse_default_values(self, env):
         genv = env.global_scope()
@@ -1497,7 +1502,8 @@ class DefNode(FuncDefNode):
                             with_gil = cfunc.type.with_gil,
                             nogil = cfunc.type.nogil,
                             visibility = 'private',
-                            api = False)
+                            api = False,
+                            pxd_locals = cfunc.pxd_locals)
     
     def analyse_declarations(self, env):
         if 'locals' in env.directives:
index 6cb72bf2daa510a2d9acd680d72fd34680b6e1a8..4834501c458338688ca3eebd37101e9672f2a282 100644 (file)
@@ -234,6 +234,22 @@ class PxdPostParse(CythonTransform):
         if (isinstance(node, DefNode) and self.scope_type == 'cclass'
             and node.name in ('__getbuffer__', '__releasebuffer__')):
             ok = True
+            
+        if isinstance(node, CFuncDefNode):
+            ok = True
+            for stat in node.body.stats:
+                if not isinstance(stat, CVarDefNode):
+                    self.context.error("C function definition not allowed here")
+                    ok = False
+                    break
+            node = CVarDefNode(node.pos, 
+                visibility = node.visibility,
+                base_type = node.base_type,
+                declarators = [node.declarator],
+                in_pxd = True,
+                api = node.api,
+                overridable = node.overridable, 
+                pxd_locals = node.body.stats)
 
         if not ok:
             self.context.nonfatal_error(PostParseError(node.pos,
@@ -547,6 +563,8 @@ property NAME:
                     lenv.declare_var(var, type, type_node.pos)
                 else:
                     error(type_node.pos, "Not a type")
+        for stat in node.pxd_locals:
+            stat.analyse_declarations(lenv)
         node.body.analyse_declarations(lenv)
         self.env_stack.append(lenv)
         self.visitchildren(node)
index 45fa1015474e208a60c20198a947e2e9dbe32ff2..960a362a0109410138ac816f85a9a1e77e91a1b8 100644 (file)
@@ -2128,7 +2128,7 @@ def p_c_func_or_var_declaration(s, pos, ctx):
                                 assignable = 1, nonempty = 1)
     declarator.overridable = ctx.overridable
     if s.sy == ':':
-        if ctx.level not in ('module', 'c_class'):
+        if ctx.level not in ('module', 'c_class', 'module_pxd', 'c_class_pxd'):
             s.error("C function definition not allowed here")
         doc, suite = p_suite(s, Ctx(level = 'function'), with_doc = 1)
         result = Nodes.CFuncDefNode(pos,
index 8af93ebf49db7cafe116495fd4e7a114a8681968..10b19277f9b4891b26b3d00975906e184e72e632 100644 (file)
@@ -13,3 +13,14 @@ cdef class PyrexScanner(Scanner):
     cdef public int bracket_nesting_level
     cdef public sy
     cdef public systring
+
+    cdef long current_level(self)
+    cpdef begin(self, state)
+    cpdef next(self)
+    cpdef bint expect(self, what, message = *) except -2
+    
+    cpdef indentation_action(self, text):
+        cdef:
+            long current_level
+            long new_level
+    
index 9a08a2a64c8de36905a79b7f9409b1b85f9f58ed..797ba7b8e09665fc12ac440be9605d09aef431fb 100644 (file)
@@ -415,7 +415,7 @@ class PyrexScanner(Scanner):
                 systring.encoding = self.source_encoding
         self.sy = sy
         self.systring = systring
-        if debug_scanner:
+        if False: # debug_scanner:
             _, line, col = self.position()
             if not self.systring or self.sy == self.systring:
                 t = self.sy
index 081e73db331b3136e41b924904e1ed71156ff98f..1416ce0d44d61348319c630b6e15e610d2b06185 100644 (file)
@@ -1,3 +1,5 @@
+import cython
+
 cdef class Scanner:
     cdef public lexicon
     cdef public stream
@@ -12,12 +14,31 @@ cdef class Scanner:
     cdef public long start_line
     cdef public long start_col
     cdef public text
-    cdef public initial_state
+    cdef public initial_state # int?
     cdef public state_name
     cdef public list queue
     cdef public bint trace
     cdef public cur_char
     cdef public input_state
     
-    cdef public level
-    
\ No newline at end of file
+    cdef public level # int?
+    
+    cpdef next_char(self):
+        cdef:
+            long input_state
+    
+    cpdef run_machine_inlined(self):
+        cdef:
+            long cur_pos
+            long cur_line
+            long cur_line_start
+            long input_state
+            long next_pos
+            long buf_start_pos
+            long buf_len
+            long buf_index
+            bint trace
+            long discard
+    
+    cpdef begin(self, state)
+    cpdef produce(self, value, text = *)