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.
11 lines
182 B
C
11 lines
182 B
C
#ifndef CODEGEN_H
|
|
#define CODEGEN_H
|
|
|
|
#include "analysis.h"
|
|
#include <stdio.h>
|
|
|
|
/* Generate C source from the analyzed program */
|
|
void codegen_emit(FILE *out, analysis_t *a);
|
|
|
|
#endif
|