• R/O
  • SSH

Commit

Tags
Keine 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

Revisionb9c8c8df87927d66b7a7903b9b618bfb6d8ef7f7 (tree)
Zeit2023-02-05 03:35:53
AutorAlbert Mietus < albert AT mietus DOT nl >
CommiterAlbert Mietus < albert AT mietus DOT nl >

Log Message

asis

Ändern Zusammenfassung

Diff

diff -r de24bfc5c82a -r b9c8c8df8792 Makefile
--- a/Makefile Sat Feb 04 00:47:31 2023 +0100
+++ b/Makefile Sat Feb 04 19:35:53 2023 +0100
@@ -6,7 +6,6 @@
66 pytst/writers/CC2Cpy/test_2a_groundwork.py \
77 pytst/writers/CC2Cpy/test_2b_EventProtocol.py \
88 pytst/writers/CC2Cpy/test_3a_CompPort.py \
9-
109 #
1110 CURRENT_TESTS = \
1211 pytst/writers/CC2Cpy/test_3b_CompInterface.py \
diff -r de24bfc5c82a -r b9c8c8df8792 castle/writers/CC2Cpy/Component.py
--- a/castle/writers/CC2Cpy/Component.py Sat Feb 04 00:47:31 2023 +0100
+++ b/castle/writers/CC2Cpy/Component.py Sat Feb 04 19:35:53 2023 +0100
@@ -10,15 +10,15 @@
1010 CC_Component: TypeAlias = 'CC_Component' # Forward ref # pragma: no mutate
1111
1212 class CC_PortDirection(Enum):
13- Unknown = CC_B_PortDirectionIs_UNKNOWN = 0
14- In = CC_B_PortDirectionIs_in = 1
15- Out = CC_B_PortDirectionIs_out = 2
16- BiDir = CC_B_PortDirectionIs_bidirect = 3 # Not supported yet
17- Master = CC_B_PortDirectionIs_master = 4 # Not supported yet
18- Slave = CC_B_PortDirectionIs_slave = 5 # Not supported yet
13+ CC_B_PortDirectionIs_UNKNOWN = Unknown = 0
14+ CC_B_PortDirectionIs_in = In = 1
15+ CC_B_PortDirectionIs_out = Out = 2
16+ CC_B_PortDirectionIs_bidirect = BiDir = 3 # Not supported yet
17+ CC_B_PortDirectionIs_master = Master = 4 # Not supported yet
18+ CC_B_PortDirectionIs_slave = Slave = 5 # Not supported yet
1919
20- def render(self): ### CC_B_PortDirectionIs_{self.name}'
21- return f'CC_B_PortDirectionIs_{self.name}'
20+ def portray_name(self): ### CC_B_PortDirectionIs_{self.name}'
21+ return f'{self.name}'
2222
2323 @dataclass
2424 class CC_Port(CC_Base):
@@ -27,8 +27,15 @@
2727 direction: CC_PortDirection = CC_PortDirection.Unknown
2828 type: type
2929
30- def render(self) ->str: ### <port name>
31- return f'cc_P_{self.type if isinstance(self.type, str) else self.type.name}'
30+ def portray_name(self) ->str: ### <port name>
31+ return f'{self.name}'
32+
33+ def portray_type(self) ->str: ### <port type> e.g a protocol
34+ if isinstance(self.type, CC_Base):
35+ return self.type.portray_name()
36+ else:
37+ tn = self.type if isinstance(self.type, str) else self.type.__name__
38+ return f'cc_P_{tn}'
3239
3340
3441 @dataclass
diff -r de24bfc5c82a -r b9c8c8df8792 castle/writers/CC2Cpy/Protocol.py
--- a/castle/writers/CC2Cpy/Protocol.py Sat Feb 04 00:47:31 2023 +0100
+++ b/castle/writers/CC2Cpy/Protocol.py Sat Feb 04 19:35:53 2023 +0100
@@ -37,6 +37,9 @@
3737 kind: CC_ProtocolKind
3838 based_on: Optional[CC_B_Protocol]=dc_field(default_factory= lambda :CC_B_Protocol._BASE)
3939
40+ def portray_name(self):
41+ return f'cc_P_{self.name}'
42+
4043
4144 baseProtocol = CC_B_Protocol("Protocol", kind=CC_ProtocolKind.Unknown, based_on=None) # pragma: no mutate
4245 CC_B_Protocol._BASE=baseProtocol
@@ -72,16 +75,15 @@
7275 self.render_indexes(prepend) + "\n" +
7376 self.render_FTs(prepend) + "\n" )
7477
75-
7678 def render_struct(self, prepend:str="", indent=" ") ->str: ## struct CC_B_Protocol $name = {...} ;
77- var_name = f'cc_P_{self.name}'
78- based_on_link = f'&cc_P_{self.based_on.name}' if self.based_on else "NULL"
79+ var_name = self.portray_name()
80+ based_on_ref = f'&{self.based_on.portray_name()}' if self.based_on else "NULL"
7981
8082 retval = []
8183 retval.append(f'{prepend}struct CC_B_Protocol {var_name} = {{')
8284 retval.append(f'{prepend}{indent}.name = "{self.name}",')
8385 retval.append(f'{prepend}{indent}.kind = CC_B_ProtocolKindIs_{self.kind.name},')
84- retval.append(f'{prepend}{indent}.inherit_from = {based_on_link},')
86+ retval.append(f'{prepend}{indent}.inherit_from = {based_on_ref},')
8587 retval.append(f'{prepend}{indent}.length = {len(self.events)},')
8688 retval.append(f'{prepend}{indent}.events = {{')
8789
diff -r de24bfc5c82a -r b9c8c8df8792 pytst/writers/CC2Cpy/test_3a_CompPort.py
--- a/pytst/writers/CC2Cpy/test_3a_CompPort.py Sat Feb 04 00:47:31 2023 +0100
+++ b/pytst/writers/CC2Cpy/test_3a_CompPort.py Sat Feb 04 19:35:53 2023 +0100
@@ -2,7 +2,7 @@
22 """
33 Test the supporting types (Enum, dataclasses ect) for CC_B_ComponentInterface, and ...
44
5-The more relevant test of Protocol can be found in test_3b_* and test_3c_*"""
5+The more relevant test of Component(s) can be found in test_3b_* and test_3c_*"""
66
77 import logging; logger = logging.getLogger(__name__)
88 import pytest
@@ -10,6 +10,7 @@
1010
1111 from castle.writers.CC2Cpy.Component import *
1212
13+
1314 def test_1a_CC_PortDirection():
1415 # Test the (int) value -- needed for the generated C code
1516 assert CC_PortDirection.Unknown.value == 0
@@ -27,8 +28,14 @@
2728 assert CC_PortDirection.Master == CC_PortDirection.CC_B_PortDirectionIs_master
2829 assert CC_PortDirection.Slave == CC_PortDirection.CC_B_PortDirectionIs_slave
2930
30-@pytest.mark.skip(reason="Is rendering needed?")
31-def test_1b_render_PortDirection(): pass
31+def test_1b_portray_PortDirection():
32+ assert CCompare('CC_B_PortDirectionIs_UNKNOWN', CC_PortDirection.Unknown.portray_name())
33+ assert CCompare('CC_B_PortDirectionIs_in', CC_PortDirection.In.portray_name())
34+ assert CCompare('CC_B_PortDirectionIs_out', CC_PortDirection.Out.portray_name())
35+ assert CCompare('CC_B_PortDirectionIs_bidirect', CC_PortDirection.BiDir.portray_name())
36+ assert CCompare('CC_B_PortDirectionIs_master', CC_PortDirection.Master.portray_name())
37+ assert CCompare('CC_B_PortDirectionIs_slave', CC_PortDirection.Slave.portray_name())
38+
3239
3340 def test_2a1_Port_defaults():
3441 n, t = "defaults", int
@@ -46,11 +53,31 @@
4653 assert inp.direction == d
4754
4855
49-@pytest.mark.skip(reason="Is rendering needed?")
50-def test_2z_render_Port(): pass
51-
56+def test_2b1_portray_Port_name():
57+ port = CC_Port(name="aPort", type="no_relevant")
58+ assert CCompare('aPort', port.portray_name())
5259
53-
60+def test_2b2a_portray_Port_strtype():
61+ port = CC_Port(name="=NoName", type="textType")
62+ assert CCompare('cc_P_textType', port.portray_type())
5463
55-@pytest.mark.skip(reason="More basic-testse are needed")
56-def test_more(): pass
64+def test_2b2b_portray_Port_inttype():
65+ port = CC_Port(name="=NoName", type=int)
66+ assert CCompare('cc_P_int', port.portray_type())
67+
68+def test_2b2c_portray_Port_floattype():
69+ port = CC_Port(name="=NoName", type=float)
70+ assert CCompare('cc_P_float', port.portray_type())
71+
72+from castle.writers.CC2Cpy.Protocol import * #CC_EventProtocol
73+
74+def test_2b2c_portray_Port_Protocol():
75+ proto = CC_EventProtocol("JustAProtocol", events=[], based_on=None)
76+ port = CC_Port(name="=NoName", type=proto)
77+ # Note: When a Port's type is a Protocol, than the port's portray_type is both
78+ ## the string 'cc_P_<xxxx>', and
79+ ## the portray_name of that protocol.
80+ ## We check both for now.
81+ assert CCompare('cc_P_JustAProtocol', port.portray_type())
82+ assert CCompare(proto.portray_name(), port.portray_type())
83+