fprime-gds 4.0.0a8__py3-none-any.whl → 4.0.0a10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fprime_gds/common/fpy/README.md +56 -0
- fprime_gds/common/fpy/SPEC.md +69 -0
- fprime_gds/common/fpy/bytecode/__init__.py +0 -0
- fprime_gds/common/fpy/bytecode/directives.py +490 -0
- fprime_gds/common/fpy/codegen.py +1687 -0
- fprime_gds/common/fpy/grammar.lark +88 -0
- fprime_gds/common/fpy/main.py +40 -0
- fprime_gds/common/fpy/parser.py +239 -0
- fprime_gds/common/templates/cmd_template.py +8 -0
- fprime_gds/executables/cli.py +31 -16
- fprime_gds/executables/data_product_writer.py +66 -30
- {fprime_gds-4.0.0a8.dist-info → fprime_gds-4.0.0a10.dist-info}/METADATA +2 -1
- {fprime_gds-4.0.0a8.dist-info → fprime_gds-4.0.0a10.dist-info}/RECORD +18 -12
- {fprime_gds-4.0.0a8.dist-info → fprime_gds-4.0.0a10.dist-info}/entry_points.txt +1 -1
- fprime_gds/common/fpy/serialize_bytecode.py +0 -229
- fprime_gds/common/fpy/types.py +0 -203
- {fprime_gds-4.0.0a8.dist-info → fprime_gds-4.0.0a10.dist-info}/WHEEL +0 -0
- {fprime_gds-4.0.0a8.dist-info → fprime_gds-4.0.0a10.dist-info}/licenses/LICENSE.txt +0 -0
- {fprime_gds-4.0.0a8.dist-info → fprime_gds-4.0.0a10.dist-info}/licenses/NOTICE.txt +0 -0
- {fprime_gds-4.0.0a8.dist-info → fprime_gds-4.0.0a10.dist-info}/top_level.txt +0 -0
fprime_gds/common/fpy/types.py
DELETED
@@ -1,203 +0,0 @@
|
|
1
|
-
from __future__ import annotations
|
2
|
-
from dataclasses import dataclass, field
|
3
|
-
from enum import Enum
|
4
|
-
import struct
|
5
|
-
from typing import Any, Callable
|
6
|
-
from fprime.common.models.serialize.type_base import BaseType, ValueType
|
7
|
-
from fprime.common.models.serialize.time_type import TimeType
|
8
|
-
from fprime.common.models.serialize.numerical_types import U32Type, U16Type, U8Type
|
9
|
-
from fprime.common.models.serialize.string_type import StringType
|
10
|
-
|
11
|
-
from fprime_gds.common.loaders.json_loader import PRIMITIVE_TYPE_MAP
|
12
|
-
from fprime_gds.common.templates.ch_template import ChTemplate
|
13
|
-
from fprime_gds.common.templates.prm_template import PrmTemplate
|
14
|
-
|
15
|
-
|
16
|
-
def get_type_obj_for(type: str) -> type[ValueType]:
|
17
|
-
if type == "FwOpcodeType":
|
18
|
-
return U32Type
|
19
|
-
elif type == "FwSizeStoreType":
|
20
|
-
return U16Type
|
21
|
-
elif type == "FwChanIdType":
|
22
|
-
return U32Type
|
23
|
-
elif type == "FwPrmIdType":
|
24
|
-
return U32Type
|
25
|
-
|
26
|
-
raise RuntimeError("Unknown FPrime type alias " + str(type))
|
27
|
-
|
28
|
-
|
29
|
-
class StatementType(Enum):
|
30
|
-
DIRECTIVE = 0
|
31
|
-
CMD = 1
|
32
|
-
|
33
|
-
|
34
|
-
@dataclass
|
35
|
-
class StatementTemplate:
|
36
|
-
"""a statement with unspecified argument values"""
|
37
|
-
|
38
|
-
statement_type: StatementType
|
39
|
-
opcode: int
|
40
|
-
name: str
|
41
|
-
"""fully qualified statement name"""
|
42
|
-
args: list[type[BaseType] | Callable[[Any, BytecodeParseContext], BaseType]]
|
43
|
-
"""list of argument types of this statement, or functions that return an arg type"""
|
44
|
-
|
45
|
-
|
46
|
-
@dataclass
|
47
|
-
class StatementData:
|
48
|
-
template: StatementTemplate
|
49
|
-
arg_values: list[BaseType]
|
50
|
-
|
51
|
-
|
52
|
-
HEADER_FORMAT = "!BBBBBHI"
|
53
|
-
HEADER_SIZE = struct.calcsize(HEADER_FORMAT)
|
54
|
-
|
55
|
-
|
56
|
-
@dataclass
|
57
|
-
class Header:
|
58
|
-
majorVersion: int
|
59
|
-
minorVersion: int
|
60
|
-
patchVersion: int
|
61
|
-
schemaVersion: int
|
62
|
-
argumentCount: int
|
63
|
-
statementCount: int
|
64
|
-
bodySize: int
|
65
|
-
|
66
|
-
|
67
|
-
FOOTER_FORMAT = "!I"
|
68
|
-
FOOTER_SIZE = struct.calcsize(FOOTER_FORMAT)
|
69
|
-
|
70
|
-
|
71
|
-
@dataclass
|
72
|
-
class Footer:
|
73
|
-
crc: int
|
74
|
-
|
75
|
-
|
76
|
-
class DirectiveOpcode(Enum):
|
77
|
-
INVALID = 0x00000000
|
78
|
-
WAIT_REL = 0x00000001
|
79
|
-
WAIT_ABS = 0x00000002
|
80
|
-
SET_LVAR = 0x00000003
|
81
|
-
GOTO = 0x00000004
|
82
|
-
IF = 0x00000005
|
83
|
-
NO_OP = 0x00000006
|
84
|
-
GET_TLM = 0x00000007
|
85
|
-
GET_PRM = 0x00000008
|
86
|
-
|
87
|
-
|
88
|
-
@dataclass
|
89
|
-
class BytecodeParseContext:
|
90
|
-
goto_tags: map[str, int] = field(default_factory=dict)
|
91
|
-
"""a map of tag name with tag statement index"""
|
92
|
-
types: map[str, type[BaseType]] = field(default_factory=dict)
|
93
|
-
"""a map of name to all parsed types available in the dictionary"""
|
94
|
-
channels: map[str, ChTemplate] = field(default_factory=dict)
|
95
|
-
"""a map of name to ChTemplate object for all tlm channels"""
|
96
|
-
params: map[str, PrmTemplate] = field(default_factory=dict)
|
97
|
-
"""a map of name to PrmTemplate object for all prms"""
|
98
|
-
|
99
|
-
|
100
|
-
def time_type_from_json(js, ctx: BytecodeParseContext):
|
101
|
-
return TimeType(js["time_base"], js["time_context"], js["seconds"], js["useconds"])
|
102
|
-
|
103
|
-
|
104
|
-
def arbitrary_type_from_json(js, ctx: BytecodeParseContext):
|
105
|
-
type_name = js["type"]
|
106
|
-
|
107
|
-
if type_name == "string":
|
108
|
-
# by default no max size restrictions in the bytecode
|
109
|
-
return StringType.construct_type(f"String", None)(js["value"])
|
110
|
-
|
111
|
-
# try first checking parsed_types, then check primitive types
|
112
|
-
type_class = ctx.types.get(type_name, PRIMITIVE_TYPE_MAP.get(type_name, None))
|
113
|
-
if type_class is None:
|
114
|
-
raise RuntimeError("Unknown type " + str(type_name))
|
115
|
-
|
116
|
-
return type_class(js["value"])
|
117
|
-
|
118
|
-
|
119
|
-
def goto_tag_or_idx_from_json(js, ctx: BytecodeParseContext):
|
120
|
-
if isinstance(js, str):
|
121
|
-
# it's a tag
|
122
|
-
if js not in ctx.goto_tags:
|
123
|
-
raise RuntimeError("Unknown goto tag " + str(js))
|
124
|
-
return U32Type(ctx.goto_tags[js])
|
125
|
-
|
126
|
-
# otherwise it is a statement index
|
127
|
-
return U32Type(js)
|
128
|
-
|
129
|
-
|
130
|
-
def tlm_chan_id_from_json(js, ctx: BytecodeParseContext):
|
131
|
-
if isinstance(js, str):
|
132
|
-
if js not in ctx.channels:
|
133
|
-
raise RuntimeError("Unknown telemetry channel " + str(js))
|
134
|
-
return get_type_obj_for("FwChanIdType")(ctx.channels[js].id)
|
135
|
-
elif isinstance(js, int):
|
136
|
-
matching = [tmp for tmp in ctx.channels.keys() if tmp.id == js]
|
137
|
-
if len(matching) != 1:
|
138
|
-
if len(matching) == 0:
|
139
|
-
raise RuntimeError("Unknown telemetry channel id " + str(js))
|
140
|
-
raise RuntimeError("Multiple matches for telemetry channel id " + str(js))
|
141
|
-
matching = matching[0]
|
142
|
-
return get_type_obj_for("FwChanIdType")(matching.id)
|
143
|
-
|
144
|
-
|
145
|
-
def prm_id_from_json(js, ctx: BytecodeParseContext):
|
146
|
-
if isinstance(js, str):
|
147
|
-
if js not in ctx.params:
|
148
|
-
raise RuntimeError("Unknown parameter " + str(js))
|
149
|
-
return get_type_obj_for("FwPrmIdType")(ctx.params[js].prm_id)
|
150
|
-
elif isinstance(js, int):
|
151
|
-
matching = [tmp for tmp in ctx.params.keys() if tmp.prm_id == js]
|
152
|
-
if len(matching) != 1:
|
153
|
-
if len(matching) == 0:
|
154
|
-
raise RuntimeError("Unknown param id " + str(js))
|
155
|
-
raise RuntimeError("Multiple matches for param id " + str(js))
|
156
|
-
matching = matching[0]
|
157
|
-
return get_type_obj_for("FwPrmIdType")(matching.prm_id)
|
158
|
-
|
159
|
-
|
160
|
-
FPY_DIRECTIVES: list[StatementTemplate] = [
|
161
|
-
StatementTemplate(
|
162
|
-
StatementType.DIRECTIVE,
|
163
|
-
DirectiveOpcode.WAIT_REL.value,
|
164
|
-
"WAIT_REL",
|
165
|
-
[U32Type, U32Type],
|
166
|
-
),
|
167
|
-
StatementTemplate(
|
168
|
-
StatementType.DIRECTIVE,
|
169
|
-
DirectiveOpcode.WAIT_ABS.value,
|
170
|
-
"WAIT_ABS",
|
171
|
-
[time_type_from_json],
|
172
|
-
),
|
173
|
-
StatementTemplate(
|
174
|
-
StatementType.DIRECTIVE,
|
175
|
-
DirectiveOpcode.SET_LVAR.value,
|
176
|
-
"SET_LVAR",
|
177
|
-
[U8Type, arbitrary_type_from_json],
|
178
|
-
),
|
179
|
-
StatementTemplate(
|
180
|
-
StatementType.DIRECTIVE,
|
181
|
-
DirectiveOpcode.GOTO.value,
|
182
|
-
"GOTO",
|
183
|
-
[goto_tag_or_idx_from_json],
|
184
|
-
),
|
185
|
-
StatementTemplate(
|
186
|
-
StatementType.DIRECTIVE,
|
187
|
-
DirectiveOpcode.IF.value,
|
188
|
-
"IF",
|
189
|
-
[U8Type, goto_tag_or_idx_from_json],
|
190
|
-
),
|
191
|
-
StatementTemplate(
|
192
|
-
StatementType.DIRECTIVE,
|
193
|
-
DirectiveOpcode.GET_TLM.value,
|
194
|
-
"GET_TLM",
|
195
|
-
[U8Type, U8Type, tlm_chan_id_from_json],
|
196
|
-
),
|
197
|
-
StatementTemplate(
|
198
|
-
StatementType.DIRECTIVE,
|
199
|
-
DirectiveOpcode.GET_PRM.value,
|
200
|
-
"GET_PRM",
|
201
|
-
[U8Type, prm_id_from_json],
|
202
|
-
),
|
203
|
-
]
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|