Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorMarion <marion.zepf@gmail.com>2013-09-10 22:04:43 (GMT)
committer Marion <marion.zepf@gmail.com>2013-09-10 22:04:43 (GMT)
commit27c87bbc282dcc72fcc137684831551556eb5e24 (patch)
tree584a85d38010d08c531dc71a98acbf92d5446c0e /plugins
parent3d3238126b293f2354b97d7d331fc502b70f198e (diff)
add Primitives for the 'push', 'pop', and 'is empty heap?' blocks
Diffstat (limited to 'plugins')
-rw-r--r--plugins/turtle_blocks_extras/turtle_blocks_extras.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/plugins/turtle_blocks_extras/turtle_blocks_extras.py b/plugins/turtle_blocks_extras/turtle_blocks_extras.py
index c75cbbd..04f83ff 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_BOOL, TYPE_CHAR, TYPE_INT, TYPE_NUMBER,
+from TurtleArt.tatype import (TYPE_BOOL, TYPE_BOX, TYPE_CHAR, TYPE_INT,
TYPE_OBJECT, TYPE_STRING)
@@ -475,7 +475,8 @@ program started'))
help_string=_('pushes value onto FILO (first-in \
last-out heap)'))
self.tw.lc.def_prim('push', 1,
- lambda self, x: primitive_dictionary['push'](x))
+ Primitive(self.tw.lc.heap.append,
+ arg_descs=[ArgSlot(TYPE_OBJECT)]))
define_logo_function('tapush', 'to tapush :foo\nmake "taheap fput \
:foo :taheap\nend\nmake "taheap []\n')
@@ -516,7 +517,7 @@ end\n')
help_string=_('pops value off FILO (first-in \
last-out heap)'))
self.tw.lc.def_prim('pop', 0,
- lambda self: primitive_dictionary['pop']())
+ Primitive(self.tw.lc.heap.pop, return_type=TYPE_BOX))
define_logo_function('tapop', 'to tapop\nif emptyp :taheap [stop]\n\
make "tmp first :taheap\nmake "taheap butfirst :taheap\noutput :tmp\nend\n')
@@ -539,8 +540,11 @@ make "tmp first :taheap\nmake "taheap butfirst :taheap\noutput :tmp\nend\n')
value_block=True,
help_string=_('returns True if heap is empty'))
self.tw.lc.def_prim('isheapempty2', 0,
- lambda self:
- primitive_dictionary['isheapempty2']())
+ # Python automatically converts the heap to a boolean in contexts
+ # where a boolean is needed
+ Primitive(Primitive.not_, return_type=TYPE_BOOL,
+ arg_descs=[ConstantArg(
+ Primitive(self.tw.lc.get_heap, return_type=TYPE_BOOL))]))
primitive_dictionary['print'] = self._prim_print
palette.add_block('comment',