changeset 165:6cad00158f8a

sugar: openings (output) is now yielded.
author Sigurd Meldgaard <stm@daimi.au.dk>
date Fri, 11 Dec 2009 10:37:46 +0100
parents 0cdf99ec5204
children 9408bce66f9f
files pysmcl/runtime_sugar.py
diffstat 1 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/pysmcl/runtime_sugar.py	Wed Dec 09 12:52:40 2009 +0100
+++ b/pysmcl/runtime_sugar.py	Fri Dec 11 10:37:46 2009 +0100
@@ -1,6 +1,13 @@
 import pysmcl.ast_wrapper as ast
 
 
+"""
+input => runtime.input
+output => yield runtime.output
+get => get(runtime)
+return => returnValue
+"""
+
 def runtime_sugar(f):
     """ *f* is the AST of a function written in pysmcl (after
     desuaring if's) and makes an implicit parameter out of the
@@ -14,7 +21,7 @@
     name = make_runtime_name(f, ctx=ast.Param)
     f.args.args = [name]
 
-    class Rewriter(ast.NodeVisitor):
+    class Rewriter(ast.NodeTransformer):
 
         def visit_Call(self, node):
             runtime = make_runtime_name(node.func)
@@ -23,6 +30,9 @@
                                   identifier="output")
                 ast.copy_location(node.func, r)
                 node.func = r
+                yield_exp = ast.Yield(value=r)
+                ast.copy_location(node, yield_exp)
+                return yield_exp
             if(self.is_function(node, "input")):
                 r = ast.Attribute(value=runtime,
                                   identifier="input")
@@ -30,7 +40,7 @@
                 node.func = r
             if(self.is_function(node, "get")):
                 node.args.insert(0, name)
-
+            return node
         def is_function(self, node, fname):
             return isinstance(node.func, ast.Name) and node.func.id == fname