• R/O
  • SSH

提交

標籤
無標籤

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

修訂ceeed66715518e5ef6476c773ae96d73dc5f3a87 (tree)
時間2024-05-14 01:15:56
作者Albert Mietus < albert AT mietus DOT nl >
CommiterAlbert Mietus < albert AT mietus DOT nl >

Log Message

BUSY: sieveCastle (TESTDOUBLE): started with an EventHandler.

Change Summary

差異

diff -r 77c6349fb303 -r ceeed6671551 TestDoubles_packages/TestDoubles-aigr-sieve/Makefile
--- a/TestDoubles_packages/TestDoubles-aigr-sieve/Makefile Sun May 12 17:52:58 2024 +0200
+++ b/TestDoubles_packages/TestDoubles-aigr-sieve/Makefile Mon May 13 18:15:56 2024 +0200
@@ -8,7 +8,8 @@
88 pytst/sieve/basic1/test_2_sieve_NS.py \
99 pytst/sieve/basic1/test_3_components.py \
1010 #
11-CURRENT = pytst/sieve/basic1/test_sieveCastle.py \
11+CURRENT = \
12+ pytst/sieve/basic1/test_sieveCastle.py \
1213 #
1314
1415 TODO = \
diff -r 77c6349fb303 -r ceeed6671551 TestDoubles_packages/TestDoubles-aigr-sieve/castle/TESTDOUBLES/aigr/sieve/basic1/components.py
--- a/TestDoubles_packages/TestDoubles-aigr-sieve/castle/TESTDOUBLES/aigr/sieve/basic1/components.py Sun May 12 17:52:58 2024 +0200
+++ b/TestDoubles_packages/TestDoubles-aigr-sieve/castle/TESTDOUBLES/aigr/sieve/basic1/components.py Mon May 13 18:15:56 2024 +0200
@@ -5,6 +5,8 @@
55 .. see also:: :file:`./__init__.py` for a general intro
66 """
77
8+__all__= ['GeneratorMoat', 'SieveMoat', 'FinderMoat']
9+
810 from castle.aigr.aid import TypedParameter
911 from castle.aigr import ComponentInterface, ID
1012 from castle.aigr import Port, PortDirection
@@ -27,11 +29,9 @@
2729 # port SimpleSieve<in>:try;
2830 # port SimpleSieve<out>:coprime;
2931 # }
30-SieveMoat = ComponentInterface(name=ID("Sieve"),
31- ports=(
32- Port(name='try', direction=PortDirection.In, type=protocols.SimpleSieve),
33- Port(name='coprime', direction=PortDirection.Out, type=protocols.SimpleSieve),
34- ))
32+port_try = Port(name='try', direction=PortDirection.In, type=protocols.SimpleSieve)
33+port_coprime = Port(name='coprime', direction=PortDirection.Out, type=protocols.SimpleSieve)
34+SieveMoat = ComponentInterface(name=ID("Sieve"), ports=(port_try, port_coprime))
3535
3636
3737 # component Finder : Component {
diff -r 77c6349fb303 -r ceeed6671551 TestDoubles_packages/TestDoubles-aigr-sieve/castle/TESTDOUBLES/aigr/sieve/basic1/protocols.py
--- a/TestDoubles_packages/TestDoubles-aigr-sieve/castle/TESTDOUBLES/aigr/sieve/basic1/protocols.py Sun May 12 17:52:58 2024 +0200
+++ b/TestDoubles_packages/TestDoubles-aigr-sieve/castle/TESTDOUBLES/aigr/sieve/basic1/protocols.py Mon May 13 18:15:56 2024 +0200
@@ -17,8 +17,8 @@
1717 """protocol SimpleSieve : EventProtocol {
1818 input(int:try);
1919 }"""
20+input_event = Event(name=ID('input'), return_type=None, typedParameters=(TypedParameter(name='try', type=int),))
2021 SimpleSieve = EventProtocol(ID('SimpleSieve'),
21- events=(
22- Event(name=ID('input'), return_type=None, typedParameters=(TypedParameter(name='try', type=int),)),))
22+ events=(input_event,))
2323
2424
diff -r 77c6349fb303 -r ceeed6671551 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 Sun May 12 17:52:58 2024 +0200
+++ b/TestDoubles_packages/TestDoubles-aigr-sieve/castle/TESTDOUBLES/aigr/sieve/basic1/sieveCastle.py Mon May 13 18:15:56 2024 +0200
@@ -4,21 +4,23 @@
44
55 .. see also:: :file:`./__init__.py` for a general intro
66 """
7+import logging; logger = logging.getLogger(__name__)
78
89 __all__ = ['Sieve']
910
1011
1112 from castle import aigr
12-from castle.aigr import ComponentImplementation, ID, Method
13+from castle.aigr import ComponentImplementation, ID
14+from castle.aigr import Method, EventHandler
15+
16+from castle.aigr_extra.blend import mangle_event_handler
1317
1418
19+from . import components, protocols
1520
1621 # implement Sieve {
1722 # int myPrime;
1823 # ...
19-
20-from . import components
21-
2224 Sieve = ComponentImplementation('Sieve',
2325 interface=components.SieveMoat,
2426 parameters=(),
@@ -27,6 +29,7 @@
2729 assert isinstance(Sieve.body, aigr.Body) # This make mypy happy to fill-in the Body
2830
2931
32+
3033 # init(int:onPrime) // `init` is (typically) part of the construction of a element.
3134 # {
3235 # super.init(); // `super` acts as port to the base-class
@@ -45,8 +48,8 @@
4548 targets=(aigr.Part(base=ID('self'), attribute=ID('myPrime', context=aigr.Set())),),
4649 values=(ID('onPrime', context=aigr.Ref()),))]))
4750
51+Sieve.body.expand(init_method)
4852
49-Sieve.body.expand(init_method)
5053
5154
5255 # SimpleSieve.input(try) on .try
@@ -57,3 +60,14 @@
5760 # }
5861 #
5962 # } //@end Sieve
63+event_handler_1 = EventHandler(ID(mangle_event_handler(protocol="SimpleSieve", event="input", port="try"), context=aigr.Def()),
64+ protocol=ID('SimpleSieve', context=aigr.Ref()),
65+ event=ID('input', context=aigr.Ref()),
66+ port=ID('try', context=aigr.Ref()),
67+ body=aigr.Body(statements=[
68+ # XXXX
69+ ]))
70+
71+
72+
73+Sieve.body.expand(event_handler_1)
diff -r 77c6349fb303 -r ceeed6671551 TestDoubles_packages/TestDoubles-aigr-sieve/pytst/sieve/basic1/test_sieveCastle.py
--- a/TestDoubles_packages/TestDoubles-aigr-sieve/pytst/sieve/basic1/test_sieveCastle.py Sun May 12 17:52:58 2024 +0200
+++ b/TestDoubles_packages/TestDoubles-aigr-sieve/pytst/sieve/basic1/test_sieveCastle.py Mon May 13 18:15:56 2024 +0200
@@ -6,8 +6,13 @@
66
77 import pytest
88
9+
10+from castle import aigr
11+from castle.aigr_extra.blend import mangle_event_handler
12+
913 from castle.TESTDOUBLES.aigr.sieve.basic1 import sieveCastle
10-from castle import aigr
14+from castle.TESTDOUBLES.aigr.sieve.basic1 import protocols, components
15+
1116
1217 from . import find_name_in_body
1318
@@ -30,11 +35,32 @@
3035 def test_0c_noParms(comp):
3136 assert comp.parameters == ()
3237
33-def test_has_init(comp):
38+
39+def test_1_init_has_2lines(comp):
3440 init = find_name_in_body('init', comp.body)
3541 assert isinstance(init, aigr.Method), f"Expected an init method, got {init}"
36-
37-def test_init_has_body(comp):
38- init = find_name_in_body('init', comp.body)
3942 assert len(init.body)==2, f"Expected that 'init' has 2 statements, but found: {len(init.body.statements)}"
4043
44+
45+def verify_IDref(id, expected_name):
46+ assert id == expected_name, f"ID does not match, expected {expected_name}, got {id}"
47+ assert isinstance(id, aigr.ID), f"ID ({id}) is not an ID, but type:{type(id)}"
48+ assert isinstance(id.context, aigr.Ref), f"found ID '{id}' has not ref"
49+ # XXX ToDo: check the ref -- for now empty is fine
50+
51+
52+def test_2_handler_on_try(comp):
53+ """The event-handler name and the name of protocol/event/port are all text, but ...
54+ should match the names of the earlier/elsewere defined protocol/event/port structure.
55+ """
56+ # Notes
57+ #@ - event(`input`) -- this protocol has only one event, so its simple
58+ ## - port('try') -- thats the 1ste one. But keep it in sync (CastleCode is leading)
59+ (protocol, event, port) = protocols.SimpleSieve, protocols.SimpleSieve.events[0], components.SieveMoat.ports[0]
60+
61+ handler = find_name_in_body(mangle_event_handler(protocol=protocol.name, event=event.name, port=port.name), comp.body)
62+ assert handler, "No handler found"
63+
64+ verify_IDref(handler.protocol, protocol.name)
65+ verify_IDref(handler.event, event.name)
66+ verify_IDref(handler.port, port.name)