From 922303b177accef0ce06e6ff9b1e91c2ccb0c90b Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Tue, 06 Jan 2009 23:19:37 +0000 Subject: added push and pop (en only) --- diff --git a/NEWS b/NEWS index 7dd9d5b..b6d9298 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +28 + +* added push and pop (en only) + 27 * add named boxes and stacks diff --git a/activity/activity.info b/activity/activity.info index 0118c06..6f5d7d9 100644 --- a/activity/activity.info +++ b/activity/activity.info @@ -1,6 +1,6 @@ [Activity] name = Turtle Art -activity_version = 27 +activity_version = 28 license = MIT service_name = org.laptop.TurtleArtActivity class = TurtleArtActivity.TurtleArtActivity diff --git a/images/en/emptyheap.svg b/images/en/emptyheap.svg new file mode 100644 index 0000000..3ca8e01 --- /dev/null +++ b/images/en/emptyheap.svg @@ -0,0 +1,71 @@ + + + + + + + + + X + + + + [] + + + + + + + + ! + + diff --git a/images/en/myblocks/clearheap.svg b/images/en/myblocks/clearheap.svg new file mode 100644 index 0000000..6c200e4 --- /dev/null +++ b/images/en/myblocks/clearheap.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + empty + + + heap + + diff --git a/images/en/myblocks/myblocksgroup.svg b/images/en/myblocks/myblocksgroup.svg index 3854efe..89c3609 100644 --- a/images/en/myblocks/myblocksgroup.svg +++ b/images/en/myblocks/myblocksgroup.svg @@ -1,26 +1,27 @@ - - - - - - - + - - - - - - + - - - + + + + + + + + + + + + - - - - - - - - - + + X - - X + + - MyBlocks - - MyBlocks + + - - stack1 - - stack1 + + - - stack1 - - stack1 + + - - stack2 - - stack2 + + - - stack2 - - stack2 + + - - stack - - stack + + - - stack - - stack + + - - - - + - - store in - - store in + + - box1 - - box1 + + - - box1 - - box1 + + - - - - + - - store in - - store in + + - box2 - - box2 + + - - box2 - - box2 + + - - store - - store + + - in - - in + + - box - - box + + - - box - - - box + + + - - name - - - + style="font-size:11px">name + + + + + + + + + + push + + + + + + pop + + + + + + show + + + heap + + + + + + empty + + + heap + + + diff --git a/images/en/myblocks/myblocksmask.svg b/images/en/myblocks/myblocksmask.svg index 77b82ba..adee223 100644 --- a/images/en/myblocks/myblocksmask.svg +++ b/images/en/myblocks/myblocksmask.svg @@ -99,4 +99,32 @@ id="path3902" style="fill:#707070;fill-opacity:1;fill-rule:nonzero;stroke:#707070;stroke-width:1;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + + + + + + + + + + + + diff --git a/images/en/myblocks/pop.svg b/images/en/myblocks/pop.svg new file mode 100644 index 0000000..54825af --- /dev/null +++ b/images/en/myblocks/pop.svg @@ -0,0 +1,38 @@ + + + + + + + + + + + + pop + + diff --git a/images/en/myblocks/printheap.svg b/images/en/myblocks/printheap.svg new file mode 100644 index 0000000..e8434ab --- /dev/null +++ b/images/en/myblocks/printheap.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + show + + + heap + + diff --git a/images/en/myblocks/push.svg b/images/en/myblocks/push.svg new file mode 100644 index 0000000..2e0d236 --- /dev/null +++ b/images/en/myblocks/push.svg @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + push + + diff --git a/images/es/emptyheap.svg b/images/es/emptyheap.svg new file mode 100644 index 0000000..3ca8e01 --- /dev/null +++ b/images/es/emptyheap.svg @@ -0,0 +1,71 @@ + + + + + + + + + X + + + + [] + + + + + + + + ! + + diff --git a/images/es/myblocks/clearheap.svg b/images/es/myblocks/clearheap.svg new file mode 100644 index 0000000..6c200e4 --- /dev/null +++ b/images/es/myblocks/clearheap.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + empty + + + heap + + diff --git a/images/es/myblocks/pop.svg b/images/es/myblocks/pop.svg new file mode 100644 index 0000000..54825af --- /dev/null +++ b/images/es/myblocks/pop.svg @@ -0,0 +1,38 @@ + + + + + + + + + + + + pop + + diff --git a/images/es/myblocks/printheap.svg b/images/es/myblocks/printheap.svg new file mode 100644 index 0000000..e8434ab --- /dev/null +++ b/images/es/myblocks/printheap.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + show + + + heap + + diff --git a/images/es/myblocks/push.svg b/images/es/myblocks/push.svg new file mode 100644 index 0000000..2e0d236 --- /dev/null +++ b/images/es/myblocks/push.svg @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + push + + diff --git a/images/fi/emptyheap.svg b/images/fi/emptyheap.svg new file mode 100644 index 0000000..3ca8e01 --- /dev/null +++ b/images/fi/emptyheap.svg @@ -0,0 +1,71 @@ + + + + + + + + + X + + + + [] + + + + + + + + ! + + diff --git a/images/fi/myblocks/clearheap.svg b/images/fi/myblocks/clearheap.svg new file mode 100644 index 0000000..6c200e4 --- /dev/null +++ b/images/fi/myblocks/clearheap.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + empty + + + heap + + diff --git a/images/fi/myblocks/pop.svg b/images/fi/myblocks/pop.svg new file mode 100644 index 0000000..54825af --- /dev/null +++ b/images/fi/myblocks/pop.svg @@ -0,0 +1,38 @@ + + + + + + + + + + + + pop + + diff --git a/images/fi/myblocks/printheap.svg b/images/fi/myblocks/printheap.svg new file mode 100644 index 0000000..e8434ab --- /dev/null +++ b/images/fi/myblocks/printheap.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + show + + + heap + + diff --git a/images/fi/myblocks/push.svg b/images/fi/myblocks/push.svg new file mode 100644 index 0000000..2e0d236 --- /dev/null +++ b/images/fi/myblocks/push.svg @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + push + + diff --git a/images/fr/emptyheap.svg b/images/fr/emptyheap.svg new file mode 100644 index 0000000..3ca8e01 --- /dev/null +++ b/images/fr/emptyheap.svg @@ -0,0 +1,71 @@ + + + + + + + + + X + + + + [] + + + + + + + + ! + + diff --git a/images/fr/myblocks/clearheap.svg b/images/fr/myblocks/clearheap.svg new file mode 100644 index 0000000..6c200e4 --- /dev/null +++ b/images/fr/myblocks/clearheap.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + empty + + + heap + + diff --git a/images/fr/myblocks/pop.svg b/images/fr/myblocks/pop.svg new file mode 100644 index 0000000..54825af --- /dev/null +++ b/images/fr/myblocks/pop.svg @@ -0,0 +1,38 @@ + + + + + + + + + + + + pop + + diff --git a/images/fr/myblocks/printheap.svg b/images/fr/myblocks/printheap.svg new file mode 100644 index 0000000..e8434ab --- /dev/null +++ b/images/fr/myblocks/printheap.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + show + + + heap + + diff --git a/images/fr/myblocks/push.svg b/images/fr/myblocks/push.svg new file mode 100644 index 0000000..2e0d236 --- /dev/null +++ b/images/fr/myblocks/push.svg @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + push + + diff --git a/images/mn/emptyheap.svg b/images/mn/emptyheap.svg new file mode 100644 index 0000000..3ca8e01 --- /dev/null +++ b/images/mn/emptyheap.svg @@ -0,0 +1,71 @@ + + + + + + + + + X + + + + [] + + + + + + + + ! + + diff --git a/images/mn/myblocks/clearheap.svg b/images/mn/myblocks/clearheap.svg new file mode 100644 index 0000000..6c200e4 --- /dev/null +++ b/images/mn/myblocks/clearheap.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + empty + + + heap + + diff --git a/images/mn/myblocks/pop.svg b/images/mn/myblocks/pop.svg new file mode 100644 index 0000000..54825af --- /dev/null +++ b/images/mn/myblocks/pop.svg @@ -0,0 +1,38 @@ + + + + + + + + + + + + pop + + diff --git a/images/mn/myblocks/printheap.svg b/images/mn/myblocks/printheap.svg new file mode 100644 index 0000000..e8434ab --- /dev/null +++ b/images/mn/myblocks/printheap.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + show + + + heap + + diff --git a/images/mn/myblocks/push.svg b/images/mn/myblocks/push.svg new file mode 100644 index 0000000..2e0d236 --- /dev/null +++ b/images/mn/myblocks/push.svg @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + push + + diff --git a/images/pt/emptyheap.svg b/images/pt/emptyheap.svg new file mode 100644 index 0000000..3ca8e01 --- /dev/null +++ b/images/pt/emptyheap.svg @@ -0,0 +1,71 @@ + + + + + + + + + X + + + + [] + + + + + + + + ! + + diff --git a/images/pt/myblocks/clearheap.svg b/images/pt/myblocks/clearheap.svg new file mode 100644 index 0000000..6c200e4 --- /dev/null +++ b/images/pt/myblocks/clearheap.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + empty + + + heap + + diff --git a/images/pt/myblocks/pop.svg b/images/pt/myblocks/pop.svg new file mode 100644 index 0000000..54825af --- /dev/null +++ b/images/pt/myblocks/pop.svg @@ -0,0 +1,38 @@ + + + + + + + + + + + + pop + + diff --git a/images/pt/myblocks/printheap.svg b/images/pt/myblocks/printheap.svg new file mode 100644 index 0000000..e8434ab --- /dev/null +++ b/images/pt/myblocks/printheap.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + show + + + heap + + diff --git a/images/pt/myblocks/push.svg b/images/pt/myblocks/push.svg new file mode 100644 index 0000000..2e0d236 --- /dev/null +++ b/images/pt/myblocks/push.svg @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + push + + diff --git a/images/ru/emptyheap.svg b/images/ru/emptyheap.svg new file mode 100644 index 0000000..3ca8e01 --- /dev/null +++ b/images/ru/emptyheap.svg @@ -0,0 +1,71 @@ + + + + + + + + + X + + + + [] + + + + + + + + ! + + diff --git a/images/ru/myblocks/clearheap.svg b/images/ru/myblocks/clearheap.svg new file mode 100644 index 0000000..6c200e4 --- /dev/null +++ b/images/ru/myblocks/clearheap.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + empty + + + heap + + diff --git a/images/ru/myblocks/pop.svg b/images/ru/myblocks/pop.svg new file mode 100644 index 0000000..54825af --- /dev/null +++ b/images/ru/myblocks/pop.svg @@ -0,0 +1,38 @@ + + + + + + + + + + + + pop + + diff --git a/images/ru/myblocks/printheap.svg b/images/ru/myblocks/printheap.svg new file mode 100644 index 0000000..e8434ab --- /dev/null +++ b/images/ru/myblocks/printheap.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + show + + + heap + + diff --git a/images/ru/myblocks/push.svg b/images/ru/myblocks/push.svg new file mode 100644 index 0000000..2e0d236 --- /dev/null +++ b/images/ru/myblocks/push.svg @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + push + + diff --git a/images/tr/emptyheap.svg b/images/tr/emptyheap.svg new file mode 100644 index 0000000..3ca8e01 --- /dev/null +++ b/images/tr/emptyheap.svg @@ -0,0 +1,71 @@ + + + + + + + + + X + + + + [] + + + + + + + + ! + + diff --git a/images/tr/myblocks/clearheap.svg b/images/tr/myblocks/clearheap.svg new file mode 100644 index 0000000..6c200e4 --- /dev/null +++ b/images/tr/myblocks/clearheap.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + empty + + + heap + + diff --git a/images/tr/myblocks/pop.svg b/images/tr/myblocks/pop.svg new file mode 100644 index 0000000..54825af --- /dev/null +++ b/images/tr/myblocks/pop.svg @@ -0,0 +1,38 @@ + + + + + + + + + + + + pop + + diff --git a/images/tr/myblocks/printheap.svg b/images/tr/myblocks/printheap.svg new file mode 100644 index 0000000..e8434ab --- /dev/null +++ b/images/tr/myblocks/printheap.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + show + + + heap + + diff --git a/images/tr/myblocks/push.svg b/images/tr/myblocks/push.svg new file mode 100644 index 0000000..2e0d236 --- /dev/null +++ b/images/tr/myblocks/push.svg @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + push + + diff --git a/po/TurtleArt.pot b/po/TurtleArt.pot index 0ff3212..3fb1125 100644 --- a/po/TurtleArt.pot +++ b/po/TurtleArt.pot @@ -94,6 +94,14 @@ msgid "pop" msgstr "" #: +msgid "show heap" +msgstr + +#: +msgid "empty heap" +msgstr + +#: msgid "Numbers" msgstr "" diff --git a/taexport.py b/taexport.py index 16dbc1a..0ab5399 100644 --- a/taexport.py +++ b/taexport.py @@ -92,6 +92,7 @@ tasetshade :shade \r" pensize = 0 tastack = 0 arc = 0 + heap = 0 for b in bs: this_stack = "" data = self.walk_stack(tw, b) @@ -124,12 +125,10 @@ tasetshade :shade \r" this_stack += d[2:] this_stack += " " this_stack += myvar - # this_stack += " " namedbox = 0 myvar = "" else: myvar += d - # myvar += " " elif refstack == 1: this_stack += d[2:] this_stack += " " @@ -137,11 +136,7 @@ tasetshade :shade \r" elif refbox == 1: this_stack += ":" this_stack += d[2:] - # this_stack += " " refbox = 0 - # elif d[0:1] == "#s": - # this_stack += d[2:] - # this_stack += " " elif d == "stack": refstack = 1 elif d == "box": @@ -195,6 +190,18 @@ tasetshade :shade \r" elif d == "arc": arc = 1 this_stack += "taarc" + elif d == "pop": + heap = 1 + this_stack += "tapop" + elif d == "push": + heap = 1 + this_stack += "tapush" + elif d == "heap": + heap = 1 + this_stack += "taprintheap" + elif d == "emptyheap": + heap = 1 + this_stack += "taclearheap" else: this_stack += d this_stack += " " @@ -218,11 +225,18 @@ tasetshade :shade \r" code = "to tapensize\routput first round pensize\rend\r" + code if setxy: # swap args and round args code = "to tasetxy :y :x\rpenup\rsetxy :x :y\rpendown\rend\r" + code - if arc: + if arc: # need to redefine this one all together c = (2 * math.pi)/360 code = "to taarc :a :r\rrepeat round :a [right 1 forward (" + str(c) + " * :r)]\rend\r" + code + if heap: # add psuedo push and pop + code = "to tapush :foo\routput fput :foo :taheap\rend\r" + \ + "to tapop\rif emptyp :taheap [stop]\rmake \"tmp first :taheap\r" + \ + "make \"taheap butfirst :taheap\routput :tmp\rend\r" + \ + "to taclearheap\rmake \"taheap []\rend\r" + \ + "to taprintheap \rprint :taheap\rend\r" + \ + "make \"taheap []\r" + code code = "window\r" + code - print code +# print code return code def walk_stack(self, tw, spr): diff --git a/talogo.py b/talogo.py index 38aaf3a..44a3232 100644 --- a/talogo.py +++ b/talogo.py @@ -31,6 +31,7 @@ from UserDict import UserDict class noKeyError(UserDict): __missing__=lambda x,y: 0 + class taLogo: pass from taturtle import * @@ -38,7 +39,6 @@ from taturtle import * procstop = False class symbol: - def __init__(self, name): self.name = name self.nargs = None @@ -358,6 +358,10 @@ def lcNew(tw): defprim(lc,'storeinbox1', 1, lambda lc,x: setbox(lc, 'box1',x)) defprim(lc,'storeinbox2', 1, lambda lc,x: setbox(lc, 'box2',x)) defprim(lc,'storeinbox', 2, lambda lc,x,y: setbox(lc, 'box3'+str(y),x)) + defprim(lc,'push', 1, lambda lc,x: push_heap(lc,x)) + defprim(lc,'pop', 0, lambda lc: pop_heap(lc)) + defprim(lc,'heap', 0, lambda lc: heap_print(lc)) + defprim(lc,'emptyheap', 0, lambda lc: empty_heap(lc)) defprim(lc,'define', 2, prim_define) defprim(lc,'nop', 0, lambda lc: None) @@ -374,8 +378,8 @@ def lcNew(tw): lc.istack = [] lc.stacks = {} -# lc.boxes = {'box1': 0, 'box2': 0} lc.boxes = noKeyError({'box1': 0, 'box2': 0}) + lc.heap = [] lc.iline, lc.cfun, lc.arglist, lc.ufun = None, None, None,None @@ -402,16 +406,20 @@ def ireturn(lc, res=None): def ijmp(lc, fcn, *args): lc.step = fcn(lc,*(args)) +def heap_print(lc): + showlabel(lc,lc.heap) + def status_print(lc,n): showlabel(lc,int(float(n)*10)/10.) def showlabel(lc,l): if l=='#nostack': shp = 'nostack'; l='' elif l=='#noinput': shp = 'noinput'; l='' + elif l=='#emptyheap': shp = 'emptyheap'; l='' else:shp = 'status' setshape(lc.tw.status_spr, lc.tw.status_shapes[shp]) setlabel(lc.tw.status_spr,l) - setlayer(lc.tw.status_spr,710); + setlayer(lc.tw.status_spr,710) def stopsignon(lc): setshape(lc.stopsign, lc.stopsign.onshape) @@ -422,12 +430,22 @@ def stopsignoff(lc): setlayer(lc.tw.turtle.spr,630) def stop_logo(tw): tw.lc.step = just_stop() + def just_stop(): yield False def setbox(lc, name,val): lc.boxes[name]=val + +def push_heap(lc,val): lc.heap.append(val) + +def pop_heap(lc): + try: return lc.heap.pop(-1) + except: raise logoerror ("#emptyheap") + +def empty_heap(lc): lc.heap = [] + def tyo(n): print n -def millis(): return int(clock()*1000) +def millis(): return int(clock()*1000) def sensor_val(lc, y): return_this = 0 @@ -435,5 +453,5 @@ def sensor_val(lc, y): return_this = ag.get_sensor_val(y) if y==3: return_this = ag.get_sensor_val(y) - return return_this + diff --git a/tasetup.py b/tasetup.py index b82dd53..01bbd1c 100644 --- a/tasetup.py +++ b/tasetup.py @@ -103,7 +103,11 @@ selectors = ( ('box2','box2','num'), ('storeinbox','storeinbox','1sarg',100,'foo'), ('box','box','nfuncs','foo'), - ('string','','string','',str,strcheck)))) + ('string','','string','',str,strcheck), + ('push','push','onearg'), + ('pop','pop','num'), + ('printheap','heap','noarg2'), + ('clearheap','emptyheap','noarg2')))) toolbaritems = ( ('stopit',75), @@ -112,6 +116,7 @@ toolbaritems = ( dockdetails = { 'noarg': (('flow',True,37,5),('flow',False,37,44)), + 'noarg2': (('flow',True,37,5),('flow',False,37,59)), 'onearg': (('flow',True,37,5),('num',False,74,21),('flow',False,37,44)), '1arg': (('flow',True,37,5),('num',False,74,29),('flow',False,37,59)), 'twoargs': (('flow',True,37,5),('num',False,74,21),('num',False,74,58),('flow',False,37,81)), @@ -162,6 +167,7 @@ def setup_selectors(tw): tw.status_shapes['status'] = load_image(tw.path, '', 'status') tw.status_shapes['nostack'] = load_image(tw.path, '', 'nostack') tw.status_shapes['noinput'] = load_image(tw.path, '', 'noinput') + tw.status_shapes['emptyheap'] = load_image(tw.path, '', 'emptyheap') # position status shapes at bottom of screen (minus shape height and toolbar height) screenh = gtk.gdk.screen_height() - 38 - 120 tw.status_spr = sprNew(tw,0,screenh,tw.status_shapes['status'],True) -- cgit v0.9.1