• R/O
  • SSH

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2


Commit MetaInfo

修订版67b41b41168be43083fc96d7c3548c1ae6dbd128 (tree)
时间2024-05-28 06:15:12
作者Albert Mietus < albert AT mietus DOT nl >
CommiterAlbert Mietus < albert AT mietus DOT nl >

Log Message

TESTDOUBLES::sieveCastle:EH done

更改概述

差异

diff -r cd0f75d04c29 -r 67b41b41168b TestDoubles_packages/TestDoubles-aigr-sieve/castle/TESTDOUBLES/aigr/sieve/basic1/sieveCastle.py
--- a/TestDoubles_packages/TestDoubles-aigr-sieve/castle/TESTDOUBLES/aigr/sieve/basic1/sieveCastle.py Mon May 27 20:01:59 2024 +0200
+++ b/TestDoubles_packages/TestDoubles-aigr-sieve/castle/TESTDOUBLES/aigr/sieve/basic1/sieveCastle.py Mon May 27 23:15:12 2024 +0200
@@ -42,7 +42,7 @@
4242 aigr.VoidCall(
4343 aigr.Call(
4444 callable=aigr.Part(
45- base=aigr.Call(callable=ID('super')), attribute=ID('init')),
45+ base=aigr.Call(callable=ID('super')), attribute=ID('init', context=aigr.Ref())),
4646 arguments=())),
4747 aigr.Become(
4848 targets=(aigr.Part(base=ID('self'), attribute=ID('myPrime', context=aigr.Set())),),
@@ -66,14 +66,20 @@
6666 port=ID('try', context=aigr.Ref()),
6767 body=aigr.Body(statements=[
6868 aigr.If(
69- test=aigr.Compare(ops=aigr.operators.NotEqual(), values=(
70- builders.Modulo(
71- ID("try", context=aigr.Ref()),
72- ID("myPrime",context=aigr.Ref())),
73- aigr.Constant(value=0))),
74- body=aigr.Body(statements=[
75- "XXX"
76- ]))]))
69+ test=aigr.Compare(
70+ ops=aigr.operators.NotEqual(),
71+ values=(
72+ builders.Modulo(
73+ ID("try", context=aigr.Ref()),
74+ ID("myPrime",context=aigr.Ref())),
75+ aigr.Constant(value=0),)),
76+ body=aigr.Body(
77+ statements=[
78+ aigr.machinery.sendEvent(
79+ outport=aigr.Part(base=ID('self'), attribute=ID('coprime', context=aigr.Ref())),
80+ event=ID('input',context=aigr.Ref()),
81+ arguments=[aigr.Argument(ID('try', context=aigr.Ref()))])
82+ ]))]))
7783
7884
7985
diff -r cd0f75d04c29 -r 67b41b41168b TestDoubles_packages/TestDoubles-aigr-sieve/pytst/sieve/basic1/test_sieveCastle.py
--- a/TestDoubles_packages/TestDoubles-aigr-sieve/pytst/sieve/basic1/test_sieveCastle.py Mon May 27 20:01:59 2024 +0200
+++ b/TestDoubles_packages/TestDoubles-aigr-sieve/pytst/sieve/basic1/test_sieveCastle.py Mon May 27 23:15:12 2024 +0200
@@ -15,6 +15,14 @@
1515 from . import find_name_in_body
1616
1717
18+def verify_ID(id, name, isRef=False, isDef=False, isSet=False):
19+ assert isinstance(id, aigr.ID), f"Expected an ID, found {type(id)} for {id}"
20+ assert id == name, f"wrong ID, expected {name}, got {id}"
21+ if isRef: assert isinstance(id.context, aigr.Ref)
22+ if isDef: assert isinstance(id.context, aigr.Def)
23+ if isSet: assert isinstance(id.context, aigr.Set)
24+
25+
1826 @pytest.fixture
1927 def comp():
2028 return sieveCastle.Sieve
@@ -44,22 +52,48 @@
4452 def test_0c_noParms(comp):
4553 assert comp.parameters == ()
4654
47-def test_1_init_has_2lines(comp):
55+def test_1a_init_has_2lines(comp):
4856 init = find_name_in_body('init', comp.body)
4957 assert isinstance(init, aigr.Method), f"Expected an init method, got {init}"
5058 assert len(init.body)==2, f"Expected that 'init' has 2 statements, but found: {len(init.body.statements)}"
5159
5260
53-def verify_IDref(id, expected_name):
54- assert id == expected_name, f"ID does not match, expected {expected_name}, got {id}"
55- assert isinstance(id, aigr.ID), f"ID ({id}) is not an ID, but type:{type(id)}"
56- assert isinstance(id.context, aigr.Ref), f"found ID '{id}' has not ref"
57- # XXX ToDo: check the ref -- for now empty is fine
61+def test_1b_init_1st_line_superinit(comp):
62+ """ CastleCode: super.init(); """
63+ init = find_name_in_body('init', comp.body)
64+ line = init.body[0]
65+
66+ assert isinstance(line, aigr.VoidCall) and isinstance(line.call, aigr.Call)
67+ callable, arguments = line.call.callable, line.call.arguments
68+
69+ assert isinstance(callable, aigr.Part)
70+ assert isinstance(callable.base, aigr.Call) and callable.base.callable == "super" and callable.base.arguments is ()
71+ verify_ID(callable.attribute, "init", isRef=True)
72+ assert callable.index is None
73+
74+ assert arguments is (), f"Expected no arguments, but found: {arguments}"
75+
76+
77+def test_1c_init_2nd_line_become(comp):
78+ """ CastleCode: .myPrime := onPrime; """
79+
80+ init = find_name_in_body('init', comp.body)
81+ line = init.body[1]
82+
83+ assert isinstance(line, aigr.Become) and len(line.targets)==1 and len(line.values)==1
84+ myPrime, onPrime = line.targets[0], line.values[0]
85+
86+ assert isinstance(myPrime, aigr.Part)
87+ verify_ID(myPrime.base, "self")
88+ verify_ID(myPrime.attribute, "myPrime", isSet=True)
89+
90+ verify_ID(onPrime, "onPrime", isRef=True)
91+
5892
5993 def test_2_handler_on_try(event_handler):
60- verify_IDref(event_handler.protocol, "SimpleSieve")
61- verify_IDref(event_handler.event, "input")
62- verify_IDref(event_handler.port, "try")
94+ verify_ID(event_handler.protocol, "SimpleSieve", isRef=True)
95+ verify_ID(event_handler.event, "input", isRef=True)
96+ verify_ID(event_handler.port, "try", isRef=True)
6397
6498
6599 def test_3a_EH_is_one_statement(event_handler):
@@ -84,7 +118,7 @@
84118
85119
86120 def test_3c_EH_test_exps(event_handler):
87- """ CastleCode: (try % .myPrime) !=0 """
121+ """ CastleCode: try % .myPrime) !=0 """
88122 if_statement = event_handler.body[0]
89123 test_expr = if_statement.test
90124
@@ -98,8 +132,8 @@
98132 assert len(lhs.values) == 2
99133 var_try, myPrime = lhs.values[0], lhs.values[1]
100134
101- assert isinstance(var_try, aigr.ID) and var_try == 'try' and isinstance(var_try.context, aigr.Ref)
102- assert isinstance(myPrime, aigr.ID) and myPrime == 'myPrime' and isinstance(myPrime.context, aigr.Ref)
135+ verify_ID(var_try, "try", isRef=True)
136+ verify_ID(myPrime, "myPrime", isRef=True)
103137
104138 # The rhs is easy/simple
105139 logger.debug("rhs: %s -- ``0``", rhs)
@@ -108,10 +142,21 @@
108142
109143
110144 def test_3d_EH_then_send(event_handler):
145+ """ CastleCode: .coprime.input(try); """
111146 if_statement=event_handler.body[0]
112147 then = if_statement.body
113148 assert len(then) == 1 # Not a test, only to check.
114149 send = then[0]
115150
116- assert False, "ToDo if-then"
151+ assert isinstance(send, aigr.machinery.sendEvent)
117152
153+ assert isinstance(send.outport, aigr.Part)
154+ verify_ID(send.outport.base, "self")
155+ verify_ID(send.outport.attribute, "coprime", isRef=True)
156+
157+ verify_ID(send.event, "input", isRef=True)
158+
159+ assert isinstance(send.arguments, (tuple, list)) and len(send.arguments) == 1
160+ assert isinstance(send.arguments[0], aigr.Argument)
161+ verify_ID(send.arguments[0].value, "try", isRef=True)
162+
diff -r cd0f75d04c29 -r 67b41b41168b base_packages/castle-aigr/castle/aigr/__init__.py
--- a/base_packages/castle-aigr/castle/aigr/__init__.py Mon May 27 20:01:59 2024 +0200
+++ b/base_packages/castle-aigr/castle/aigr/__init__.py Mon May 27 23:15:12 2024 +0200
@@ -13,3 +13,5 @@
1313
1414 from .statements import *
1515 from .expressions import *
16+
17+from . import machinery
diff -r cd0f75d04c29 -r 67b41b41168b base_packages/castle-aigr/castle/aigr/machinery/__init__.py
--- a/base_packages/castle-aigr/castle/aigr/machinery/__init__.py Mon May 27 20:01:59 2024 +0200
+++ b/base_packages/castle-aigr/castle/aigr/machinery/__init__.py Mon May 27 23:15:12 2024 +0200
@@ -20,7 +20,7 @@
2020 @dataclass
2121 class send_proto(machinery):
2222 _: KW_ONLY
23- outport : Port
23+ outport : AIGR # ID | Parts| ...
2424
2525 @dataclass
2626 class sendStream(send_proto, todo.mark_Dataclass): ...
@@ -29,7 +29,8 @@
2929
3030 @dataclass
3131 class sendEvent(send_proto):
32- event: Event
32+ _: KW_ONLY
33+ event: AIGR # ID | Parts| ...
3334 arguments: PTH.Sequence[Argument]
3435
3536 @dataclass