From 28055326bbf7f9830ba2082fd03928732ac07290 Mon Sep 17 00:00:00 2001 From: Eremey Valetov Date: Sun, 29 Mar 2026 19:40:30 -0400 Subject: [PATCH] =?UTF-8?q?Compiler:=20CHAIN/COMMON/RUN=20"file"=20via=20r?= =?UTF-8?q?untime=20delegation=20=E2=80=94=2067/72=20(93%)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- src/codegen.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/codegen.c b/src/codegen.c index 4a79f9e..e9dce55 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -1853,6 +1853,20 @@ static void emit_stmt(void) } /* OPEN / CLOSE — file I/O (Phase 3: needs inline argument parsing) */ + /* RUN ["file"] — if with string arg, delegate to runtime interpreter */ + if (tok == TOK_RUN) { + uint8_t *start = tp; + advance(); + skip_spaces(); + if (cur() == '"') { + /* RUN "file" — load and run via interpreter. Doesn't return. */ + emit_delegate_stmt(start, false); + EMIT(" gwrt_shutdown(); exit(0);\n"); + } + /* RUN (without file) — restart compiled program. Just goto first line. */ + return; + } + /* SAVE / LOAD / MERGE / BSAVE / BLOAD — delegate to runtime */ if (tok == TOK_SAVE || tok == TOK_LOAD) { uint8_t *start = tp; @@ -2132,9 +2146,16 @@ static void emit_stmt(void) emit_delegate_stmt(fe_start, true); return; } - if (xstmt == XSTMT_COMMON || xstmt == XSTMT_CHAIN) { - EMIT(" /* CHAIN/COMMON — not supported in compiled mode */\n"); - while (cur() && cur() != ':' && cur() != 0) tp++; + if (xstmt == XSTMT_COMMON) { + /* COMMON marks variables for CHAIN preservation — delegate */ + emit_delegate_stmt(fe_start, false); + return; + } + if (xstmt == XSTMT_CHAIN) { + /* CHAIN loads + runs another .bas file via the runtime interpreter. + * Sync all variables, then delegate. CHAIN doesn't return. */ + emit_delegate_stmt(fe_start, false); + EMIT(" gwrt_shutdown(); exit(0); /* CHAIN doesn't return */\n"); return; } if (xstmt == XSTMT_ENVIRON || xstmt == XSTMT_DATE ||