From 16d58ebac0ea1250055b046414b40549426eeb84 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 28 Feb 2026 19:56:42 +0200 Subject: Fix function body literal mutation: make examples pass MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- docs/stats.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/stats.txt') diff --git a/docs/stats.txt b/docs/stats.txt index e4a2d10..09e90e9 100644 --- a/docs/stats.txt +++ b/docs/stats.txt @@ -1,6 +1,6 @@ make[1]: Entering directory '/home/paul/git/fype' ===> Num of C source files : 46 -===> Num of C source lines : 8744 +===> Num of C source lines : 8753 ===> Num of Fype source examples : 19 ===> Num of Fype source lines : 883 make[1]: Leaving directory '/home/paul/git/fype' -- cgit v1.2.3