diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-19 10:13:51 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-19 10:13:51 +0200 |
| commit | 2e81f599a0323e2025883bc1375bf438d1406733 (patch) | |
| tree | 8083216541adfb688e47d1c2dfbf8010ef34f23a /tags | |
| parent | 3ad7831662b8f4c6ffd4666169b8edebc1391e36 (diff) | |
Implement function named arguments, ret, and multiple return values
- 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>
Diffstat (limited to 'tags')
| -rw-r--r-- | tags | 2 |
1 files changed, 2 insertions, 0 deletions
@@ -160,6 +160,8 @@ datiter_new ./src/data/dat.c /^datiter_new(Dat *p_dat) {$/;" f typeref:typename: datiter_next ./src/data/dat.c /^datiter_next(DatIter *p_iter) {$/;" f typeref:typename:void * datiter_next_t ./src/data/dat.c /^datiter_next_t(DatIter *p_iter, TYPE *p_type) {$/;" f typeref:typename:void * datiter_skip ./src/data/dat.c /^datiter_skip(DatIter *p_iter, unsigned i_num) {$/;" f typeref:typename:void +funcdef_delete ./src/core/symbol.c /^funcdef_delete(FuncDef *p_funcdef) {$/;" f typeref:typename:void +funcdef_new ./src/core/symbol.c /^funcdef_new(List *p_body, List *p_params, int i_nparams) {$/;" f typeref:typename:FuncDef * function_delete ./src/core/function.c /^function_delete(Function *p_function) {$/;" f typeref:typename:void function_is_buildin ./src/core/functions.c /^function_is_buildin(Token *p_token_ident) {$/;" f typeref:typename:_Bool function_is_self_defined ./src/core/functions.c /^function_is_self_defined(Interpret *p_interpret) {$/;" f typeref:typename:_Bool |
