diff options
author | Marion <marion.zepf@gmail.com> | 2013-09-05 21:15:59 (GMT) |
---|---|---|
committer | Marion <marion.zepf@gmail.com> | 2013-09-05 21:15:59 (GMT) |
commit | 90dad2ec57b9110b1e2ec6f46539edf41cfe2e99 (patch) | |
tree | 736d578b99ccec331af3be31ca6cb476ddf8cc0e | |
parent | 42d9ecf455ffd63bb2aa82d6442a470ff265c831 (diff) |
simplify and fix export of 'while' and 'until' loops
-rw-r--r-- | TurtleArt/taprimitive.py | 14 | ||||
-rw-r--r-- | TurtleArt/tatype.py | 28 |
2 files changed, 7 insertions, 35 deletions
diff --git a/TurtleArt/taprimitive.py b/TurtleArt/taprimitive.py index 162eaf8..e037db9 100644 --- a/TurtleArt/taprimitive.py +++ b/TurtleArt/taprimitive.py @@ -31,7 +31,7 @@ from taturtle import (Turtle, Turtles) from tatype import (ACTION_AST, BOX_AST, convert, get_call_ast, get_converter, get_type, is_bound_instancemethod, is_instancemethod, is_staticmethod, TATypeError, Type, TypeDisjunction, - TypedLambda, TYPE_COLOR, TYPE_FLOAT, TYPE_OBJECT) + TYPE_COLOR, TYPE_FLOAT, TYPE_OBJECT) from tautils import debug_output from tawindow import (global_objects, TurtleArtWindow) from util import ast_extensions @@ -346,9 +346,9 @@ class Primitive(object): if controller == Primitive.controller_forever: condition_ast = ast.Name(id="True", ctx=ast.Load) elif controller == Primitive.controller_while: - condition_ast = new_arg_asts[0].body.args[0].body + condition_ast = new_arg_asts[0].args[0] elif controller == Primitive.controller_until: - pos_cond_ast = new_arg_asts[0].body.args[0].body + pos_cond_ast = new_arg_asts[0].args[0] condition_ast = ast.UnaryOp(op=ast.Not, operand=pos_cond_ast) else: @@ -867,10 +867,6 @@ class ArgSlot(object): continue if convert_to_ast: called_argument = func_prim.get_ast() - if not (slot.call_arg and call_my_args): - called_argument = TypedLambda( - body=called_argument, - return_type=called_argument.return_type) else: if slot.call_arg and call_my_args: # call and pass on the return value @@ -888,10 +884,6 @@ class ArgSlot(object): " %s to an AST") % (repr(wrapper))) wrapped_argument = wrapper.get_ast( called_argument) - if not (slot.call_arg and call_my_args): - wrapped_argument = TypedLambda( - body=wrapped_argument, - return_type=wrapped_argument.return_type) else: if slot.call_arg and call_my_args: wrapped_argument = wrapper(called_argument) diff --git a/TurtleArt/tatype.py b/TurtleArt/tatype.py index add26e3..cf75e44 100644 --- a/TurtleArt/tatype.py +++ b/TurtleArt/tatype.py @@ -49,11 +49,8 @@ class Type(object): class TypeDisjunction(tuple,Type): """ Disjunction of two or more Types (from the type hierarchy) """ - def __init__(self, iterable): self = tuple(iterable) - - def __str__(self): s = ["("] for disj in self: @@ -129,6 +126,9 @@ def get_type(x): return (TYPE_INT, True) elif x.func.id in ('repr', 'str', 'unicode'): return (TYPE_STRING, True) + # unary operands never change the type of their argument + elif isinstance(x, ast.UnaryOp): + return get_type(x.operand) return (TYPE_OBJECT, isinstance(x, ast.AST)) @@ -337,27 +337,7 @@ class TypedCall(ast.Call): @property def return_type(self): if self._return_type is None: - return get_type(self.func) - else: - return self._return_type - - -class TypedLambda(ast.Lambda): - """ Like a Lambda AST, but with a return type """ - - def __init__(self, body=None, args=None, return_type=None): - - if args is None: - args = ast.arguments(args=[], vararg=None, kwarg=None, defaults=[]) - - ast.Lambda.__init__(self, body=body, args=args) - - self._return_type = return_type - - @property - def return_type(self): - if self._return_type is None: - return get_type(self.func) + return get_type(self.func)[0] else: return self._return_type |