basics.html


001| ####################################################################################################
002| from sys import stdout, stderr, argv
003| ####################################################################################################
004| 
005| #
006| BoolList = ('LST', 3, ('addr',1234), ('addr',2345), ('addr',3456), '?')
007| #
008| # If there is a final member, a string '?', then the List is Gated, which means the first
009| # item in the List is a Gate Expression that is evaluated for TRUE/FALSE. If TRUE, then
010| # the remaining members of the list get Messages (whatever was sent to the List) as usual.
011| # If FALSE, the List sends no Message to those members.
012| #
013| # Without the Gate, the List sends its Message to all members.
014| #
015| 
016| #
017| Object = ('OBJ', 'int', ('ds',12), ('addr',1234), ('constant','0'), ('name','foo'))
018| #
019| # (OBJ, model, ds-id, initializer [attributes])
020| #
021| # The 'constant' and 'name' attributes mutually exclusive logically (they would have identical values).
022| 
023| #
024| Reference = ('REF', 'int', 2, ('name','bar'))
025| #
026| # (REF, model, ds-id, [attributes])
027| #
028| # References do not have an initializer field!
029| #
030| 
031| #
032| Message = ('MSG', 'add', ('addr',1234), [('addr',4321)])
033| #
034| # (MSG, name, target, [arguments-list])
035| #
036| 
037| #
038| # @@test
039| #
040| _SS = ('test', '<', '<')
041| _NT = {}
042| _AS = []
043| Action1 = ('ACT', _SS, [], [], [('test',0,None)], _AS, _NT)
044| #
045| # @@fourtwo
046| # << *int answer = 42
047| #
048| _SS = ('fourtwo', '<*', '<*int')
049| _NT = {'answer':1}
050| _AS =[   ('LST', 1, ('constant', '42'))
051| ,   ('OBJ', 'int', 0, ('local',0), ('name','answer'))
052| ]
053| Action2 = ('ACT', _SS, [('local',1)], [('local',1)], [('fourtwo',0,None)], _AS, _NT)
054| #
055| # @@sin
056| # >> *float angle
057| # << *float answer = sin:angle;
058| #
059| _SS = ('sin', '*<*', '*float<*float')
060| _NT = {'angle':0, 'answer':3}
061| _AS =[   ('REF', 'float', 0, ('name','angle'))
062| ,   ('MSG', 'sin', ('local',0), [])
063| ,   ('LST', 1, ('local',1))
064| ,   ('OBJ', 'float', 1, ('local',2), ('name','answer'))
065| ]
066| Action3 = ('ACT', _SS, [('local',0),('local',3)], [('local',3)], [('sin',1,None)], _AS, _NT)
067| #
068| # @@add
069| # >> *int a
070| # >> *int b
071| # << *int c
072| # . set:c add:a b;;
073| #
074| _SS = ('add', '**<*', '*int*int<*int')
075| _NT = {'a':0, 'b':1, 'c':2}
076| _AS =[   ('REF', 'int', 0, ('name','a'))
077| ,   ('REF', 'int', 0, ('name','b'))
078| ,   ('OBJ', 'int', 0, None, ('name','c'))
079| ,   ('MSG', 'add', ('local',0), [('local',1)])
080| ,   ('MSG', 'set', ('local',2), [('local',3)])
081| ,   ('LST', 1, ('local',4))
082| ]
083| Action4 = ('ACT', _SS, [('local',0),('local',1),('local',2)], [('local',2)], [('add',2,('local',5))], _AS, _NT)
084| #
085| #
086| del _SS
087| del _NT
088| del _AS
089| 
090| #
091| # @test
092| #
093| Actor1 = ('TOR', 'test', [('test',)])
094| #
095| # @add a b
096| #
097| Actor2 = ('TOR', 'add', [('add',('addr',1234),('addr',2345))])
098| #
099| # @if...
100| #
101| Actor3a = ('TOR', 'if', [
102|     ('if'  ,('addr',1234),('addr',2345))
103| ])
104| Actor3b = ('TOR', 'if', [
105|     ('if'  ,('addr',1234),('addr',2345)),
106|     ('else',('addr',5678))
107| ])
108| Actor3c = ('TOR', 'if', [
109|     ('if'  ,('addr',1234),('addr',2345)),
110|     ('elif',('addr',3456),('addr',4567)),
111|     ('else',('addr',5678))
112| ])
113| Actor3d = ('TOR', 'if', [
114|     ('if'  ,('addr',1234),('addr',2345)),
115|     ('elif',('addr',3456),('addr',4567)),
116|     ('elif',('addr',5678),('addr',6789)),
117|     ('elif',('addr',7890),('addr',8901)),
118|     ('else',('addr',9012))
119| ])
120| 
121| 
122| #
123| Model_Actions = {} # list of Model-Action nodes: Name:(Action, Actor)
124| 
125| Model = ('MOD', 'int', [('OBJ','int',0,None)], Model_Actions)
126| #
127| # The name of an Action under a Model is the name of the Message that invokes it.
128| 
129| 
130| 
131| 
132| ####################################################################################################
133| def main (command='', arguments=[]):
134|     print('command:',command)
135|     if command == 'test':
136|         return arguments
137|     if (command == '') or (command == 'main'):
138|         return arguments
139|     return (command, arguments)
140| 
141| ####################################################################################################
142| if __name__ == '__main__':
143|     print('autorun:',argv[0])
144|     cmnd = argv[1]  if 1 < len(argv) else ''
145|     args = argv[2:] if 2 < len(argv) else []
146|     obj = main(cmnd, args)
147|     print('done:',type(obj))
148|     print(dir())
149| 
150| ####################################################################################################
151| '''eof'''
152|