[cig-commits] r6168 - cs/babel/trunk/spike/Spike/Compiler

leif at geodynamics.org leif at geodynamics.org
Fri Mar 2 19:53:54 PST 2007


Author: leif
Date: 2007-03-02 19:53:53 -0800 (Fri, 02 Mar 2007)
New Revision: 6168

Modified:
   cs/babel/trunk/spike/Spike/Compiler/CmdLine.py
   cs/babel/trunk/spike/Spike/Compiler/ExprNodes.py
   cs/babel/trunk/spike/Spike/Compiler/Main.py
   cs/babel/trunk/spike/Spike/Compiler/Nodes.py
Log:
Resurrected the ability to parse Pyrex code, as some people might
prefer Pythonic syntax.


Modified: cs/babel/trunk/spike/Spike/Compiler/CmdLine.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/CmdLine.py	2007-03-03 00:16:25 UTC (rev 6167)
+++ cs/babel/trunk/spike/Spike/Compiler/CmdLine.py	2007-03-03 03:53:53 UTC (rev 6168)
@@ -64,7 +64,7 @@
                 bad_usage()
         else:
             arg = pop_arg()
-            if arg.endswith(".spk"):
+            if arg.endswith(".spk") or arg.endswith(".pyx"):
                 sources.append(arg)
             elif arg.endswith(".o"):
                 options.objects.append(arg)

Modified: cs/babel/trunk/spike/Spike/Compiler/ExprNodes.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/ExprNodes.py	2007-03-03 00:16:25 UTC (rev 6167)
+++ cs/babel/trunk/spike/Spike/Compiler/ExprNodes.py	2007-03-03 03:53:53 UTC (rev 6168)
@@ -16,6 +16,8 @@
 from DebugFlags import debug_disposal_code, debug_temp_alloc, \
     debug_coercion
 
+implicit_decls = False
+
 class ExprNode(Node):
     #  subexprs     [string]     Class var holding names of subexpr node attrs
     #  type         SpikeType    Type of the result
@@ -706,7 +708,8 @@
         if not self.entry:
             #print "NameNode.analyse_target_declaration:", self.name ###
             #print "...declaring as py_object_type" ###
-            if False:
+            global implicit_decls
+            if implicit_decls:
                 # Death to Pythonic behavior...
                 self.entry = env.declare_var(self.name, py_object_type, self.pos)
             else:
@@ -716,7 +719,8 @@
     def analyse_types(self, env):
         self.entry = env.lookup(self.name)
         if not self.entry:
-            if False:
+            global implicit_decls
+            if implicit_decls:
                 # ...death, death, I say!
                 self.entry = env.declare_builtin(self.name, self.pos)
             else:

Modified: cs/babel/trunk/spike/Spike/Compiler/Main.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/Main.py	2007-03-03 00:16:25 UTC (rev 6167)
+++ cs/babel/trunk/spike/Spike/Compiler/Main.py	2007-03-03 03:53:53 UTC (rev 6168)
@@ -130,7 +130,7 @@
             self.modules[name] = scope
         return scope
 
-    def xxxparse(self, source_filename, type_names, pxd):
+    def parsePyrex(self, source_filename, type_names, pxd):
         # Parse the given source file and return a parse tree.
         f = open(source_filename, "rU")
         s = SpikeScanner(f, source_filename, 
@@ -143,7 +143,7 @@
             raise CompileError
         return tree
 
-    def parse(self, source_filename, type_names, pxd):
+    def parseSpike(self, source_filename, type_names, pxd):
         import parser
         import Nodes
         initial_pos = (source_filename, 1, 0)
@@ -151,6 +151,17 @@
         tree = Nodes.ModuleNode(initial_pos, doc = None, body = body)
         return tree
 
+    def parse(self, source_filename, type_names, pxd):
+        if source_filename.endswith(".spk"):
+            tree = self.parseSpike(source_filename, type_names, pxd)
+        elif source_filename.endswith(".pyx"):
+            import ExprNodes
+            ExprNodes.implicit_decls = True
+            tree = self.parsePyrex(source_filename, type_names, pxd)
+        else:
+            assert false
+        return tree
+
     def extract_module_name(self, path):
         # Get the module name out of a source file pathname.
         _, tail = os.path.split(path)

Modified: cs/babel/trunk/spike/Spike/Compiler/Nodes.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/Nodes.py	2007-03-03 00:16:25 UTC (rev 6167)
+++ cs/babel/trunk/spike/Spike/Compiler/Nodes.py	2007-03-03 03:53:53 UTC (rev 6168)
@@ -2058,6 +2058,7 @@
     #  assmt   AssignmentNode   Function construction/assignment
     
     assmt = None
+    is_generated = False # generated by Spike
     
     def analyse_declarations(self, env):
         for arg in self.args:
@@ -2136,8 +2137,11 @@
     
     def declare_pyfunction(self, env):
         cname = Naming.func_prefix + env.scope_prefix + self.name
-        # Declare as 'cname', since the SpikeFuncDefNode is declared as 'self.name'.
-        self.entry = env.declare_pyfunction(cname, self.pos)
+        if self.is_generated:
+            # Declare as 'cname', since the SpikeFuncDefNode is declared as 'self.name'.
+            self.entry = env.declare_pyfunction(cname, self.pos)
+        else:
+            self.entry = env.declare_pyfunction(self.name, self.pos)            
         self.entry.doc = self.doc
         self.entry.func_cname = cname
         self.entry.doc_cname = \
@@ -2476,7 +2480,8 @@
                          star_arg = None,
                          starstar_arg = None,
                          doc = None,
-                         body = pybody)
+                         body = pybody,
+                         is_generated = True)
         func = cls(pos, name = name, cfunc = cfunc, pyfunc = pyfunc, cname = name)
         return [cfunc, pyfunc, func]
     new_spike_func = classmethod(new_spike_func)



More information about the cig-commits mailing list