git @ Cat's Eye Technologies Xoomonk / c3e2924
Implement remainder of builtins. All tests pass! catseye 9 years ago
2 changed file(s) with 46 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
394394 getting 0 assigned to its `x`, and so forth.
395395
396396 | l := $.loop*
397 | counter := 5
397 | $.counter := 5
398398 | l.do := {
399399 | y := x
400 | print ^.counter
400 | print $.counter
401401 | o := $.sub*
402 | o.x := ^.counter
402 | o.x := $.counter
403403 | o.y := 1
404 | ^.counter := o.result
404 | $.counter := o.result
405405 | continue := o.result
406406 | }
407407 | print string "done!"
408408 = 5
409409 = 4
410 = 5
410 = 3
411411 = 2
412412 = 1
413413 = done!
469469 store['result'] = store['x'] - store['y']
470470 return store
471471
472 def mul(store):
473 store['result'] = store['x'] * store['y']
474 return store
475
476 def div(store):
477 store['result'] = store['x'] / store['y']
478 return store
479
480 def gt(store):
481 if store['x'] > store['y']:
482 store['result'] = 1
483 else:
484 store['result'] = 0
485
486 def not_(store):
487 if store['x'] == 0:
488 store['result'] = 1
489 else:
490 store['result'] = 0
491
492 def if_(store):
493 if store['cond'] != 0:
494 store['then']['x'] = store['cond']
495 else:
496 store['else']['x'] = store['cond']
497
498 def loop(store):
499 done = False
500 while not done:
501 do = store['do'].copy()
502 do['x'] = 0
503 done = (do['continue'] == 0)
504
472505 DOLLAR_STORE = {
473506 'add': MalingeringStore(['x', 'y', 'result'], ['x', 'y'], add),
474507 'sub': MalingeringStore(['x', 'y', 'result'], ['x', 'y'], sub),
508 'mul': MalingeringStore(['x', 'y', 'result'], ['x', 'y'], mul),
509 'div': MalingeringStore(['x', 'y', 'result'], ['x', 'y'], div),
510 'gt': MalingeringStore(['x', 'y', 'result'], ['x', 'y'], gt),
511 'not': MalingeringStore(['x', 'y', 'result'], ['x', 'y'], not_),
512 'if': MalingeringStore(['cond', 'then', 'else'],
513 ['cond', 'then', 'else'], if_),
514 'loop':MalingeringStore(['do'], ['do'], loop),
475515 }
476
516
477517
478518 def main(argv):
479519 optparser = OptionParser(__doc__)