Commit Graph

1 Commits

Author SHA1 Message Date
Eremey Valetov
d3b57d9f3b Implement ahead-of-time compiler (Phase 1): BASIC to C via token stream
New tool gwbasic-compile translates tokenized .bas programs to C source,
which gcc compiles into native executables linked against libgwrt.a (the
interpreter's runtime modules minus the execution loop).

Pipeline: .bas → gw_crunch() → analysis pass (line table, variable census,
GOTO targets, DATA collection) → C codegen → gcc → native executable.

Phase 1 supports: PRINT, LET, IF/THEN/ELSE, GOTO, GOSUB/RETURN, FOR/NEXT,
END/STOP/SYSTEM, REM, DATA/READ/RESTORE, CLS, arithmetic/relational/logical
operators, core math functions (SIN, COS, SQR, ABS, etc.), string functions
(LEFT$, RIGHT$, MID$, CHR$, ASC, VAL, STR$, LEN, etc.), string concatenation.

All control flow uses goto/labels (no C for/while) so GOTO into loops works.
GOSUB uses a return-label stack with switch dispatch.
2026-03-29 06:59:42 -04:00