diff options
| author | iamcheeseman <[email protected]> | 2026-04-17 20:30:05 -0400 |
|---|---|---|
| committer | iamcheeseman <[email protected]> | 2026-04-17 20:30:05 -0400 |
| commit | de5d3ebdbc674bf8f1e324ee5b43c51af288a286 (patch) | |
| tree | dc8b71afade33ddc43dae846456d031f49f3c97e /uscript/parser.c | |
| parent | a4677cf4301f378c6338f2f29408f83f91053516 (diff) | |
microscript: syntax sugar for one-liner functions
Diffstat (limited to 'uscript/parser.c')
| -rw-r--r-- | uscript/parser.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/uscript/parser.c b/uscript/parser.c index dc721d5..f90e6d0 100644 --- a/uscript/parser.c +++ b/uscript/parser.c @@ -739,13 +739,17 @@ void fun_stat(struct parser *p, bool is_global) expect(p, ')', "expected ')' after arguments"); } - while (p->cur.kind != TOKEN_END && p->cur.kind != TOKEN_EOF) - stat(p); + if (consume(p, ':')) { + expr(p); + parser_add_byte(p, BC_RET); + } else { + while (p->cur.kind != TOKEN_END && p->cur.kind != TOKEN_EOF) + stat(p); + expect(p, TOKEN_END, "unterminated function"); + } end_function(p); - expect(p, TOKEN_END, "unterminated function"); - if (global_idx != -1) { parser_add_byte(p, BC_SET_GLOBAL); parser_add_byte(p, (global_idx >> 8) & 0xFF); |
