Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TurtleArt/taexportpython.py
diff options
context:
space:
mode:
authorMarion <marion.zepf@gmail.com>2013-08-02 13:35:38 (GMT)
committer Marion <marion.zepf@gmail.com>2013-08-02 13:35:38 (GMT)
commit79670ede9da310ab637cb1323e17bc5bf9de5eaf (patch)
treeb3ff7c4daa52362146adf0a3ef7c512973e48040 /TurtleArt/taexportpython.py
parentf2c774d660adc85de5ea95397188d4bb14f371ef (diff)
make finding tops of block stacks more efficient in taexportpython
Diffstat (limited to 'TurtleArt/taexportpython.py')
-rw-r--r--TurtleArt/taexportpython.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/TurtleArt/taexportpython.py b/TurtleArt/taexportpython.py
index 62065ce..809679d 100644
--- a/TurtleArt/taexportpython.py
+++ b/TurtleArt/taexportpython.py
@@ -30,7 +30,7 @@ import util.codegen as codegen
from talogo import LogoCode
from taprimitive import (Primitive, PyExportError)
-from tautils import (debug_output, find_top_block)
+from tautils import (debug_output, find_group, find_top_block)
@@ -77,14 +77,19 @@ PAT_IDENTIFIER_ILLEGAL_CHAR = re.compile("[^A-Za-z0-9_]")
def save_python(tw):
""" Find all the action stacks and turn each into python code """
- stacks_of_blocks = tw.just_blocks()
+ all_blocks = tw.just_blocks()
+ blocks_covered = set()
+ tops_of_stacks = []
+ for block in all_blocks:
+ if block not in blocks_covered:
+ top = find_top_block(block)
+ tops_of_stacks.append(top)
+ block_stack = find_group(top)
+ blocks_covered.update(set(block_stack))
+
snippets = [_SETUP_CODE_START]
- for block in stacks_of_blocks:
+ for block in tops_of_stacks:
# TODO name of action stack?
- # TODO there must be a more efficient way than finding the top from each block
- top = find_top_block(block)
- if block != top:
- continue
pythoncode = _action_stack_to_python(block, tw.lc)
snippets.append(pythoncode)
snippets.append(linesep)