From 1dd1ba377bebb7d4ae2089cda25eca1d3f6bd490 Mon Sep 17 00:00:00 2001 From: IgorCielniak Date: Sun, 14 Dec 2025 17:02:09 +0100 Subject: [PATCH] added support for raw l2 statementrs inside 'fn' decls --- a.out | Bin 7616 -> 7760 bytes build/t.asm | 27 +++++++++++++++++++++++++++ build/t.o | Bin 3984 -> 4128 bytes build/test.asm | 40 ++++++++++++++++++++-------------------- build/test.o | Bin 7472 -> 7472 bytes fn.sl | 43 +++++++++++++++++++++++++++++++++++++++++-- t.sl | 8 +++++--- 7 files changed, 93 insertions(+), 25 deletions(-) diff --git a/a.out b/a.out index 5ea17b99f8ed72a413c43acc14dfde00853217e9..b3b29121da1194e429d505e59de9100342b01006 100755 GIT binary patch delta 354 zcmX?LeZgje2IGZ^n)#f^SQxR+t<|NsAsB|yTn`3;BXaTXOu zprRLNe#5zIgxFg6oN_cV}_N;ESM17#*hiHL2^ z7s+HX{1391fstXlhy#cL2b>@S7=VO=16&Nm5SaW?LYz?=Oe#%QloV&w1(W8J10}^J zy?`17fTl4Bpz3m++z3<|2qqmiZYVwxNxvu85D ttRiFhWJB3<(FhTU`T|x64RVRu)z#7n(B(uupUpoA^Nk$e1j}Xa}OA80|y@*crfJ2P=eT15!4V*D`8z z3h+Wi5+*-nG-oQ{pDe{>!PvMtn8}=_{>94w|Np;O0wg?}-*9*yXHj7UDt>YHH$niU z`NckT6>CBIy8Z%*P7tdFNF0V4!3@*^V>5wtPXj5bL^Ja+P-gQ?Hhxw~Hjp9)MuzDu zAQ}M#CLiRMoqUX2h*^b+VX`BmD5Lh|kKE#nW?<5GvLcT-qX(D_njFYuFfo8*b0ZHU S6LVUA{^T0I=*bWGHUI#zU}uy7 delta 175 zcmZ3WFhPF80>33W?Fn|UP`>N>0~WwrC?(-h)`N$PH}3yu?3O>OC+{ALwSBt wN_r # out tok (r: body') + dup "return" string= if + drop + r> + continue + then + dup ";" string= if + drop + r> + continue + then + list-append # out' + r> # out' body' + continue +again +; +compile-only + + +: fn-body->tokens # bodyLexemes -- tokens + dup list-length 0 == if "empty function body" parse-error then + dup 0 list-get token-lexeme "return" string= if + fn-validate-body # expr + shunt # postfix + exit + then + fn-filter-raw-body + dup list-length 0 == if "empty function body" parse-error then +; +compile-only + : fn-emit-prologue # params out -- params out over list-length # params out n begin @@ -322,8 +362,7 @@ compile-only fn-collect-body # params bodyTokens swap >r # bodyTokens (r: params) fn-lexemes-from-tokens # lexemes - fn-validate-body # expr - shunt # postfix + fn-body->tokens # tokens r> # postfix params fn-build-body # body r> drop # drop name string diff --git a/t.sl b/t.sl index 4833ba2..7eee533 100644 --- a/t.sl +++ b/t.sl @@ -1,13 +1,15 @@ import stdlib.sl import fn.sl -fn foo(int a){ - return a + 1; +fn foo(int a, int b){ + 1 + puts + return a b +; } : main extend-syntax - foo(1) + foo(3, 2) puts 0 ; \ No newline at end of file