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.
Files changed (117) hide show
  1. opencrbasic/__init__.py +3 -0
  2. opencrbasic/__main__.py +5 -0
  3. opencrbasic/analysis.py +184 -0
  4. opencrbasic/bindings.py +1034 -0
  5. opencrbasic/catalog.py +173 -0
  6. opencrbasic/checkconfig.py +144 -0
  7. opencrbasic/checker/__init__.py +977 -0
  8. opencrbasic/checker/cr3xx.py +3118 -0
  9. opencrbasic/checker/ess.py +81 -0
  10. opencrbasic/checker/expressions.py +3581 -0
  11. opencrbasic/checker/instr_data.py +1802 -0
  12. opencrbasic/checker/instr_measure.py +1547 -0
  13. opencrbasic/checker/instr_rules.py +3540 -0
  14. opencrbasic/checker/instructions.py +17 -0
  15. opencrbasic/checker/intervals.py +678 -0
  16. opencrbasic/checker/longconv.py +133 -0
  17. opencrbasic/checker/scan_time.py +580 -0
  18. opencrbasic/checker/storage.py +456 -0
  19. opencrbasic/checker/structs.py +240 -0
  20. opencrbasic/checker/structure.py +6213 -0
  21. opencrbasic/checker/symbols.py +609 -0
  22. opencrbasic/checker/terminals.py +249 -0
  23. opencrbasic/checker/unused.py +186 -0
  24. opencrbasic/checker/var_types.py +564 -0
  25. opencrbasic/checker/warnings.py +661 -0
  26. opencrbasic/checks.py +491 -0
  27. opencrbasic/cli.py +391 -0
  28. opencrbasic/commands.py +128 -0
  29. opencrbasic/compiler.py +320 -0
  30. opencrbasic/consteval.py +327 -0
  31. opencrbasic/data/background_calibration.json +4 -0
  32. opencrbasic/data/before_beginprog.json +99 -0
  33. opencrbasic/data/cr1000x/background_calibration.json +4 -0
  34. opencrbasic/data/cr1000x/before_beginprog.json +138 -0
  35. opencrbasic/data/cr1000x/ess_variables.json +1087 -0
  36. opencrbasic/data/cr1000x/fnotch.json +29 -0
  37. opencrbasic/data/cr1000x/functions.json +1337 -0
  38. opencrbasic/data/cr1000x/instructions.json +4836 -0
  39. opencrbasic/data/cr1000x/measure.json +121 -0
  40. opencrbasic/data/cr1000x/mode.json +111 -0
  41. opencrbasic/data/cr1000x/pipeline_tasks.json +88 -0
  42. opencrbasic/data/cr1000x/settings_fields.json +321 -0
  43. opencrbasic/data/cr1000x/status_members.json +318 -0
  44. opencrbasic/data/cr1000x/symbols.json +872 -0
  45. opencrbasic/data/cr1000x/terminals.json +225 -0
  46. opencrbasic/data/cr300/before_beginprog.json +42 -0
  47. opencrbasic/data/cr300/ess_variables.json +1087 -0
  48. opencrbasic/data/cr300/fnotch.json +22 -0
  49. opencrbasic/data/cr300/functions.json +1261 -0
  50. opencrbasic/data/cr300/instructions.json +2837 -0
  51. opencrbasic/data/cr300/measure.json +33 -0
  52. opencrbasic/data/cr300/mode.json +121 -0
  53. opencrbasic/data/cr300/settings_fields.json +259 -0
  54. opencrbasic/data/cr300/status_members.json +303 -0
  55. opencrbasic/data/cr300/symbols.json +584 -0
  56. opencrbasic/data/cr300/terminals.json +193 -0
  57. opencrbasic/data/cr350/before_beginprog.json +44 -0
  58. opencrbasic/data/cr350/ess_variables.json +1087 -0
  59. opencrbasic/data/cr350/fnotch.json +22 -0
  60. opencrbasic/data/cr350/functions.json +1262 -0
  61. opencrbasic/data/cr350/instructions.json +2848 -0
  62. opencrbasic/data/cr350/measure.json +35 -0
  63. opencrbasic/data/cr350/mode.json +121 -0
  64. opencrbasic/data/cr350/settings_fields.json +292 -0
  65. opencrbasic/data/cr350/status_members.json +303 -0
  66. opencrbasic/data/cr350/symbols.json +572 -0
  67. opencrbasic/data/cr350/terminals.json +190 -0
  68. opencrbasic/data/ess_variables.json +1087 -0
  69. opencrbasic/data/fnotch.json +34 -0
  70. opencrbasic/data/functions.json +1337 -0
  71. opencrbasic/data/instructions.json +4965 -0
  72. opencrbasic/data/measure.json +123 -0
  73. opencrbasic/data/mode.json +121 -0
  74. opencrbasic/data/notices_cr6.json +890 -0
  75. opencrbasic/data/pipeline_tasks.json +84 -0
  76. opencrbasic/data/settings_fields.json +322 -0
  77. opencrbasic/data/status_members.json +319 -0
  78. opencrbasic/data/status_table.json +684 -0
  79. opencrbasic/data/symbols.json +902 -0
  80. opencrbasic/data/terminals.json +195 -0
  81. opencrbasic/data/type_codes.json +249 -0
  82. opencrbasic/diagnostics.py +196 -0
  83. opencrbasic/editing.py +827 -0
  84. opencrbasic/formatting.py +310 -0
  85. opencrbasic/helpdocs.py +677 -0
  86. opencrbasic/hover.py +667 -0
  87. opencrbasic/inlay.py +169 -0
  88. opencrbasic/lexer.py +183 -0
  89. opencrbasic/lsp/__init__.py +5 -0
  90. opencrbasic/lsp/__main__.py +7 -0
  91. opencrbasic/lsp/config.py +202 -0
  92. opencrbasic/lsp/features.py +602 -0
  93. opencrbasic/lsp/server.py +741 -0
  94. opencrbasic/lsp/session.py +1189 -0
  95. opencrbasic/lsp/worker.py +128 -0
  96. opencrbasic/mode.py +143 -0
  97. opencrbasic/navigation.py +401 -0
  98. opencrbasic/parser.py +3264 -0
  99. opencrbasic/positions.py +274 -0
  100. opencrbasic/preprocess.py +269 -0
  101. opencrbasic/profiles.py +266 -0
  102. opencrbasic/provenance.py +17 -0
  103. opencrbasic/quickfix.py +331 -0
  104. opencrbasic/rename.py +662 -0
  105. opencrbasic/signature.py +33 -0
  106. opencrbasic/source.py +600 -0
  107. opencrbasic/sources.py +125 -0
  108. opencrbasic/syntax.py +337 -0
  109. opencrbasic/tables.py +2173 -0
  110. opencrbasic/tables_hook.py +14 -0
  111. opencrbasic/tdf.py +142 -0
  112. opencrbasic/timing.py +565 -0
  113. opencrbasic-1.0.0.dist-info/METADATA +223 -0
  114. opencrbasic-1.0.0.dist-info/RECORD +117 -0
  115. opencrbasic-1.0.0.dist-info/WHEEL +4 -0
  116. opencrbasic-1.0.0.dist-info/entry_points.txt +3 -0
  117. opencrbasic-1.0.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,81 @@
