| Age | Commit message (Collapse) | Author |
|
|
|
functions.c::_op_assign() was reading p_interpret->p_token_array_lhs and
p_interpret->i_array_lhs_index directly — a hidden cross-module coupling
where the functions module reached into interpreter-private state.
Pass the array-LHS context as explicit parameters instead:
- _op_assign() gains Token *p_array_lhs, int i_lhs_idx params
- _process() propagates them to _op_assign()
- function_process() propagates them from the call site
In interpret.c the "restore" lines that set p_interpret->p_token_array_lhs
and p_interpret->i_array_lhs_index before calling function_process() are
removed; instead p_lhs and i_lhs_idx are passed directly. The three
non-array-LHS call sites pass NULL / 0. _op_assign() no longer touches
Interpret internals for the array assignment path.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
|
_process() was a 510-line function with a nested switch(operator) x
switch(type) structure. Extracted 17 static helper functions:
- _resolve_composite_op(): maps two-token operator pairs (!=, ==, <=,
>=, <<, >>) to their canonical single TokenType
- _op_assign(): handles variable and array-element assignment
- _op_add(), _op_sub(), _op_mult(), _op_div(): arithmetic operators
- _op_eq(), _op_neq(), _op_lt(), _op_gt(), _op_le(), _op_ge():
comparison operators (result always TT_INTEGER)
- _op_and(), _op_or(), _op_xor(), _op_lshift(), _op_rshift():
bitwise operators (doubles/strings coerced to int)
_process() is now a ~70-line dispatcher. Assignment is guarded by
`else if` so it only fires when p_token_op2 == NULL, preserving the
original semantics exactly.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
|
Extract each of the 21 built-in function handlers (assert, decr, double,
end, exit, fork, gc, incr, ind, integer, len, ln, neg, no, not, put,
refs, say, scope, string, yes) into individual static _builtin_XXX()
functions, each focused on a single responsibility.
Add a null-terminated BuiltinEntry g_builtins[] dispatch table mapping
name strings to handler function pointers. Rewrite function_is_buildin()
and function_process_buildin() to iterate the table instead of
maintaining parallel 21-branch strcmp chains.
This satisfies OCP (adding a built-in only requires a new table row),
SRP (each handler owns exactly one built-in's logic), and DRY (name
lookup done in one place). The array special-case (len/ind on TT_ARRAY
vs element-wise iteration) is preserved inline before the table dispatch.
Also add missing NO_DEFAULT; to _builtin_say's switch for style
consistency with all other handlers.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
|
|
|
- Add FuncDef struct to symbol.h/symbol.c: holds body token list,
strdup'd param names, and param count; replaces the bare List* that
SYM_FUNCTION used to store; funcdef_delete frees param strings and
body list (tokens are GC-managed)
- Add CONTROL_RET to ControlType so ret can propagate cleanly through
the interpreter's control-flow stack
- Update _func_decl to parse optional (p1, p2, ...) param list and store
a FuncDef* instead of a raw List*
- Implement case TT_RET in _control: clears intermediate stack values,
evaluates comma-separated return expressions, sets CONTROL_RET
- Propagate CONTROL_RET in all loop bodies (while/until, loop, do)
without clearing it; while/until rescues return values from the
temporary condition stack before it is destroyed
- Update _term call site to support parenthesised func(arg1, arg2)
syntax alongside the existing no-parens style for backward compat
- Modify interpret_subprocess to merge the sub's stack into the parent
when CONTROL_RET is active so return values survive teardown
- Update function_process_self_defined SYM_FUNCTION case to pop and
bind named args, run the body, then clear CONTROL_RET
- Add -D_POSIX_C_SOURCE=200809L to Makefile CFLAGS for strdup under
-std=c99 -pedantic
- Add examples/func_args_ret.fy covering zero-arg, single-arg,
two-arg, conditional ret, multiple return values, and old-style
no-parens backward compat
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|