• R/O
  • SSH

Commit

Tags
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

Revision80e84a4d4dce9b2f1eb6f508be8882d341445552 (tree)
Time2023-09-23 19:18:07
AuthorAlbert Mietus < albert AT mietus DOT nl >
CommiterAlbert Mietus < albert AT mietus DOT nl >

Log Message

More aigr groundwork

Change Summary

Incremental Difference

diff -r 6a4855765d41 -r 80e84a4d4dce Makefile
--- a/Makefile Sat Sep 23 11:54:36 2023 +0200
+++ b/Makefile Sat Sep 23 12:18:07 2023 +0200
@@ -9,9 +9,10 @@
99 # TODO: Some test that are needed soon
1010 rPY_LAST = \
1111 pytst/writers/RPy/test_0_templating.py \
12+ pytst/aigr/test_0_AIGR.py \
1213 #
1314 rPY_CURRENT = \
14- pytst/aigr/test_0_AIGR.py \
15+ pytst/aigr/test_1_events.py \
1516 #
1617 CC2CPy_TODO = \
1718 pytst/writers/RPy/test_999.py \
diff -r 6a4855765d41 -r 80e84a4d4dce castle/aigr/__init__.py
--- a/castle/aigr/__init__.py Sat Sep 23 11:54:36 2023 +0200
+++ b/castle/aigr/__init__.py Sat Sep 23 12:18:07 2023 +0200
@@ -8,4 +8,5 @@
88 return super().__new__(cls)
99
1010
11-
11+from .events import *
12+from .protocols import *
diff -r 6a4855765d41 -r 80e84a4d4dce castle/aigr/events.py
--- a/castle/aigr/events.py Sat Sep 23 11:54:36 2023 +0200
+++ b/castle/aigr/events.py Sat Sep 23 12:18:07 2023 +0200
@@ -6,23 +6,24 @@
66 - better
77 TODO: update the CC2Cpy parts to use this generic AIGR layer
88 """
9+
10+import typing as PTH # Python TypeHints
911 from dataclasses import dataclass, KW_ONLY
1012 from . import AIGR
11-from .types import TypedParameter
13+from .types import TypedParameter # Castle/AIGR types
1214
1315 __all__ = ['Event']
1416
15-from dataclasses import dataclass, KW_ONLY
1617
17-from castle.auxiliary import AIGR
1818
19-@dataclass # pragma: no mutate
19+
20+@dataclass # pragma: no mutate
2021 class Event(AIGR):
2122 """An event is like a (remote) function-call
2223
23- It has a name, a return-type (can be void), and a sequence of typed parameters."""
24+ It has a name, a return-type (can be void), and an (inmutable) sequence of typed parameters."""
2425
2526 name: str
26- _: KW_ONLY # The field below must be passed as keywords, when initialising
27+ _: KW_ONLY
2728 return_type: type=None
28- typedParameters: Sequence[TypedParameter]=() ## A tuple `()` is inmutable
29+ typedParameters: PTH.Sequence[TypedParameter]=()
diff -r 6a4855765d41 -r 80e84a4d4dce castle/aigr/protocols.py
--- a/castle/aigr/protocols.py Sat Sep 23 11:54:36 2023 +0200
+++ b/castle/aigr/protocols.py Sat Sep 23 12:18:07 2023 +0200
@@ -7,8 +7,10 @@
77 TODO: update the CC2Cpy parts to use this generic AIGR layer
88 """
99
10+import typing as PTH # Python TypeHints
1011 from enum import Enum
1112 from dataclasses import dataclass, KW_ONLY
13+from dataclasses import field as dc_field
1214 from . import AIGR
1315 from .events import Event
1416
@@ -27,18 +29,18 @@
2729 Stream = 3
2830
2931
30-Protocol: TypeAlias = 'Protocol' # forward reference # pragma: no mutate
32+Protocol: PTH.TypeAlias = 'Protocol' # forward reference # pragma: no mutate
3133 @dataclass
3234 class Protocol(AIGR):
3335 """ .. note:: Use one of the subclasses -- Only Event is defined yet
3436 .. todo:: Design: What is the `kind` self and the inherited ones are not the same?
3537 overriding ProtocolKind.Unknown is always allowed
3638 """
37- _BASE: ClassVar=None # pragma: no mutate
39+ _BASE: PTH.ClassVar=None # pragma: no mutate
3840
3941 name: str
4042 kind: ProtocolKind
41- based_on: Optional[Protocol]=dc_field(default_factory= lambda :Protocol._BASE)
43+ based_on: PTH.Optional[Protocol]=dc_field(default_factory= lambda :Protocol._BASE)
4244
4345
4446 @dataclass
@@ -62,5 +64,5 @@
6264 """
6365 _: KW_ONLY
6466 kind: ProtocolKind = ProtocolKind.Event
65- events: Sequence[Event]
67+ events: PTH.Sequence[Event]
6668
diff -r 6a4855765d41 -r 80e84a4d4dce castle/aigr/types.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/castle/aigr/types.py Sat Sep 23 12:18:07 2023 +0200
@@ -0,0 +1,24 @@
1+# (C) Albert Mietus, 2023. Part of Castle/CCastle project
2+
3+""" This file is based (a fork) on `../writers/CC2Cpy/Protocol.py`,
4+ - the rendering part is removed
5+ - the prefixed are gone
6+ - better
7+TODO: update the CC2Cpy parts to use this generic AIGR layer
8+"""
9+
10+import typing as PTH # Python TypeHints
11+from enum import Enum
12+from dataclasses import dataclass, KW_ONLY
13+from . import AIGR
14+
15+# XXX__all__ = [
16+@dataclass
17+class TypedParameter(AIGR):
18+ """This is many a helper class/struct to combine a parameter: a name and an type"""
19+ name: str
20+ type: type
21+
22+
23+TypedParameterTuple: PTH.TypeAlias = PTH.Sequence[TypedParameter]
24+
diff -r 6a4855765d41 -r 80e84a4d4dce pytst/aigr/test_1_events.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pytst/aigr/test_1_events.py Sat Sep 23 12:18:07 2023 +0200
@@ -0,0 +1,22 @@
1+# (C) Albert Mietus, 2022, 2023. Part of Castle/CCastle project
2+
3+
4+from castle.aigr import Event
5+from castle.aigr.types import TypedParameter
6+
7+def test_0_Event_empty():
8+ e = Event("leeg_event")
9+ assert e.name == 'leeg_event'
10+ assert e.return_type is None
11+ assert len(e.typedParameters) == 0
12+
13+def test_1_Event_small():
14+ e = Event("demo_int", typedParameters=[TypedParameter(name='p1', type=float )])
15+ assert e.return_type is None
16+ assert len(e.typedParameters) == 1
17+ assert e.typedParameters[0].name == 'p1'
18+ assert e.typedParameters[0].type == float
19+
20+def test_2_Event_retunInt():
21+ e = Event("an_event", return_type=int)
22+ assert e.return_type == int