opencrbasic 1.0.0__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.
- opencrbasic/__init__.py +3 -0
- opencrbasic/__main__.py +5 -0
- opencrbasic/analysis.py +184 -0
- opencrbasic/bindings.py +1034 -0
- opencrbasic/catalog.py +173 -0
- opencrbasic/checkconfig.py +144 -0
- opencrbasic/checker/__init__.py +977 -0
- opencrbasic/checker/cr3xx.py +3118 -0
- opencrbasic/checker/ess.py +81 -0
- opencrbasic/checker/expressions.py +3581 -0
- opencrbasic/checker/instr_data.py +1802 -0
- opencrbasic/checker/instr_measure.py +1547 -0
- opencrbasic/checker/instr_rules.py +3540 -0
- opencrbasic/checker/instructions.py +17 -0
- opencrbasic/checker/intervals.py +678 -0
- opencrbasic/checker/longconv.py +133 -0
- opencrbasic/checker/scan_time.py +580 -0
- opencrbasic/checker/storage.py +456 -0
- opencrbasic/checker/structs.py +240 -0
- opencrbasic/checker/structure.py +6213 -0
- opencrbasic/checker/symbols.py +609 -0
- opencrbasic/checker/terminals.py +249 -0
- opencrbasic/checker/unused.py +186 -0
- opencrbasic/checker/var_types.py +564 -0
- opencrbasic/checker/warnings.py +661 -0
- opencrbasic/checks.py +491 -0
- opencrbasic/cli.py +391 -0
- opencrbasic/commands.py +128 -0
- opencrbasic/compiler.py +320 -0
- opencrbasic/consteval.py +327 -0
- opencrbasic/data/background_calibration.json +4 -0
- opencrbasic/data/before_beginprog.json +99 -0
- opencrbasic/data/cr1000x/background_calibration.json +4 -0
- opencrbasic/data/cr1000x/before_beginprog.json +138 -0
- opencrbasic/data/cr1000x/ess_variables.json +1087 -0
- opencrbasic/data/cr1000x/fnotch.json +29 -0
- opencrbasic/data/cr1000x/functions.json +1337 -0
- opencrbasic/data/cr1000x/instructions.json +4836 -0
- opencrbasic/data/cr1000x/measure.json +121 -0
- opencrbasic/data/cr1000x/mode.json +111 -0
- opencrbasic/data/cr1000x/pipeline_tasks.json +88 -0
- opencrbasic/data/cr1000x/settings_fields.json +321 -0
- opencrbasic/data/cr1000x/status_members.json +318 -0
- opencrbasic/data/cr1000x/symbols.json +872 -0
- opencrbasic/data/cr1000x/terminals.json +225 -0
- opencrbasic/data/cr300/before_beginprog.json +42 -0
- opencrbasic/data/cr300/ess_variables.json +1087 -0
- opencrbasic/data/cr300/fnotch.json +22 -0
- opencrbasic/data/cr300/functions.json +1261 -0
- opencrbasic/data/cr300/instructions.json +2837 -0
- opencrbasic/data/cr300/measure.json +33 -0
- opencrbasic/data/cr300/mode.json +121 -0
- opencrbasic/data/cr300/settings_fields.json +259 -0
- opencrbasic/data/cr300/status_members.json +303 -0
- opencrbasic/data/cr300/symbols.json +584 -0
- opencrbasic/data/cr300/terminals.json +193 -0
- opencrbasic/data/cr350/before_beginprog.json +44 -0
- opencrbasic/data/cr350/ess_variables.json +1087 -0
- opencrbasic/data/cr350/fnotch.json +22 -0
- opencrbasic/data/cr350/functions.json +1262 -0
- opencrbasic/data/cr350/instructions.json +2848 -0
- opencrbasic/data/cr350/measure.json +35 -0
- opencrbasic/data/cr350/mode.json +121 -0
- opencrbasic/data/cr350/settings_fields.json +292 -0
- opencrbasic/data/cr350/status_members.json +303 -0
- opencrbasic/data/cr350/symbols.json +572 -0
- opencrbasic/data/cr350/terminals.json +190 -0
- opencrbasic/data/ess_variables.json +1087 -0
- opencrbasic/data/fnotch.json +34 -0
- opencrbasic/data/functions.json +1337 -0
- opencrbasic/data/instructions.json +4965 -0
- opencrbasic/data/measure.json +123 -0
- opencrbasic/data/mode.json +121 -0
- opencrbasic/data/notices_cr6.json +890 -0
- opencrbasic/data/pipeline_tasks.json +84 -0
- opencrbasic/data/settings_fields.json +322 -0
- opencrbasic/data/status_members.json +319 -0
- opencrbasic/data/status_table.json +684 -0
- opencrbasic/data/symbols.json +902 -0
- opencrbasic/data/terminals.json +195 -0
- opencrbasic/data/type_codes.json +249 -0
- opencrbasic/diagnostics.py +196 -0
- opencrbasic/editing.py +827 -0
- opencrbasic/formatting.py +310 -0
- opencrbasic/helpdocs.py +677 -0
- opencrbasic/hover.py +667 -0
- opencrbasic/inlay.py +169 -0
- opencrbasic/lexer.py +183 -0
- opencrbasic/lsp/__init__.py +5 -0
- opencrbasic/lsp/__main__.py +7 -0
- opencrbasic/lsp/config.py +202 -0
- opencrbasic/lsp/features.py +602 -0
- opencrbasic/lsp/server.py +741 -0
- opencrbasic/lsp/session.py +1189 -0
- opencrbasic/lsp/worker.py +128 -0
- opencrbasic/mode.py +143 -0
- opencrbasic/navigation.py +401 -0
- opencrbasic/parser.py +3264 -0
- opencrbasic/positions.py +274 -0
- opencrbasic/preprocess.py +269 -0
- opencrbasic/profiles.py +266 -0
- opencrbasic/provenance.py +17 -0
- opencrbasic/quickfix.py +331 -0
- opencrbasic/rename.py +662 -0
- opencrbasic/signature.py +33 -0
- opencrbasic/source.py +600 -0
- opencrbasic/sources.py +125 -0
- opencrbasic/syntax.py +337 -0
- opencrbasic/tables.py +2173 -0
- opencrbasic/tables_hook.py +14 -0
- opencrbasic/tdf.py +142 -0
- opencrbasic/timing.py +565 -0
- opencrbasic-1.0.0.dist-info/METADATA +223 -0
- opencrbasic-1.0.0.dist-info/RECORD +117 -0
- opencrbasic-1.0.0.dist-info/WHEEL +4 -0
- opencrbasic-1.0.0.dist-info/entry_points.txt +3 -0
- opencrbasic-1.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""Constant arguments converted to the compiler's 32-bit `long` (oracle, 2026-10-02,
|
|
2
|
+
`docs/checker.md` "Option arguments"), shared by the `SplitStr`, `IPRoute` and `Matrix` option
|
|
3
|
+
checks.
|
|
4
|
+
|
|
5
|
+
An integer-typed constant expression (integer literals, whole-valued names, `+ - * MOD \\`) wraps
|
|
6
|
+
at 32 bits (`100000*100000` -> 1410065408, `2147483647+1` -> -2147483648). A float-typed one (a
|
|
7
|
+
decimal point or exponent, `/`, `^`, a literal beyond 32 bits, a name declared from one) is
|
|
8
|
+
truncated toward zero. Beyond the 32-bit range a float becomes -2147483648 on CR6/CR1000X; on
|
|
9
|
+
CR300/CR350 a digits-only literal (optionally negated, or a `Const` declared as one) is first rounded to a 32-bit float,
|
|
10
|
+
becoming -2147483648 past +-2^31 and otherwise saturating at +-2147483647 (any other float
|
|
11
|
+
expression gives -2147483648). A string or NAN is -2147483648. Hex literals wrap to 32 bits.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import math
|
|
15
|
+
import struct
|
|
16
|
+
|
|
17
|
+
from .. import consteval
|
|
18
|
+
from .. import syntax as S
|
|
19
|
+
|
|
20
|
+
INT_MIN = -(2**31)
|
|
21
|
+
_OPS = ("+", "-", "*", "/", "^", "\\", "MOD")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def float_names(statements) -> frozenset[str]:
|
|
25
|
+
"""`Const` names whose declaration is float-typed (resolved in declaration order)."""
|
|
26
|
+
names: set[str] = set()
|
|
27
|
+
for st in statements:
|
|
28
|
+
if isinstance(st, S.ConstDecl) and _float_typed(st.value, names):
|
|
29
|
+
names.add(st.name.upper())
|
|
30
|
+
return frozenset(names)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def literal_names(statements) -> frozenset[str]:
|
|
34
|
+
"""`Const` names declared as one digits-only literal (`_integer_literal`)."""
|
|
35
|
+
return frozenset(st.name.upper() for st in statements if isinstance(st, S.ConstDecl) and _integer_literal(st.value))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _float_typed(expr: S.Expr | None, names) -> bool:
|
|
39
|
+
if isinstance(expr, S.Number):
|
|
40
|
+
text = expr.text.upper()
|
|
41
|
+
if text.startswith("&"):
|
|
42
|
+
return False
|
|
43
|
+
return "." in text or "E" in text or not INT_MIN <= expr.value < 2**31
|
|
44
|
+
if isinstance(expr, S.Name):
|
|
45
|
+
return expr.name.upper() in names
|
|
46
|
+
if isinstance(expr, S.Unary):
|
|
47
|
+
return _float_typed(expr.operand, names)
|
|
48
|
+
if isinstance(expr, S.Binary):
|
|
49
|
+
return expr.op in ("/", "^") or _float_typed(expr.left, names) or _float_typed(expr.right, names)
|
|
50
|
+
return False
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _plain(expr: S.Expr | None) -> bool:
|
|
54
|
+
if isinstance(expr, (S.Number, S.Name)):
|
|
55
|
+
return True
|
|
56
|
+
if isinstance(expr, S.Unary):
|
|
57
|
+
return expr.op in ("-", "+") and _plain(expr.operand)
|
|
58
|
+
if isinstance(expr, S.Binary):
|
|
59
|
+
return expr.op in _OPS and _plain(expr.left) and _plain(expr.right)
|
|
60
|
+
return False
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def long_value(arg: S.Expr | None, env: consteval.Env, profile, names=frozenset(), literals=frozenset()) -> int | None:
|
|
64
|
+
"""The 32-bit `long` the compiler makes of constant `arg`, or None when `arg` is missing, not
|
|
65
|
+
constant, or in a form this model does not cover (hex beyond 8 digits, function calls)."""
|
|
66
|
+
if arg is None:
|
|
67
|
+
return None
|
|
68
|
+
if isinstance(arg, S.String):
|
|
69
|
+
return INT_MIN
|
|
70
|
+
if isinstance(arg, S.Name) and arg.name.upper() in ("NAN", "INF") and arg.name.upper() not in env.consts:
|
|
71
|
+
return INT_MIN
|
|
72
|
+
if not _plain(arg):
|
|
73
|
+
return None
|
|
74
|
+
try:
|
|
75
|
+
value = consteval.value_of(arg, env)
|
|
76
|
+
except consteval.NotConstant:
|
|
77
|
+
return None
|
|
78
|
+
if isinstance(value, str):
|
|
79
|
+
return INT_MIN
|
|
80
|
+
if isinstance(value, bool) or not isinstance(value, (int, float)):
|
|
81
|
+
return None
|
|
82
|
+
if isinstance(value, float) and not math.isfinite(value):
|
|
83
|
+
return INT_MIN
|
|
84
|
+
if isinstance(arg, S.Number) and arg.text.startswith("&"):
|
|
85
|
+
if value > 0xFFFFFFFF:
|
|
86
|
+
return None
|
|
87
|
+
return int(value) - 2**32 if value >= 2**31 else int(value)
|
|
88
|
+
if _hex_inside(arg):
|
|
89
|
+
return None
|
|
90
|
+
if not (_float_typed(arg, names) or value != int(value)):
|
|
91
|
+
return _wrap(int(value))
|
|
92
|
+
if INT_MIN < value < 2**31:
|
|
93
|
+
return int(value)
|
|
94
|
+
if profile.name in ("cr300", "cr350") and (
|
|
95
|
+
_integer_literal(arg) or (isinstance(arg, S.Name) and arg.name.upper() in literals)
|
|
96
|
+
):
|
|
97
|
+
return _float32_long(value)
|
|
98
|
+
return INT_MIN
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _integer_literal(expr: S.Expr | None) -> bool:
|
|
102
|
+
"""A digits-only literal, optionally negated: the only form CR300/CR350 saturate (oracle,
|
|
103
|
+
2026-10-03, and the `Const` forms in `tests/fixtures/option_args.json`: `2147483648` -> 2147483647, `-2147483649` -> -2147483647, but `2147483648.0`,
|
|
104
|
+
`2147483648*1.0`, `2^31` and `-2^31` all give -2147483648)."""
|
|
105
|
+
if isinstance(expr, S.Unary) and expr.op == "-":
|
|
106
|
+
expr = expr.operand
|
|
107
|
+
return isinstance(expr, S.Number) and expr.text.isdigit()
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _hex_inside(expr: S.Expr | None) -> bool:
|
|
111
|
+
if isinstance(expr, S.Number):
|
|
112
|
+
return expr.text.startswith("&")
|
|
113
|
+
if isinstance(expr, S.Unary):
|
|
114
|
+
return _hex_inside(expr.operand)
|
|
115
|
+
if isinstance(expr, S.Binary):
|
|
116
|
+
return _hex_inside(expr.left) or _hex_inside(expr.right)
|
|
117
|
+
return False
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _wrap(value: int) -> int:
|
|
121
|
+
value = int(value) & 0xFFFFFFFF
|
|
122
|
+
return value - 2**32 if value >= 2**31 else value
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _float32_long(value: float) -> int:
|
|
126
|
+
f = (
|
|
127
|
+
struct.unpack("<f", struct.pack("<f", float(value)))[0]
|
|
128
|
+
if abs(value) < 3.4e38
|
|
129
|
+
else math.copysign(math.inf, value)
|
|
130
|
+
)
|
|
131
|
+
if not -(2**31) <= f <= 2**31:
|
|
132
|
+
return INT_MIN
|
|
133
|
+
return max(-(2**31) + 1, min(2**31 - 1, int(f)))
|