TS generator: fix #12 (5 expression patterns) + #11 (opaque record types)

#12: All 5 untranslated SpeckDL patterns now emit valid JS:
  - notIn → !.has(), old() → drop, union → Set spread,
    set diff → filter, append() → [...X, Y], length() → .length
  - ==/!= operator replacement fixed (word-boundary regression)
  - Postcondition object comparisons get @ts-expect-error TS2839

#11: Generator auto-detects opaque identifier types used in state
  variables and action params, emits 'type X = any' before class.
  - State properties use ! (non-null assertion) for strict mode

TigerBeetleLedger → tsc --noEmit = 0 errors. 37/37 tests pass.
This commit is contained in:
Scott Scoble 2026-05-11 10:16:15 -07:00
parent 29d4c83d76
commit 8b520284cb
31 changed files with 3934 additions and 973 deletions

30
fix-z3-again.py Normal file
View file

@ -0,0 +1,30 @@
import sys
content = open('compiler/src/generators/z3.ts').read()
lines = content.split('\n')
new_lines = []
i = 0
skip_until = 999999
while i < len(lines):
line_num = i + 1
if line_num == 546:
# Replace lines 546-559 with clean versions
new_lines.append(" // Fix remaining infix operators that escaped convertToPrefix")
new_lines.append(" // word = word/val: convert to (= word val)")
new_lines.append(" e = e.replace(/(\\b\\w+)\\s*=\\s*(\\w+|\\d+|Bool|true|false)\\b/g, '(= $1 $2)');")
new_lines.append(" // (innermost expr) = val: convert to (= (expr) val)")
new_lines.append(" e = e.replace(/\\(([^()]+)\\)\\s*=\\s*(\\w+|\\d+|Bool|true|false)\\b/g, '(= ($1) $2)');")
new_lines.append(" // word <= word: convert to (<= word word)")
new_lines.append(" e = e.replace(/(\\b\\w+)\\s*(<=|>=)\\s*(\\w+|\\d+|Bool|true|false)\\b/g, '($2 $1 $3)');")
new_lines.append(" // (innermost expr) <= val: convert to (<= (expr) val)")
new_lines.append(" e = e.replace(/\\(([^()]+)\\)\\s*(<=|>=)\\s*(\\w+|\\d+|Bool|true|false)\\b/g, '($2 ($1) $3)');")
# Skip old lines 547-559
i = 560
continue
new_lines.append(lines[i])
i += 1
open('compiler/src/generators/z3.ts', 'w').write('\n'.join(new_lines))
print('Done')