changeset 169:196ecd8eeea4

runtime_sugar: return statements are rewritten to returnValue In order to work with inlineCallbacks from twisted.
author Sigurd Meldgaard <stm@daimi.au.dk>
date Fri, 11 Dec 2009 11:31:16 +0100
parents 31e6933cecec
children a75448236cc7
files pysmcl/runtime_sugar.py
diffstat 1 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/pysmcl/runtime_sugar.py	Fri Dec 11 10:47:03 2009 +0100
+++ b/pysmcl/runtime_sugar.py	Fri Dec 11 11:31:16 2009 +0100
@@ -15,7 +15,7 @@
 
     def make_runtime_name(loc, ctx=ast.Load):
         r = ast.Name(id = "runtime", ctx=ctx)
-        ast.copy_location(loc, r)
+        ast.copy_location(r, loc)
         return r
 
     name = make_runtime_name(f, ctx=ast.Param)
@@ -28,19 +28,30 @@
             if(self.is_function(node, "output")):
                 r = ast.Attribute(value=runtime,
                                   identifier="output")
-                ast.copy_location(node.func, r)
+                ast.copy_location(r, node.func)
                 node.func = r
                 yield_exp = ast.Yield(value=node)
-                ast.copy_location(node, yield_exp)
+                ast.copy_location(yield_exp, node)
                 return yield_exp
             if(self.is_function(node, "input")):
                 r = ast.Attribute(value=runtime,
                                   identifier="input")
-                ast.copy_location(node.func, r)
+                ast.copy_location(r, node.func)
                 node.func = r
             if(self.is_function(node, "get")):
                 node.args.insert(0, name)
             return node
+
+        def visit_Return(self, node):
+            returnValue = ast.Name(id="returnValue", ctx=ast.Load)
+            e = ast.Call(func=ast.copy_location(returnValue, node),
+                         args=[node.value],
+                         keywords=[],
+                         starargs=[],
+                         kwargs=[])
+            r = ast.Expr(value=ast.copy_location(e, node))
+            return ast.copy_location(r, node)
+
         def is_function(self, node, fname):
             return isinstance(node.func, ast.Name) and node.func.id == fname