• 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

修訂5ff5f113ebfe059ad6ee570058bc41f1b02caf42 (tree)
時間2023-01-30 06:53:49
作者Albert Mietus < albert AT mietus DOT nl >
CommiterAlbert Mietus < albert AT mietus DOT nl >

Log Message

Starting with Component rendering: Port, Interface, Class & struct

Change Summary

差異

diff -r 5a48482b6d4b -r 5ff5f113ebfe Makefile
--- a/Makefile Sun Jan 29 12:28:05 2023 +0100
+++ b/Makefile Sun Jan 29 22:53:49 2023 +0100
@@ -7,7 +7,10 @@
77 pytst/writers/CC2Cpy/test_2b_EventProtocol.py \
88 #
99 CURRENT_TESTS = \
10- pytst/writers/CC2Cpy/test_3_Interface.py \
10+ pytst/writers/CC2Cpy/test_3a_CompPort.py \
11+ pytst/writers/CC2Cpy/test_3b_CompInterface.py \
12+ pytst/writers/CC2Cpy/test_3c_CompClass.py \
13+ pytst/writers/CC2Cpy/test_3d_CompStruct.py \
1114 #
1215 TODO_TESTS = \
1316 pytst/writers/CC2Cpy/test_999_NoNameCollision.py \
diff -r 5a48482b6d4b -r 5ff5f113ebfe castle/writers/CC2Cpy/Component.py
--- a/castle/writers/CC2Cpy/Component.py Sun Jan 29 12:28:05 2023 +0100
+++ b/castle/writers/CC2Cpy/Component.py Sun Jan 29 22:53:49 2023 +0100
@@ -2,5 +2,83 @@
22
33 __all__ = ['CC_B_ComponentInterface', ]
44
5+from enum import Enum
6+
57 from .CCbase import *
6-class CC_B_ComponentInterface(CC_Base): pass
8+CC_Component: TypeAlias = 'CC_Component' # Forward ref
9+
10+class CC_PortDirection(Enum):
11+ Unknown = CC_B_PortDirectionIs_UNKNOWN = 0
12+ In = CC_B_PortDirectionIs_in = 1
13+ Out = CC_B_PortDirectionIs_out = 2
14+ BiDir = CC_B_PortDirectionIs_bidirect = 3 # Not supported yet
15+ Master = CC_B_PortDirectionIs_master = 4 # Not supported yet
16+ Slave = CC_B_PortDirectionIs_slave = 5 # Not supported yet
17+
18+ def render(self): ### CC_B_PortDirectionIs_{self.name}'
19+ return f'CC_B_PortDirectionIs_{self.name}'
20+
21+@dataclass
22+class CC_Port(CC_Base):
23+ name: str
24+ _ : KW_ONLY
25+ direction: CC_PortDirection = CC_PortDirection.Unknown
26+ type: type
27+
28+ def render(self) ->str: ### <port name>
29+ return f'cc_P_{self.type if isinstance(self.type, str) else self.type.name}'
30+
31+class CC_B_ComponentInterface(CC_Base):pass
32+## @dataclass
33+## class CC_B_ComponentInterface(CC_Base):
34+## name: str
35+## based_on: Optional[CC_Component]=()
36+## _: KW_ONLY
37+## ports: Sequence[CC_Port] =()
38+
39+## def __post_init__(self):
40+## self.based_on = mk_tuple(self.based_on)
41+## self.ports = mk_tuple(self.ports)
42+
43+## def no_of_ports(self, inherired=False, mine=True) ->int:
44+## count = 0
45+## if inherired:
46+## for b in self.based_on:
47+## count += b.no_of_ports(inherired=True)
48+## if mine:
49+## count += len(self.ports)
50+## return count
51+
52+## def render(self, prepend:str="", indent=" ") ->str:
53+## self.render_struct(prepend=prepend, indent=indent)
54+
55+## def render_struct(self, prepend:str="", indent=" ") ->str: ## struct CC_B_ComponentInterface cc_CI_${name} ...
56+## """
57+## .. todo::
58+
59+## - Move `CC_B_ComponentInterface.render()` into a Rendering subclass-delegate
60+## - refactor & test: spilt into parts
61+## - optional: Use Jinja ipv f-strings
62+## - make name/prefix (``f'cc_CI_{self.name}``) in a getter oid
63+## """
64+## name = f'cc_CI_{self.name}'
65+## based_on_link = f'&cc_CI_{self.based_on[0].name}' if self.based_on[0] else "NULL"
66+
67+## retval = []
68+## retval.append(f'{prepend}struct CC_B_ComponentInterface {name} = {{')
69+## retval.append(f'{prepend}{indent}.name = "{self.name}",')
70+## retval.append(f'{prepend}{indent}.inherit_from = {based_on_link},')
71+## retval.append(f'{prepend}{indent}.length = {len(self.ports)},')
72+## retval.append(f'{prepend}{indent}.ports = {{')
73+
74+## #loop over ports ...
75+## for n,p in enumerate(self.ports, self.no_of_ports(inherired=True, mine=False)):
76+## retval.append(f'{prepend}{(indent*3)[:-2]}{{ .portNo = {n}, ')
77+## retval.append(f'{prepend}{indent*3}.protocol = &{p.render()}, ')
78+## retval.append(f'{prepend}{indent*3}.direction = {p.direction.render()}, ')
79+## retval.append(f'{prepend}{indent*3}.name = "{p.name}", ')
80+## retval.append(f'{prepend}{indent*3}.part_of = &{name} }} ,')
81+## retval.append(f'{prepend}{indent}}}') # end of ports
82+## retval.append(f'{prepend}}} ;') # end of struct
83+
84+## return '\n'.join(retval)+"\n"
diff -r 5a48482b6d4b -r 5ff5f113ebfe pytst/writers/CC2Cpy/test_3_Interface.py
--- a/pytst/writers/CC2Cpy/test_3_Interface.py Sun Jan 29 12:28:05 2023 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
1-# (C) Albert Mietus, 2022, 2023. Part of Castle/CCastle project
2-
3-import logging; logger = logging.getLogger(__name__)
4-import pytest
5-from . import * # CCompare
6-
7-from castle.writers.CC2Cpy.Component import * # CC_B_ComponentInterface
diff -r 5a48482b6d4b -r 5ff5f113ebfe pytst/writers/CC2Cpy/test_3a_CompPort.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pytst/writers/CC2Cpy/test_3a_CompPort.py Sun Jan 29 22:53:49 2023 +0100
@@ -0,0 +1,37 @@
1+# (C) Albert Mietus, 2022, 2023. Part of Castle/CCastle project
2+"""
3+Test the supporting types (Enum, dataclasses ect) for CC_B_ComponentInterface, and ...
4+
5+The more relevant test of Protocol can be found in test_3b_* and test_3c_*"""
6+
7+import logging; logger = logging.getLogger(__name__)
8+import pytest
9+from . import * # CCompare
10+
11+from castle.writers.CC2Cpy.Component import *
12+from castle.writers.CC2Cpy.Component import CC_PortDirection # Not public XXX
13+
14+def test_1a_CC_PortDirection():
15+ # Test the (int) value -- needed for the generated C code
16+ assert CC_PortDirection.Unknown.value == 0
17+ assert CC_PortDirection.In.value == 1
18+ assert CC_PortDirection.Out.value == 2
19+ assert CC_PortDirection.BiDir.value == 3
20+ assert CC_PortDirection.Master.value == 4
21+ assert CC_PortDirection.Slave.value == 5
22+
23+ # Test the long-name & short-name are the same
24+ assert CC_PortDirection.Unknown == CC_PortDirection.CC_B_PortDirectionIs_UNKNOWN
25+ assert CC_PortDirection.In == CC_PortDirection.CC_B_PortDirectionIs_in
26+ assert CC_PortDirection.Out == CC_PortDirection.CC_B_PortDirectionIs_out
27+ assert CC_PortDirection.BiDir == CC_PortDirection.CC_B_PortDirectionIs_bidirect
28+ assert CC_PortDirection.Master == CC_PortDirection.CC_B_PortDirectionIs_master
29+ assert CC_PortDirection.Slave == CC_PortDirection.CC_B_PortDirectionIs_slave
30+
31+@pytest.mark.skip(reason="Is rendering needed?")
32+def test_1b_PortRender(): pass
33+
34+
35+
36+@pytest.mark.skip(reason="More basic-testse are needed")
37+def test_more(): pass
diff -r 5a48482b6d4b -r 5ff5f113ebfe pytst/writers/CC2Cpy/test_3b_CompInterface.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pytst/writers/CC2Cpy/test_3b_CompInterface.py Sun Jan 29 22:53:49 2023 +0100
@@ -0,0 +1,14 @@
1+# (C) Albert Mietus, 2022, 2023. Part of Castle/CCastle project
2+
3+import logging; logger = logging.getLogger(__name__)
4+import pytest
5+from . import * # CCompare
6+
7+from castle.writers.CC2Cpy.Component import * # CC_B_ComponentInterface
8+
9+
10+
11+
12+
13+@pytest.mark.skip(reason="More CompInterface-tests are needed")
14+def test_more(): pass
diff -r 5a48482b6d4b -r 5ff5f113ebfe pytst/writers/CC2Cpy/test_3c_CompClass.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pytst/writers/CC2Cpy/test_3c_CompClass.py Sun Jan 29 22:53:49 2023 +0100
@@ -0,0 +1,14 @@
1+# (C) Albert Mietus, 2022, 2023. Part of Castle/CCastle project
2+
3+import logging; logger = logging.getLogger(__name__)
4+import pytest
5+from . import * # CCompare
6+
7+from castle.writers.CC2Cpy.Component import * # CC_B_ComponentClass
8+
9+
10+
11+
12+
13+@pytest.mark.skip(reason="More CompClass-tests are needed")
14+def test_more(): pass
diff -r 5a48482b6d4b -r 5ff5f113ebfe pytst/writers/CC2Cpy/test_3d_CompStruct.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pytst/writers/CC2Cpy/test_3d_CompStruct.py Sun Jan 29 22:53:49 2023 +0100
@@ -0,0 +1,14 @@
1+# (C) Albert Mietus, 2022, 2023. Part of Castle/CCastle project
2+
3+import logging; logger = logging.getLogger(__name__)
4+import pytest
5+from . import * # CCompare
6+
7+from castle.writers.CC2Cpy.Component import *
8+
9+
10+
11+
12+
13+@pytest.mark.skip(reason="More CompStruct-tests are needed")
14+def test_more(): pass