| Age | Commit message (Collapse) | Author |
|
|
|
_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>
|
|
|
|
Replace the `func` language keyword with `fun` throughout: update the
scanner's string-to-token mapping, all .fy example scripts, and all
documentation files (.txt, .pod, .tex, .man, .html).
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>
|
|
Replace bare say statements with assert expected == say value; so that
each example self-verifies its output at runtime — matching the
convention used in expressions.fy and types.fy.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
|
Completes the 'loop, next, break, do' TODO entry — break and next
were landed in the previous commit; this adds the remaining two forms:
- loop { body } — infinite loop; the only exit is break. Simpler than
while/until since there is no condition expression to evaluate.
- do { body } while expr; / do { body } until expr; — post-condition
loop: body always executes at least once, condition is checked at the
bottom of each iteration. Condition tokens are collected until ';'
(mirrors _expression_get but stops at semicolon instead of '{'), then
replayed each iteration using the same temp-stack/temp-iterator
technique as while/until. Both break and next are supported.
Token changes: TT_LOOP and TT_DO added to the keyword enum in token.h,
registered in get_tt() and tt_get_name() in token.c.
Add examples/loop_do.fy; expected output: 5 / 12 / 11 / 5.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
|
TT_BREAK and TT_NEXT were already tokenised; this wires them up:
- _program(): guard statement loop with ct == CONTROL_NONE so a break/next
flag set inside a loop body stops block execution and propagates upward
- _control(): add TT_BREAK and TT_NEXT cases that set CONTROL_BREAK /
CONTROL_NEXT on p_interpret->ct and return immediately
- while/until loop: replace the commented-out switch with active if/else
logic that clears the flag and either stops iteration (break) or lets
the loop re-evaluate its condition (next)
Add examples/break_next.fy to exercise both keywords in while and until
loops; expected output: 5 / 12 / 7.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|