Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TurtleArt/taprimitive.py
diff options
context:
space:
mode:
Diffstat (limited to 'TurtleArt/taprimitive.py')
-rw-r--r--TurtleArt/taprimitive.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/TurtleArt/taprimitive.py b/TurtleArt/taprimitive.py
index cf15ca5..e0db4fd 100644
--- a/TurtleArt/taprimitive.py
+++ b/TurtleArt/taprimitive.py
@@ -28,8 +28,8 @@ from tacanvas import TurtleGraphics
from taconstants import (Color, CONSTANTS)
from talogo import (LogoCode, logoerror)
from taturtle import (Turtle, Turtles)
-from tatype import (convert, get_call_ast, get_converter, get_type,
- is_bound_instancemethod, is_instancemethod,
+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,
TYPE_FLOAT, TYPE_OBJECT)
from tautils import debug_output
@@ -352,20 +352,21 @@ class Primitive(object):
# 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
+ target_ast = ast.Subscript(value=BOX_AST,
+ slice=ast.Index(value=new_arg_asts[0]),
+ ctx=ast.Store)
+ return ast.Assign(targets=[target_ast], value=new_arg_asts[1])
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)
+ return ast.Subscript(value=BOX_AST,
+ slice=ast.Index(value=new_arg_asts[0]),
+ ctx=ast.Load)
# action stacks
elif self == LogoCode.prim_define_stack:
return
elif self == LogoCode.prim_invoke_stack:
stack_name = ast_to_value(new_arg_asts[0])
+ # TODO use ast.Subscript
stack_func_name = 'ACTION[%s]' % (repr(stack_name))
stack_func = ast.Name(id=stack_func_name, ctx=ast.Load)
return get_call_ast('logo.icall', [stack_func])
@@ -1004,8 +1005,8 @@ class ArgSlot(object):
# 3. check the type and convert the argument if necessary
try:
- converted_argument = convert(wrapped_argument, new_type,
- converter=converter)
+ converted_argument = convert(wrapped_argument,
+ new_type, old_type=old_type, converter=converter)
except TATypeError as error:
# on failure, try next wrapper/ slot/ func
bad_value = wrapped_argument
@@ -1115,7 +1116,9 @@ def ast_to_value(ast_object):
""" Retrieve the value out of a value AST. Supported AST types:
Num, Str, Name, List, Tuple, Set
If no value can be extracted, return None. """
- if isinstance(ast_object, ast.Num):
+ if not isinstance(ast_object, ast.AST):
+ return ast_object
+ elif isinstance(ast_object, ast.Num):
return ast_object.n
elif isinstance(ast_object, ast.Str):
return ast_object.s