1
+ """`ESSVariables` against variables the program declared itself (pass 2, all four loggers).
2
+
3
+ The real compiler walks its ESS table (`data/**/ess_variables.json`, `tools/extract_tables.py`) at
4
+ each `ESSVariables` statement. A name not yet declared is declared there; one already declared is
5
+ checked, every failing entry reported at that line in table order (oracle, 2026-10-01, decompiled
6
+ CR6 `DAT_005fd008` loop):
7
+
8
+ - `ESS variable %s must be declared as String` / `... as Long` when the type differs;
9
+ - `ESS variable of type string must be of size 255` for a string not declared `* 255`;
10
+ - `ESS variable %s must be dimensioned as %d` when the element count differs (a `LONG_ARRAY16`
11
+ entry is declared `count x 16`, so a second `ESSVariables` reports each of them).
12
+ """
13
+
14
+ import json
15
+ from functools import cache
16
+ from pathlib import Path
17
+
18
+ from .. import consteval
19
+ from .. import syntax as S
20
+ from ..diagnostics import Diagnostics
21
+
22
+
23
+ @cache
24
+ def _table(data_dir: str) -> tuple[dict, ...]:
25
+ path = Path(data_dir) / "ess_variables.json"
26
+ return tuple(json.loads(path.read_text())) if path.exists() else ()
27
+
28
+
29
+ def _const_int(expr: S.Expr | None, env: consteval.Env) -> int | None:
30
+ if expr is None or not consteval.is_constant(expr, env):
31
+ return None
32
+ try:
33
+ value = consteval.value_of(expr, env)
34
+ except consteval.NotConstant:
35
+ return None
36
+ if (
37
+ not isinstance(value, (int, float))
38
+ or isinstance(value, bool)
39
+ or value != value
40
+ or value in (float("inf"), float("-inf"))
41
+ ):
42
+ return None # (`String * 1e999`: no implementation exception, round 29)
43
+ return int(value)
44
+
45
+
46
+ def check(program: S.Program, profile, diags: Diagnostics, env: consteval.Env) -> None:
47
+ table = _table(str(profile.data_dir))
48
+ if not table:
49
+ return
50
+ declared: dict[str, tuple[str, str, int | None, int | None]] = {}
51
+ for stmt in program.statements:
52
+ if isinstance(stmt, S.Declaration) and stmt.kind in ("PUBLIC", "DIM", "STATIC"):
53
+ for v in stmt.vars:
54
+ total: int | None = 1
55
+ for d in v.dims:
56
+ n = _const_int(d, env)
57
+ total = None if n is None or total is None else total * n
58
+ kind = (v.type or "FLOAT").upper()
59
+ size = _const_int(v.string_size, env) if v.string_size is not None else 24
60
+ declared.setdefault(v.name.upper(), (v.name, kind, total, size))
61
+ continue
62
+ if not (isinstance(stmt, S.Instruction) and stmt.keyword.upper() == "ESSVARIABLES"):
63
+ continue
64
+ for row in table:
65
+ if not row["count"]:
66
+ continue
67
+ required = "STRING" if row["type"] == "STRING" else "LONG"
68
+ have = declared.get(row["name"].upper())
69
+ if have is None:
70
+ total = row["count"] * (16 if row["type"] == "LONG_ARRAY16" else 1)
71
+ declared[row["name"].upper()] = (row["name"], required, total, 255)
72
+ continue
73
+ spelling, kind, total, size = have
74
+ if kind != required:
75
+ diags.error(
76
+ stmt.line, f"ESS variable {spelling} must be declared as {required.capitalize()}", stmt.file
77
+ )
78
+ elif required == "STRING" and size is not None and size != 255:
79
+ diags.error(stmt.line, "ESS variable of type string must be of size 255", stmt.file)
80
+ elif total is not None and total != row["count"]:
81
+ diags.error(stmt.line, f"ESS variable {spelling} must be dimensioned as {row['count']}", stmt.file)