changeset 171:32d6f31a8be2

runtime_sugar: fix of stupid bugs
author Sigurd Meldgaard <stm@daimi.au.dk>
date Mon, 14 Dec 2009 10:26:14 +0100
parents a75448236cc7
children b57cf4ece1f2
files pysmcl/runtime_sugar.py
diffstat 1 files changed, 18 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/pysmcl/runtime_sugar.py	Fri Dec 11 11:34:07 2009 +0100
+++ b/pysmcl/runtime_sugar.py	Mon Dec 14 10:26:14 2009 +0100
@@ -13,21 +13,33 @@
     desuaring if's) and makes an implicit parameter out of the
     runtime, and makes any input, output, get, etc calls use that."""
 
-    def make_runtime_name(loc, ctx=ast.Load):
+    def make_runtime_name(loc, ctx=None):
+        if ctx is None:
+            ctx = ast.Load()
         r = ast.Name(id = "runtime", ctx=ctx)
         ast.copy_location(r, loc)
         return r
 
-    name = make_runtime_name(f, ctx=ast.Param)
+    name = make_runtime_name(f, ctx=ast.Param())
     f.args.args = [name]
 
     class Rewriter(ast.NodeTransformer):
 
+        def visit_Name(self, node):
+            runtime = make_runtime_name(node)
+            if(node.id == "id"):
+                r = ast.ast.Attribute(value=runtime,
+                                  attr="id",
+                                  ctx=ast.Load())
+                ast.copy_location(r, node)
+                return r
+            return node
         def visit_Call(self, node):
             runtime = make_runtime_name(node.func)
             if(self.is_function(node, "output")):
                 r = ast.Attribute(value=runtime,
-                                  identifier="output")
+                                  attr="output",
+                                  ctx=ast.Load())
                 ast.copy_location(r, node.func)
                 node.func = r
                 yield_exp = ast.Yield(value=node)
@@ -35,11 +47,12 @@
                 return yield_exp
             if(self.is_function(node, "input")):
                 r = ast.Attribute(value=runtime,
-                                  identifier="input")
+                                  attr="input",
+                                  ctx=ast.Load())
                 ast.copy_location(r, node.func)
                 node.func = r
             if(self.is_function(node, "get")):
-                node.args.insert(0, name)
+                node.args.insert(0, runtime)
             return node
 
         def visit_Return(self, node):