Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarion <marion.zepf@gmail.com>2013-08-15 19:28:44 (GMT)
committer Marion <marion.zepf@gmail.com>2013-08-15 19:28:44 (GMT)
commit991b4f4697eeb14f1a0c55fd714863cf4bbf90de (patch)
tree57d2d3fba5c2abde1c616333275cb8a0817b7568
parent5433f0e9ff35f5f3d123e844ea2f0673aa5ff01c (diff)
use utility function for creating Call ASTs instead of ast.Call
-rw-r--r--TurtleArt/taprimitive.py31
1 files changed, 7 insertions, 24 deletions
diff --git a/TurtleArt/taprimitive.py b/TurtleArt/taprimitive.py
index 7c34803..e05460b 100644
--- a/TurtleArt/taprimitive.py
+++ b/TurtleArt/taprimitive.py
@@ -320,11 +320,7 @@ class Primitive(object):
num_repetitions = new_arg_asts[0]
if num_repetitions.func.id == 'controller_repeat':
num_repetitions = num_repetitions.args[0]
- repeat_iter = ast.Call(func=ast.Name(id="range", ctx=ast.Load),
- args=[num_repetitions],
- keywords={},
- starargs=None,
- kwargs=None)
+ repeat_iter = get_call_ast("range", [num_repetitions])
# TODO use new variable name in nested loops
loop_ast = ast.For(target=ast.Name(id="i", ctx=ast.Store),
iter=repeat_iter,
@@ -358,13 +354,13 @@ class Primitive(object):
if_ast = ast.If(test=test, body=body, orelse=orelse)
return if_ast
+ # boxes
elif self == LogoCode.prim_set_box:
id_str = 'BOX[%s]' % (repr(ast_to_value(new_arg_asts[0])))
target_ast = ast.Name(id=id_str, ctx=ast.Store)
value_ast = new_arg_asts[1]
assign_ast = ast.Assign(targets=[target_ast], value=value_ast)
return assign_ast
-
elif self == LogoCode.prim_get_box:
id_str = 'BOX[%s]' % (repr(ast_to_value(new_arg_asts[0])))
return ast.Name(id=id_str, ctx=ast.Load)
@@ -442,11 +438,7 @@ class Primitive(object):
# get the name of the function directly from the function itself
func_name += self.func.__name__
- return ast.Call(func=ast.Name(id=func_name, ctx=ast.Load),
- args=new_arg_asts,
- keywords=new_kwarg_asts,
- starargs=None,
- kwargs=None)
+ return get_call_ast(func_name, new_arg_asts, new_kwarg_asts)
def __eq__(self, other):
""" Two Primitives are equal iff their all their properties are equal.
@@ -731,12 +723,7 @@ class Primitive(object):
elif isinstance(value, Color):
converted = float(value)
if convert_to_ast:
- conversion_ast = ast.Call(func=ast.Name(id='float',
- ctx=ast.Load),
- args=[value_ast],
- keywords={},
- starargs=None,
- kwargs=None)
+ conversion_ast = get_call_ast('float', [value_ast])
else:
return None
@@ -940,12 +927,8 @@ def value_to_ast(value, *args_for_prim, **kwargs_for_prim):
else:
# call to the Color constructor with this object's values,
# e.g., Color('red', 0, 50, 100)
- return ast.Call(func=ast.Name(id='Color', ctx=ast.Load),
- args=[value.name, value.color, value.shade,
- value.gray],
- keywords={},
- starargs=None,
- kwargs=None)
+ return get_call_ast('Color', [value.name, value.color,
+ value.shade, value.gray])
else:
raise ValueError("unknown type of raw value: " + repr(type(value)))
@@ -968,7 +951,7 @@ def ast_to_value(ast_object):
else:
return None
-# TODO replace every call to ast.Call with a call to this function
+
def get_call_ast(func_name, args=[], keywords={}):
return ast.Call(func=ast.Name(id=func_name,
ctx=ast.Load),