CHAIN: delegate to runtime interpreter via emit_delegate_stmt with full
variable sync. Runtime loads .bas file, preserves COMMON variables, and
runs it via gw_run_loop(). Compiled code exits after CHAIN returns.
COMMON: delegate to runtime to mark variables for CHAIN preservation.
RUN "file": delegate to runtime interpreter which loads and runs the
file. Compiled code exits after (RUN doesn't return to caller).
67/72 tests pass (93%). Only 2 remain: monte_carlo and number_guess
(RNG seed differences — not bugs).
misc_stmts: fix ERDEV/IOCTL$ PRINT detection (peek past spaces for $
suffix), add IOCTL$() handler in emit_str_atom that consumes (#filenum).
random_access: use emit_delegate_stmt with read_back=true for FIELD/GET/
PUT/LSET/RSET so FIELD variables are synced back after GET.
error_handler: add division-by-zero check in compiled / operator (GCC
statement expression checks divisor==0 → gw_error(11)). Second error now
caught correctly.
get_put: fix CLS to call gfx_cls()+gfx_flush() when graphics active,
producing the expected Sixel frame after SCREEN mode changes.
64/72 tests pass (89%). Only 5 remain: 3 structural (CHAIN/COMMON/RUN
"file" unsupported) + 2 RNG-dependent (different random seed).
Add emit_delegate_stmt() helper that embeds raw token bytes with full
variable sync (write before, read back after) and calls gw_exec_stmt().
Reusable pattern replaces ad-hoc token embedding in multiple handlers.
OPEN/CLOSE: delegate to runtime (handles all OPEN syntax variants).
PRINT #n: delegate with correct PRINT token position (was off-by-one).
WRITE #n: detect '#' and delegate (screen WRITE still inline).
INPUT/LINE INPUT: delegate with variable read-back.
LINE (INPUT or graphics): delegate.
LPRINT/LLIST: delegate.
50/72 tests pass. New: file_io, mbf_format, write_input.
CVI/CVS/CVD: handle 0xFD-prefix extended functions in emit_atom.
MKI$/MKS$/MKD$: handle in emit_str_atom. peek_expr_type detects FD
functions for correct PRINT type. Unlocks mkicvi.bas.
MID$ assignment: delegate to runtime via token embedding with variable
sync (both write and read-back for string variables).
ON ERROR GOTO / RESUME: set up gw_run_jmp in generated main() so
gw_error() can longjmp to the error handler. Create dummy
program_line_t so gw_find_line succeeds. Set gw.on_error_line when
ON ERROR GOTO is compiled. RESUME NEXT clears gw.in_error_handler
and dispatches to next line via line-number lookup.
ERR/ERL: emit gw_errno and gw.err_line_num for error pseudo-variables.
All-line labels: emit L_n labels for every program line (not just GOTO
targets) so RESUME NEXT can dispatch to any line.
49/72 tests pass (mkicvi new). error_handler and mid_assign partial.
String comparison: detect VT_STR left operand in relationals (>, <, =,
<=, >=, <>), re-emit as string atom, and use strcmp-based comparison
via GCC statement expression. Unlocks bubble_sort.
ON ERROR GOTO: add setjmp guard in generated main() that dispatches
to all GOTO target labels on error. Partial error_handler support.
Graphics/sound/file I/O extended statements: delegate to runtime via
token embedding with variable sync (same technique as PRINT USING and
DEF FN). Includes CIRCLE, DRAW, PAINT, PLAY, VIEW, WINDOW, PALETTE,
FIELD, LSET, RSET, PUT, GET. Fixed FE-prefix position tracking.
FRE("") GC: sync string variables to interpreter table before GC so
the collector can find live strings in compiled programs.
Division semantics: / always float (cast to double).
48/72 tests pass. New: bubble_sort, invoice. play_music/play_scale
restored after FE-prefix fix.
String concatenation: refactored emit_str_expr to use emit_str_atom +
concat loop. Self-referencing assignment A$ = A$ + B$ evaluates RHS
to temp before freeing old value.
Division semantics: GW-BASIC / always produces float (cast both operands
to double). Integer division is only for \ operator.
PRINT USING null-byte fix: token scanner now skips over float/double
constants (which may contain 0x00 bytes) instead of stopping on them.
Uses program_line_t.len for bounds instead of null termination.
FRE(): call strpool_gc() via comma expression for accurate reporting.
STICK(): return 128 (center). EOF/LOC/LOF function stubs.
46/72 tests pass. New: portio, print_using, print_using_edge,
monte_carlo (partial), string_gc, plus retained caesar_cipher,
roman_numerals.
String concatenation: refactor emit_str_expr into emit_str_atom + concat
loop. S$ = S$ + R$(I) now correctly accumulates via gw_str_concat.
String assignment order fix: evaluate RHS to temp before freeing old
value, so self-referencing A$ = A$ + B$ reads A$ before clearing it.
READ into array elements: subscript parsing with multi-dim support.
Array assignment: don't zero element before RHS evaluation (fixes
C(I,J) = C(I,J) + A(I,K)*B(K,J) self-referencing pattern).
PRINT USING colon-in-string: skip quoted strings when scanning for
statement-end colon.
43/72 tests pass. New: caesar_cipher, roman_numerals.
READ into array elements: parse subscripts after variable name in READ
handler, call gwrt_array_elem + gwrt_data_read. Unlocks matrix_mult,
roman_numerals (partial).
PRINT USING colon-in-string: scan past quoted strings when finding
statement-end colon for token embedding. Fixes truncated format strings
like "Pi estimate: #.####".
Array element assignment: don't zero element before RHS evaluation.
Previous code did `*_elem = {.type=4}` which zeroed fval before
reading C(I,J) in `C(I,J) = C(I,J) + A(I,K)*B(K,J)`, making
self-referencing assignments always read 0.
DEF FN call fix: skip past TOK_FN byte before calling gw_eval_fn_call.
DEFINT pre-scan: analysis pass processes DEFINT/DEFSNG/DEFDBL/DEFSTR
before variable type resolution.
Integer assignment rounding: use gw_cint() (rint) instead of (int16_t)
C truncation.
41/72 tests pass. 0 compile errors.
New: hundred_doors, matrix_mult, pascal_triangle, stats_calc.
PRINT USING: embed token bytes in generated C and call gw_print_using()
at runtime. Variable values synced to interpreter table before the call
so gw_eval() can resolve them. Unlocks fibonacci, temp_table, calendar.
STRING$ (single-byte token 0xD4): handle in emit_str_expr and PRINT
string detection. Emits gw_fn_strings() call.
INSTR (single-byte token 0xD6): handle in emit_atom with start position
detection. Emits gw_fn_instr() call.
PRINT USING token skip fix: skip past TOK_USING before embedding bytes
(gw_print_using expects text_ptr after USING, not at it).
27 of 72 tests now pass. New: fibonacci, calendar, temp_table.
Array name emission: use emit_name_str() to avoid null bytes in C string
literals when variable name has only one significant character.
Combined relationals: handle <=, >=, <> token pairs (TOK_LT+TOK_EQ etc.)
in the precedence climber. Previously these emitted "unknown tok 0xe5"
which broke WHILE X <= 10 and similar conditions.
Expression type tracking: peek_expr_type() determines VT_INT/VT_SNG/VT_DBL
from the leading token in PRINT expressions. PRINT now emits the correct
gw_value_t type for proper number formatting (single vs double precision).
23 of 72 tests now pass (up from 19). New: arrays, hailstone, while_wend,
prime_sieve, leibniz.
Arrays: DIM creates arrays via gwrt_dim() runtime call. Array element
read/write uses gwrt_array_elem() with buffered subscript expressions
(open_memstream) to correctly determine dimension count. Auto-DIM with
default size 10 for undeclared arrays.
Number formatting: PRINT now uses gw_print_value() (same as interpreter)
instead of gwrt_print_sng(), producing correct type-specific output.
OPEN fix: analysis pass skips OPEN statement arguments to avoid
misidentifying OUTPUT/INPUT/APPEND as variable names.
OPEN/CLOSE/INPUT: emit skip stubs (file I/O compilation is Phase 3).
19 of 72 tests now pass (up from 17). New: hanoi, text_adventure.
Add WHILE/WEND, ON n GOTO/GOSUB, ON ERROR GOTO, DIM (stub), SWAP,
POKE, DEF SEG, RANDOMIZE, COLOR, LOCATE, SCREEN, WIDTH, KEY, WRITE,
OPTION BASE, DEFINT/DEFSNG/DEFDBL/DEFSTR, TRON/TROFF.
Fix MOD/IDIV/POW operators: buffer left operand via open_memstream so
both sides can be properly cast (MOD/IDIV → int16_t, POW → pow()).
Previously MOD on float operands was a C compile error.
Handle all extended statement tokens (0xFE prefix): graphics, sound,
file I/O, view/window, environ, timer — either with real codegen or
graceful skip.
17 of 72 tests now pass (up from 15). 26 compile errors (down from 30).
- FOR/NEXT: use a FOR stack to match NEXT variables to their corresponding
FOR labels, fixing nested loops (e.g., FOR I...FOR J...NEXT J...NEXT I)
- Remove unused emit_int_expr function
- Build now zero warnings across all targets
- Compiler passes 15 of 72 test programs (Phase 1 target: ~30)
- codegen.c: refactor one-liner function cases to proper multi-line blocks,
eliminating all -Wmisleading-indentation warnings
- codegen.c: escape quotes and backslashes in DATA pool string literals
- codegen.c: guard NEXT against for_label_counter=0 (NEXT without FOR)
- codegen.c: remove unused functions (emit_expr, read_sng, read_dbl)
- analysis.c: add bounds check on data_line_map writes
- Build now produces zero warnings across all three targets
- FRE(): remove strpool_gc() call during expression evaluation — temporaries
on the C stack would become dangling pointers after compaction
- WAIT: reject mask=0 (would infinite-loop since AND 0 is always 0)
- ENVIRON: use setenv()+free() instead of putenv() to avoid memory leak
and dangling pointer if pool is compacted
- portio: add bounds check to com1_inp() (com1_out already had one)
- kernel: use CHR$(1) sentinel prefix to avoid collision with user output
- kernel: fix INPUT prompt rfind() edge case when no newline in buffer
- eval.c: enlarge DATE$ format buffer to silence -Wformat-truncation
Sixel graphics: pure-Python decoder extracts ESC P...ESC \ sequences from
the output stream, renders RGBA pixels, and encodes as PNG for inline
display in the notebook. No external dependencies (no PIL, no Ghostscript).
INPUT support: when gwbasic prints "? " (INPUT prompt), the kernel uses
the Jupyter stdin protocol (raw_input) to request input from the user and
feeds the response back to the subprocess.
Pygments lexer (basic_lexer.py): GW-BASIC syntax highlighting with line
numbers, keywords, builtins, string/number literals, and comments.
Registered as a Pygments entry point and referenced in kernel language_info.
Test suite expanded from 10 to 14 tests (Sixel decode, PNG encode, inline
graphics integration, lexer tokenization).
Persistent subprocess model: gwbasic reads BASIC from stdin and writes
output to stdout in piped mode (no banner, no prompts, unbuffered).
Sentinel protocol (PRINT "<<<GWDONE>>>") delimits output per cell.
Features: state persistence across cells, error detection and reporting,
tab completion for GW-BASIC keywords, %reset/%timeout/%new magic
commands, Ctrl+C forwarding, automatic process restart.
Includes setup.py for pip install, kernel.json spec, install script,
and 10-test smoke suite (all passing).
Replaces individual malloc/free string management with a contiguous pool
(default 32KB) and compacting GC, matching the original GW-BASIC's
GETSPA/GARBAG architecture. Allocation is a bump pointer; gw_str_free()
is a no-op (descriptors are nulled, data reclaimed by GC). Compaction
runs at statement boundaries when the pool drops below 4KB free, walking
the variable table and array storage to relocate live strings.
FRE() now returns actual free pool space. FRE("") triggers a GC pass
before reporting. CLEAR n sets the string space size.
Closes the last unimplemented extended statement tokens. ENVIRON uses
putenv/getenv for real environment variable access. DATE$/TIME$
assignment is accepted but silently ignored (no system clock modification).
ERDEV/ERDEV$/IOCTL$/PEN return stub values (no real device hardware).
CALL/CALLS raise Illegal function call. COM event trapping silently
accepted.
New portio.c module following the virmem.c dispatch-by-address pattern,
emulating 8253 PIT channel 2 (speaker frequency), PPI port B (speaker
on/off), CGA mode/color select registers, game port (joystick stub),
COM1 serial (transmitter-ready stub), and floating bus default (0xFF).
OUT/WAIT/MOTOR statements and INP()/STICK()/STRIG() functions now fully
functional. Continuous tone generation via PulseAudio pthread worker for
programs that drive the speaker through OUT &H43/&H42/&H61.