diff options
| author | 2026-10-14 10:39:47 +0000 | |
|---|---|---|
| committer | 2026-10-14 10:39:47 +0000 | |
| commit | 54b8a8918bb63c98a8f58e823033232243647562 (patch) | |
| tree | e0608f7dab1f568c22390262e5a6d39966519760 /src/compiler/base.zc | |
| parent | todo: handoff section with state, conventions, in-flight work and architectur... (diff) | |
zc: add the defer statement
defer expr; and defer { ... } register code that runs when the enclosing
block ends: at the end of the block, and at return, break and continue
that leave it. the tokens are kept at the defer and compiled again at each
exit (block_close, body, kw_return, kw_break, kw_continue), newest first,
before the block's variables are released, so the analyzer sees a deferred
rt.free(p) as the transfer of p where it runs. names mean what they meant
at the defer; values are read when it runs. return, break and continue
inside a deferred statement are errors, reported once. works in unchecked
code and closures (own base per function context).
Diffstat (limited to 'src/compiler/base.zc')
| -rw-r--r-- | src/compiler/base.zc | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/compiler/base.zc b/src/compiler/base.zc index 17ec80b..d83dc9d 100644 --- a/src/compiler/base.zc +++ b/src/compiler/base.zc @@ -248,6 +248,14 @@ word xprojection; int af_mutation_tick; int xbor = -1; // local a pointer value is borrowed from, or -1 int mdbg, mdbg_flags; // memdebug: compile checks in, and the flags start() turns on int lsp, loopbase, ctxsp, snaptop; +// defer: the statements registered and not yet run, DFR_W words each (the block +// depth of the defer, its token list, whether the analyzer was on, whether compiling +// it failed, so the error is reported once, and the locals there were at the defer), +// newest last. dfr_base is where the current function's entries start. dfr_on is set +// while a deferred statement is compiled; dfr_lsp and dfr_ctx say where its own loops +// and function begin. +const int DFR_MAX = 256, DFR_W = 5; +word[1280] dfr; int ndfr, dfr_base, dfr_on, dfr_lsp, dfr_ctx; int lv, lvk, lvi, kw_expr, xcls, fty; // interned spellings the parser compares against |
