changeset 253:8c71a40ed328

runtime_sugar: cleanup
author Sigurd Meldgaard <stm@daimi.au.dk>
date Wed, 06 Jan 2010 12:36:26 +0100
parents c7b4e913b22a
children 67875afe1c90
files pysmcl/runtime_sugar.py
diffstat 1 files changed, 11 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/pysmcl/runtime_sugar.py	Wed Jan 06 12:26:24 2010 +0100
+++ b/pysmcl/runtime_sugar.py	Wed Jan 06 12:36:26 2010 +0100
@@ -9,6 +9,7 @@
 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
@@ -48,34 +49,24 @@
                 yield_exp = ast.Yield(value=node)
                 ast.copy_location(yield_exp, node)
                 return yield_exp
-            # if(self.is_function(node, "input")):
-            #     r = ast.Attribute(value=runtime,
-            #                       attr="input",
-            #                       ctx=ast.Load())
-            #     ast.copy_location(r, node.func)
-            #     node.func = r
-            #     return node
-            if(node.func.id in pysmcl.secret_annotator.annotated_functions
-               or node.func.id == "input"):
+            if(node.func.id == "input"):
+                node.args.insert(0, runtime)
+            if(node.func.id in pysmcl.secret_annotator.annotated_functions):
                 node.args.insert(0, runtime)
-                # num = ast.copy_location(ast.Num(0), node)
-                # slice = ast.copy_location(ast.Index(num), node)
-#                return ast.copy_location(ast.Subscript(value=node,
-#                                                       slice=slice,
-#                                                       ctx=ast.Load()),node)
+                yield_exp = ast.Yield(value=node)
+                ast.copy_location(yield_exp, node)
+                return yield_exp
             return node
 
         def visit_Return(self, node):
             returnValue = ast.copy_location(
                 ast.Name(id="returnValue", ctx=ast.Load()), node)
-#            lst = ast.copy_location(ast.List(elts=[node.value],
-#                                             ctx=ast.Load()), node)
             call = ast.copy_location(ast.Call(func=returnValue,
                                               args=[node.value],
                                               keywords=[],
                                               starargs=None,
                                               kwargs=None), node)
-            
+
             r = ast.copy_location(ast.Expr(value=call), node)
             return r
 
@@ -85,6 +76,8 @@
     Rewriter().visit(f)
     y = ast.copy_location(ast.Yield(value=ast.copy_location(ast.Num(0), f)), f)
     e = ast.copy_location(ast.Expr(value=y), f)
-    if_stm = ast.copy_location(ast.If(test=ast.copy_location(ast.Num(1), f), body=f.body,orelse=[e]), f)
+    if_stm = ast.copy_location(
+        ast.If(test=ast.copy_location(
+                ast.Num(1), f), body=f.body, orelse=[e]), f)
     f.body = [if_stm]
     ast.fix_ast_parents(f)