diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-28 19:56:42 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-28 19:56:42 +0200 |
| commit | 16d58ebac0ea1250055b046414b40549426eeb84 (patch) | |
| tree | ddda72dcef4c44411f6c313c2c03ac09bda50a34 /src/core/token.c | |
| parent | 6bcaef138f13f9894abe3790aca52591a3d2d1f6 (diff) | |
Fix function body literal mutation: make examples pass
Two bugs combined to break uber.fy and any function called more than once:
1. Scanner split identifiers at '_' boundaries (e.g. arr_sum → arr + _sum).
Fixed by adding d != '_' to the token-splitting guard condition so
underscores are treated as part of identifiers.
2. Dead keyword TT_ARR reserved the name 'arr' as a keyword token,
preventing its use as a function parameter. Removed TT_ARR from the
enum, keyword table, and name table.
3. (Root cause of the assert failure) _var_assign stored the symbol for a
newly declared variable pointing directly at the literal token from the
function body token list. incr/decr modify tokens in place via
stack_top, so a loop like `my i = 0; while i < n { incr i; }` would
corrupt the body's '0' literal — on the next call i starts at 10 instead
of 0. Fixed by allocating a fresh token_new_integer / token_new_dummy
for TT_INTEGER and TT_DOUBLE initialisers so body literals are never
mutated. Arrays and strings retain reference semantics unchanged.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'src/core/token.c')
| -rw-r--r-- | src/core/token.c | 2 |
1 files changed, 0 insertions, 2 deletions
diff --git a/src/core/token.c b/src/core/token.c index f7cc745..b31bed9 100644 --- a/src/core/token.c +++ b/src/core/token.c @@ -61,7 +61,6 @@ get_tt(char *c_token) { CHECK("proc") TT_PROC; CHECK("fun") TT_FUNC; CHECK("my") TT_MY; - CHECK("arr") TT_ARR; CHECK("!") TT_NOT; CHECK("!=") TT_NEQ; CHECK("=~") TT_RE; @@ -127,7 +126,6 @@ tt_get_name(TokenType tt_cur) { CASE(TT_PROC,"TT_PROC") CASE(TT_FUNC,"TT_FUNC") CASE(TT_MY,"TT_MY") - CASE(TT_ARR,"TT_ARR") CASE(TT_WHILE,"TT_WHILE") CASE(TT_UNTIL,"TT_UNTIL") CASE(TT_NEXT,"TT_NEXT") |
