git @ Cat's Eye Technologies Wanda / f146551
Implement `sink` as desired. Chris Pressey 3 years ago
2 changed file(s) with 23 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
361361 we might as well go further and imagine it's a body of water.
362362
363363 To store a value on the left end of the string, what we'll do is
364 "tie a weight" to it and let it "sink" to the bottom. When we need it
365 again, we'll "fish it out".
364 "tie a weight" to it and let it "sink" to the bottom.
365
366 We should make "the bottom" explicit, as well. It will be the `)` symbol.
366367
367368 It might be illustrative to show the trace of this.
368369
369370 -> Tests for functionality "Trace Wanda program"
370371
371 1 2 3 4 5 $ 99 sink
372 ===> 1 2 3 4 $ 99 sink 5
373 ===> 1 2 3 $ 99 sink 4 5
374 ===> 1 2 $ 99 sink 3 4 5
375 ===> 1 $ 99 sink 2 3 4 5
376 ===> $ 99 sink 1 2 3 4 5
377 ===> 99 $ sink 1 2 3 4 5
378 ===> 99 $ sink 1 2 3 4 5
379
380 # ===> 1 2 3 4 5 $ 99 sink
381 # ===> 1 2 3 4 $ 99 sinking 5
382 # ===> 1 2 3 $ 99 sinking 4 5
383 # ===> 1 2 $ 99 sinking 3 4 5
384 # ===> 1 $ 99 sinking 2 3 4 5
385 # ===> $ 99 sinking 1 2 3 4 5
386 # ===> 99 $ bubble 1 2 3 4 5
387 # ===> 99 1 $ bubble 2 3 4 5
388 # ===> 99 1 2 $ bubble 3 4 5
389 # ===> 99 1 2 3 $ bubble 4 5
390 # ===> 99 1 2 3 4 $ bubble 5
391 # ===> 99 1 2 3 4 5 $ bubble
392 # ===> 99 1 2 3 4 5 $
372 ) 1 2 3 4 5 $ 99 sink
373 ===> ) 1 2 3 4 $ 99 sink 5
374 ===> ) 1 2 3 $ 99 sink 4 5
375 ===> ) 1 2 $ 99 sink 3 4 5
376 ===> ) 1 $ 99 sink 2 3 4 5
377 ===> ) $ 99 sink 1 2 3 4 5
378 ===> ) $ 99 1 2 3 4 5
379 ===> ) 99 $ 1 2 3 4 5
380 ===> ) 99 1 $ 2 3 4 5
381 ===> ) 99 1 2 $ 3 4 5
382 ===> ) 99 1 2 3 $ 4 5
383 ===> ) 99 1 2 3 4 $ 5
384 ===> ) 99 1 2 3 4 5 $
385 ===> ) 99 1 2 3 4 5 $
386
387 Note that after the value has "sunk", the `$` will "bubble up" all
388 by itself, assuming the values on the stack are integers.
393389
394390 History
395391 -------
7878 if r0 and r1 == "$" and r2 == "dup":
7979 return dict(start=i, stop=i+2, pattern=[r0, "$", "dup"], replacement=[r0, r0, "$"])
8080
81 if r0 == ")" and r1 == "$" and r2 and r3 == "sink":
82 return dict(start=i, stop=i+3, pattern=[")", "$", r2, "sink"], replacement=[")", "$", r2])
83
8184 if r0 and r1 == "$" and r2 and r3 == "sink":
8285 return dict(start=i, stop=i+3, pattern=[r0, "$", r2, "sink"], replacement=["$", r2, "sink", r0])
8386