sandbox_bin.html
001| from sys import stdout, stderr, argv
002| from datetime import datetime
003| from logger import logger
004| from x_act_sys import *
005| from x_act_lib import *
006| from x_act_usr import *
007| from x_mdl_list import ModelImplList
008| from x_mdl_bool import ModelImplBool
009| from x_mdl_int import ModelImplInt
010| from x_mdl_float import ModelImplFloat
011| from x_mdl_string import ModelImplString
012| from x_mdl_date import ModelImplDate
013| from x_environ import BoolEnvironment
014| from x_system import build_system_action, build_global_action, build_main_action
015|
016| Log = logger('sandbox')
017| Log.start('sandbox_bin.log')
018|
019| '''
019| NEXT STEPS...
019| Implement: Copy Params to Call Frame
019| '''
020|
021|
022|
023|
024| Env = BoolEnvironment('CJS')
025|
026|
027|
028| '''
028| @@hypot
028| >> *int a
028| >> *int b
028| << *int c
028| = set: c @sqrt add: mul:a a mul:b b
028|
028| @@loop-test
028| >> *int a
028| >> *int b
028| = @while lt:a b
028| . . @print a
028| . . @incr a
028| '''
029| act_id = 'hypot'
030| act_hypot_code = []
031| act_hypot_code.append(('INST', 'int', 0, None, ('name','a')))
032| act_hypot_code.append(('INST', 'int', 1, None, ('name','b')))
033| act_hypot_code.append(('INST', 'int', 2, None, ('name','c')))
034| act_hypot_code.append(('TEMP', 'any', 3))
035| act_hypot_code.append(('TEMP', 'any', 4))
036| act_hypot_code.append(('TEMP', 'any', 5))
037| act_hypot_code.append(('TEMP', 'float', 6))
038| act_hypot_code.append(('TEMP', 'any', 7))
039| act_hypot_code.append(('MSG', 'mul', (act_id,0), (act_id,0), (act_id,3)))
040| act_hypot_code.append(('MSG', 'mul', (act_id,1), (act_id,1), (act_id,4)))
041| act_hypot_code.append(('MSG', 'add', (act_id,8), (act_id,9), (act_id,5)))
042| act_hypot_code.append(('TOR', 'sqrt', [('sqrt',(act_id,10))], (act_id,6)))
043| act_hypot_code.append(('MSG', 'set', (act_id,2), (act_id,11), (act_id,7)))
044| act_hypot_code.append(('LST', 1, (act_id,12)))
045|
046| act_hypot = ('ACT', act_id, [ (act_id,2,(act_id,12)) ], [(act_id,0),(act_id,1)], [(act_id,2)], 8, act_hypot_code)
047|
048|
049| act_id = 'loop-test'
050| act_loop_code = []
051| act_loop_code.append(('INST', 'int', 0, None, ('name','a')))
052| act_loop_code.append(('INST', 'int', 1, None, ('name','b')))
053| act_loop_code.append(('INST', 'int', 2, None, ('name','retv')))
054| act_loop_code.append(('TEMP', 'any', 3))
055| act_loop_code.append(('TEMP', 'any', 4))
056| act_loop_code.append(('TEMP', 'any', 5))
057| act_loop_code.append(('TEMP', 'any', 6))
058| act_loop_code.append(('MSG', 'lt', (act_id,1), (act_id,2), (act_id,3)))
059| act_loop_code.append(('TOR', 'print', [('print',(act_id,0))], (act_id,4)))
060| act_loop_code.append(('TOR', 'incr', [('incr',(act_id,0))], (act_id,5)))
061| act_loop_code.append(('LST', 2, (act_id,8), (act_id,9)))
062| act_loop_code.append(('TOR', 'while', [('while',(act_id,7),(act_id,10))], (act_id,6)))
063| act_loop_code.append(('LST', 1, (act_id,11)))
064|
065| act_loop = ('ACT', act_id, [ (act_id,2,(act_id,12)) ], [(act_id,0),(act_id,1)], [(act_id,2)], 7, act_hypot_code)
066|
067|
068| '''
068| @@foobar
068| = *int a = 5
068| . *int b = 7
068| . @print @hypot a b
068| . @loop-test a b
068| . @print a
068| '''
069| act_id = 'foobar'
070| act_foobar_code = []
071| act_foobar_code.append(act_hypot)
072| act_foobar_code.append(act_loop)
073| act_foobar_code.append(('INST', 'int', 0, None))
074| act_foobar_code.append(('LST', 1, ('system',14)))
075| act_foobar_code.append(('LST', 1, ('system',15)))
076| act_foobar_code.append(('INST', 'int', 1, (act_id,3), ('name','a')))
077| act_foobar_code.append(('INST', 'int', 2, (act_id,4), ('name','b')))
078| act_foobar_code.append(('TEMP', 'any', 3))
079| act_foobar_code.append(('TEMP', 'any', 4))
080| act_foobar_code.append(('TEMP', 'any', 5))
081| act_foobar_code.append(('TEMP', 'any', 6))
082| act_foobar_code.append(('TOR', 'hypot', [('hypot',(act_id,5),(act_id,6))], (act_id,7)))
083| act_foobar_code.append(('TOR', 'print', [('print',(act_id,11))], (act_id,8)))
084| act_foobar_code.append(('TOR', 'loop-test', [('loop-test',(act_id,5),(act_id,6))], (act_id,9)))
085| act_foobar_code.append(('TOR', 'print', [('print',(act_id,5))], (act_id,10)))
086| act_foobar_code.append(('LST', 5, (act_id,5),(act_id,6),(act_id,12),(act_id,13),(act_id,14)))
087|
088| act_foobar = ('ACT', act_id, [ (act_id,0,(act_id,15)) ], [], [(act_id,0)], 7, act_foobar_code)
089|
090|
091|
092|
093| def main ():
094|
095| act_main = build_main_action(Env, act_foobar)
096|
097|
098| act_global = build_global_action(Env, act_main)
099|
100|
101| act_system = build_system_action(Env, act_global)
102|
103| try:
104|
105| Env.meta['ACT'].invoke_action(Env, None, ('__bool__',act_system), [('system',)])
106| Log.info('Action Exited Normally!')
107| except EOFError as e:
108| Log.warn(e)
109|
110| Log.info('Done!')
111|
112|
113|
114| if __name__ == '__main__':
115| print('autorun',argv[0])
116| try:
117| main()
118| except Exception as e:
119| Log.error(e)
120| print(e)
121| finally:
122| Log.end()
123|
124| '''eof'''
125|