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-09-02 20:29:15 (GMT)
committer Marion <marion.zepf@gmail.com>2013-09-02 20:29:15 (GMT)
commitcc420f0e37c82275bb5d6b46d85aef9cb9fdae91 (patch)
tree5f079442bfc0758f3971865da0e78fefc26df2ea
parentdad6e183fe30339a6bb450ee8e9a02fe534dbb32 (diff)
update Primitives for the 'while' and 'until' blocks
- They are not yet exportable. - They only work with loop conditions that consist of only one block like e.g., 'pen state'.
-rw-r--r--TurtleArt/talogo.py14
-rw-r--r--TurtleArt/taprimitive.py18
-rw-r--r--plugins/turtle_blocks_extras/turtle_blocks_extras.py19
3 files changed, 32 insertions, 19 deletions
diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py
index b677c1b..f2cf4b5 100644
--- a/TurtleArt/talogo.py
+++ b/TurtleArt/talogo.py
@@ -242,13 +242,13 @@ class LogoCode:
for b in blocks:
b.unhighlight()
- # Hidden macro expansions
- for b in blocks:
- if b.name in ['while', 'until']:
- action_blk, new_blocks = self._expand_forever(b, blk, blocks)
- blocks = new_blocks[:]
- if b == blk:
- blk = action_blk
+ # TODO remove Hidden macro expansions
+# for b in blocks:
+# if b.name in ['while', 'until']:
+# action_blk, new_blocks = self._expand_forever(b, blk, blocks)
+# blocks = new_blocks[:]
+# if b == blk:
+# blk = action_blk
# for b in blocks:
# if b.name in ['forever']:
# action_blk, new_blocks = self._expand_forever(b, blk, blocks)
diff --git a/TurtleArt/taprimitive.py b/TurtleArt/taprimitive.py
index 217b0cb..6e23ad0 100644
--- a/TurtleArt/taprimitive.py
+++ b/TurtleArt/taprimitive.py
@@ -191,7 +191,8 @@ class Primitive(object):
except TATypeError as error:
break
else:
- new_slot_list.append(ConstantArg(value))
+ new_slot_list.append(ConstantArg(value,
+ call_arg=slot.call_arg))
else:
new_slot_list.append(slot)
if error is None:
@@ -206,6 +207,7 @@ class Primitive(object):
if isinstance(kwarg_desc, ArgSlot):
value = kwarg_desc.fill(keywords[key],
convert_to_ast=convert_to_ast)
+ # TODO don't we need the ConstantArg constructor here as well?
new_prim.kwarg_descs[key] = value
return new_prim
@@ -522,16 +524,18 @@ class Primitive(object):
yield True
@staticmethod
- def controller_while(boolean):
- """ Loop controller for the 'while' block """
- while boolean:
+ def controller_while(condition):
+ """ Loop controller for the 'while' block
+ condition -- callable that is evaluated every time through the loop """
+ while condition():
yield True
yield False
@staticmethod
- def controller_until(boolean):
- """ Loop controller for the 'until' block """
- while not boolean:
+ def controller_until(condition):
+ """ Loop controller for the 'until' block
+ condition -- callable that is evaluated every time through the loop """
+ while not condition():
yield True
yield False
diff --git a/plugins/turtle_blocks_extras/turtle_blocks_extras.py b/plugins/turtle_blocks_extras/turtle_blocks_extras.py
index ce18907..06a40f4 100644
--- a/plugins/turtle_blocks_extras/turtle_blocks_extras.py
+++ b/plugins/turtle_blocks_extras/turtle_blocks_extras.py
@@ -39,7 +39,7 @@ from TurtleArt.tautils import (round_int, debug_output, get_path,
hat_on_top, listify, data_from_file)
from TurtleArt.tajail import (myfunc, myfunc_import)
from TurtleArt.taprimitive import (ArgSlot, ConstantArg, Primitive)
-from TurtleArt.tatype import TYPE_STRING
+from TurtleArt.tatype import (TYPE_BOOL, TYPE_OBJECT, TYPE_STRING)
def _num_type(x):
@@ -101,10 +101,14 @@ class Turtle_blocks_extras(Plugin):
special_name=_('while'),
help_string=_('do-while-True operator that uses \
boolean operators from Numbers palette'))
- # Primitive is only used for exporting this block, not for running it
self.tw.lc.def_prim('while', 2,
Primitive(self.tw.lc.prim_loop,
- slot_wrappers={0: Primitive(Primitive.controller_while)}),
+ arg_descs=[
+ ArgSlot(TYPE_OBJECT,
+ call_arg=False,
+ wrapper=Primitive(Primitive.controller_while,
+ arg_descs=[ArgSlot(TYPE_BOOL, call_arg=False)])),
+ ArgSlot(TYPE_OBJECT)]),
True)
# internally expanded macro
@@ -116,10 +120,15 @@ boolean operators from Numbers palette'))
special_name=_('until'),
help_string=_('do-until-True operator that uses \
boolean operators from Numbers palette'))
- # Primitive is only used for exporting this block, not for running it
self.tw.lc.def_prim('until', 2,
Primitive(self.tw.lc.prim_loop,
- slot_wrappers={0: Primitive(Primitive.controller_until)}),
+ arg_descs=[
+ ArgSlot(TYPE_OBJECT,
+ call_arg=False,
+ # TODO can we use controller_while in combination with not_?
+ wrapper=Primitive(Primitive.controller_until,
+ arg_descs=[ArgSlot(TYPE_BOOL, call_arg=False)])),
+ ArgSlot(TYPE_OBJECT)]),
True)
primitive_dictionary['clamp'] = self._prim_clamp