Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2
Revisão | 8e783da5dab406b5190f8be2618d001491965a13 (tree) |
---|---|
Hora | 2023-02-13 07:23:54 |
Autor | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
(asis) fstring is gone; it just a str(ing)
@@ -92,6 +92,9 @@ | ||
92 | 92 | XXX: |
93 | 93 | grep XXX `find . -type f -name \*.py` |
94 | 94 | |
95 | +WC: | |
96 | + wc -l `find . -type f -name \*.py` | |
97 | + | |
95 | 98 | |
96 | 99 | PYREVERSE_DIR=pyreversed/ |
97 | 100 | PYREVERSE_FORMAT=svg |
@@ -1,16 +1,77 @@ | ||
1 | 1 | # (C) Albert Mietus, 2022, 2023. Part of Castle/CCastle project |
2 | 2 | |
3 | + | |
3 | 4 | from typing import TypeAlias, ClassVar, Optional |
4 | 5 | from dataclasses import dataclass, field as dc_field, KW_ONLY |
5 | 6 | from collections.abc import Sequence # Use for typing |
6 | 7 | |
8 | +from castle.auxiliary.abcd import ABCD | |
7 | 9 | |
8 | -fstring: TypeAlias=str # a Fix (sized) string. May be inplemented as a C-string, a Pascal-string, or ... | |
10 | +from enum import Enum | |
11 | + | |
9 | 12 | |
10 | 13 | class CC_Base: pass |
11 | 14 | |
12 | 15 | @dataclass |
13 | 16 | class CC_TypedParameter(CC_Base): |
14 | 17 | """This is many a helper class/struct to combine a parameter: a name and an type""" |
15 | - name: fstring | |
18 | + name: str | |
16 | 19 | type: type |
20 | + | |
21 | +class CC_PortDirection(Enum): | |
22 | + CC_B_PortDirectionIs_UNKNOWN = Unknown = 0 | |
23 | + CC_B_PortDirectionIs_in = In = 1 | |
24 | + CC_B_PortDirectionIs_out = Out = 2 | |
25 | + CC_B_PortDirectionIs_bidirect = BiDir = 3 # Not supported yet | |
26 | + CC_B_PortDirectionIs_master = Master = 4 # Not supported yet | |
27 | + CC_B_PortDirectionIs_slave = Slave = 5 # Not supported yet | |
28 | + | |
29 | + def portray_name(self): ### CC_B_PortDirectionIs_{self.name}' | |
30 | + return f'{self.name}' | |
31 | + | |
32 | +@dataclass | |
33 | +class CC_Port(CC_Base): | |
34 | + name: str | |
35 | + _ : KW_ONLY | |
36 | + direction: CC_PortDirection = CC_PortDirection.Unknown | |
37 | + type: type | |
38 | + | |
39 | + def portray_name(self) ->str: ### <port name> | |
40 | + return f'{self.name}' | |
41 | + | |
42 | + def portray_typePtr(self) ->str: ### <port type> e.g a protocol | |
43 | + if isinstance(self.type, CC_Base): | |
44 | + return f'&{self.type.portray_name()}' | |
45 | + elif self.type is None: | |
46 | + return "NULL" | |
47 | + else: | |
48 | + from warnings import warn | |
49 | + tn = self.type if isinstance(self.type, str) else self.type.__name__ | |
50 | + warn(f"Using string (or other non CC_Base types) port.types (for >>{tn}<<) is not wise", DeprecationWarning, stacklevel=2) | |
51 | + return f'&cc_P_{tn}' | |
52 | + | |
53 | + | |
54 | + | |
55 | +@dataclass | |
56 | +class CC_Function(ABCD, CC_Base): # ABC | |
57 | + name: str | |
58 | + _ : KW_ONLY | |
59 | + type: type # the return type of the callable | |
60 | + body=None; # XXX Add the (AST of the) body LATER | |
61 | + | |
62 | + | |
63 | +@dataclass | |
64 | +class CC_Handler(CC_Function): # ABC Can be an event of data/stream -- with or without paramters | |
65 | + _ : KW_ONLY | |
66 | + portID: CC_Port | |
67 | + | |
68 | +@dataclass | |
69 | +class CC_EventHandler(CC_Handler): | |
70 | + _ : KW_ONLY | |
71 | + parameterTuple: "ToBeDone" | |
72 | + | |
73 | +@dataclass | |
74 | +class CC_Method(CC_Function): pass | |
75 | +class CC_ClassMethod(CC_Method): pass | |
76 | +class CC_ElementMethod(CC_Method): pass #Or CC InstanceMethod?? | |
77 | + |
@@ -2,46 +2,12 @@ | ||
2 | 2 | |
3 | 3 | __all__ = ['CC_B_ComponentInterface', 'CC_Port', 'CC_PortDirection', 'CC_B_ComponentClass'] |
4 | 4 | |
5 | -from enum import Enum | |
6 | 5 | |
7 | 6 | from .CCbase import * |
8 | 7 | from castle.auxiliary.pack import mk_tuple |
9 | -from castle.auxiliary.abcd import ABCD | |
10 | 8 | |
11 | 9 | CC_Component: TypeAlias = 'CC_Component' # Forward ref # pragma: no mutate |
12 | 10 | |
13 | -class CC_PortDirection(Enum): | |
14 | - CC_B_PortDirectionIs_UNKNOWN = Unknown = 0 | |
15 | - CC_B_PortDirectionIs_in = In = 1 | |
16 | - CC_B_PortDirectionIs_out = Out = 2 | |
17 | - CC_B_PortDirectionIs_bidirect = BiDir = 3 # Not supported yet | |
18 | - CC_B_PortDirectionIs_master = Master = 4 # Not supported yet | |
19 | - CC_B_PortDirectionIs_slave = Slave = 5 # Not supported yet | |
20 | - | |
21 | - def portray_name(self): ### CC_B_PortDirectionIs_{self.name}' | |
22 | - return f'{self.name}' | |
23 | - | |
24 | -@dataclass | |
25 | -class CC_Port(CC_Base): | |
26 | - name: str | |
27 | - _ : KW_ONLY | |
28 | - direction: CC_PortDirection = CC_PortDirection.Unknown | |
29 | - type: type | |
30 | - | |
31 | - def portray_name(self) ->str: ### <port name> | |
32 | - return f'{self.name}' | |
33 | - | |
34 | - def portray_typePtr(self) ->str: ### <port type> e.g a protocol | |
35 | - if isinstance(self.type, CC_Base): | |
36 | - return f'&{self.type.portray_name()}' | |
37 | - elif self.type is None: | |
38 | - return "NULL" | |
39 | - else: | |
40 | - from warnings import warn | |
41 | - tn = self.type if isinstance(self.type, str) else self.type.__name__ | |
42 | - warn(f"Using string (or other non CC_Base types) port.types (for >>{tn}<<) is not wise", DeprecationWarning, stacklevel=2) | |
43 | - return f'&cc_P_{tn}' | |
44 | - | |
45 | 11 | |
46 | 12 | @dataclass |
47 | 13 | class CC_B_ComponentInterface(CC_Base): |
@@ -95,31 +61,6 @@ | ||
95 | 61 | |
96 | 62 | |
97 | 63 | |
98 | - | |
99 | -@dataclass | |
100 | -class CC_Function(ABCD, CC_Base): # ABC | |
101 | - name: str | |
102 | - _ : KW_ONLY | |
103 | - type: type # the return type of the callable | |
104 | - body=None; # XXX Add the (AST of the) body LATER | |
105 | - | |
106 | - | |
107 | -@dataclass | |
108 | -class CC_Handler(CC_Function): # ABC Can be an event of data/stream -- with or without paramters | |
109 | - _ : KW_ONLY | |
110 | - portID: CC_Port | |
111 | - | |
112 | -@dataclass | |
113 | -class CC_EventHandler(CC_Handler): | |
114 | - _ : KW_ONLY | |
115 | - parameterTuple: "ToBeDone" | |
116 | - | |
117 | -@dataclass | |
118 | -class CC_Method(CC_Function): pass | |
119 | -class CC_ClassMethod(CC_Method): pass | |
120 | -class CC_ElementMethod(CC_Method): pass #Or CC InstanceMethod?? | |
121 | - | |
122 | - | |
123 | 64 | @dataclass |
124 | 65 | class CC_B_ComponentClass(CC_Base): |
125 | 66 | metaclass="NULL" # //NULL for now, later: meta-class |
@@ -10,7 +10,7 @@ | ||
10 | 10 | |
11 | 11 | It has a name, a return-type (can be void), and a sequence of typed parameters.""" |
12 | 12 | |
13 | - name: fstring | |
13 | + name: str | |
14 | 14 | _: KW_ONLY # The field below must be passed as keywords, when initialising |
15 | 15 | return_type: type=None |
16 | 16 | typedParameters: Sequence[CC_TypedParameter]=() ## A tuple `()` is inmutable |
@@ -34,7 +34,7 @@ | ||
34 | 34 | """ |
35 | 35 | _BASE: ClassVar=None # pragma: no mutate |
36 | 36 | |
37 | - name: fstring | |
37 | + name: str | |
38 | 38 | kind: CC_ProtocolKind |
39 | 39 | based_on: Optional[CC_B_Protocol]=dc_field(default_factory= lambda :CC_B_Protocol._BASE) |
40 | 40 |
@@ -30,5 +30,3 @@ | ||
30 | 30 | """Test some trivial (type-hints) types; mostly by just using them""" |
31 | 31 | |
32 | 32 | assert CC_TypedParameter('test', int).type is int |
33 | - assert fstring is str | |
34 | - assert fstring("foo") == "foo" |