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-16 13:19:53 (GMT)
committer Marion <marion.zepf@gmail.com>2013-08-16 13:19:53 (GMT)
commit0a6a3deb566df8c7832b6181d03db55039200976 (patch)
treecd58f7098deffe957b017823d37fa2a03725f3c4
parent7d97ef90f223f4f3980f355dc3e9d39b8b8ee7c5 (diff)
special handling for 'hat' and 'stack' blocks when exporting them
-rw-r--r--TurtleArt/taexportpython.py13
-rw-r--r--TurtleArt/taprimitive.py9
2 files changed, 16 insertions, 6 deletions
diff --git a/TurtleArt/taexportpython.py b/TurtleArt/taexportpython.py
index c87757d..88a73a0 100644
--- a/TurtleArt/taexportpython.py
+++ b/TurtleArt/taexportpython.py
@@ -31,7 +31,7 @@ import util.codegen as codegen
from talogo import LogoCode
from taprimitive import (Primitive, PyExportError, value_to_ast)
-from tautils import (debug_output, find_group, find_top_block)
+from tautils import (debug_output, find_group, find_top_block, get_stack_name)
@@ -93,10 +93,11 @@ def save_python(tw):
snippets = [_SETUP_CODE_START]
for block in tops_of_stacks:
- # TODO name of action stack?
- pythoncode = _action_stack_to_python(block, tw.lc)
- snippets.append(pythoncode)
- snippets.append(linesep)
+ stack_name = get_stack_name(block)
+ if stack_name:
+ pythoncode = _action_stack_to_python(block, tw.lc, name=stack_name)
+ snippets.append(pythoncode)
+ snippets.append(linesep)
snippets.append(_SETUP_CODE_END)
return "".join(snippets)
@@ -164,7 +165,7 @@ def _walk_action_stack(top_block, lc):
block=block)
if isinstance(new_ast, (list, tuple)):
ast_list.extend(new_ast)
- else:
+ elif new_ast is not None:
ast_list.append(new_ast)
elif arg_asts:
new_ast = ast.List(elts=arg_asts, ctx=ast.Load)
diff --git a/TurtleArt/taprimitive.py b/TurtleArt/taprimitive.py
index 1fbeac9..6f83294 100644
--- a/TurtleArt/taprimitive.py
+++ b/TurtleArt/taprimitive.py
@@ -365,6 +365,15 @@ class Primitive(object):
id_str = 'BOX[%s]' % (repr(ast_to_value(new_arg_asts[0])))
return ast.Name(id=id_str, 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])
+ 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])
+
# standard operators
elif self.func.__name__ in Primitive.STANDARD_OPERATORS:
op = Primitive.STANDARD_OPERATORS[self.func.__name__]