Compare commits

...

2 Commits

Author SHA1 Message Date
iko
907ae4d250
Added function calls 2024-05-18 00:14:54 +03:00
iko
996ab8bc20
Returns 2024-05-17 23:30:50 +03:00
2 changed files with 134 additions and 3 deletions

View File

@ -465,6 +465,7 @@
[%blok blok]
[%asmnt varlist exprlist]
[%label label]
[%func-call functioncall]
[%empty ~]
==
++ parse-stat
@ -492,6 +493,10 @@
(just '=')
parse-exprlist
==
::
%+ cook
|= =functioncall [%func-call functioncall]
parse-functioncall
==
++ print-stat
|= [=stat]
@ -507,7 +512,88 @@
(commaed (turn +>.stat print-expr))
==
%label (print-label +.stat)
%func-call (print-functioncall +.stat)
==
:: functioncall
::
+$ functioncall
$%
[%call func=prefix-expr =args]
[%method obj=prefix-expr method=name =args]
==
++ print-functioncall
|= call=functioncall
^- tape
?- -.call
%call
%- zing
:~
(print-prefix-expr func.call)
(print-args args.call)
==
%method
%- zing
:~
(print-prefix-expr obj.call)
":"
(trip method.call)
(print-args args.call)
==
==
++ parse-functioncall
%+ knee *functioncall
|.
;~ pose
%+ cook
|= [func=prefix-expr =args] [%call func args]
;~ (glue ws)
parse-prefix-expr
parse-args
==
::
%+ cook
|= [obj=prefix-expr * method=name =args]
[%method obj method args]
;~ (glue ws)
parse-prefix-expr
(just ':')
parse-name
parse-args
==
==
:: args
::
+$ args exprlist
++ print-args
|= =args
^- tape
%- zing
:~
"("
(print-exprlist args)
")"
==
++ parse-args
%+ knee *args
|.
;~ pose
%+ cook
|= [* =exprlist *] exprlist
;~ (glue ws)
(just '(')
parse-exprlist
(just ')')
==
::
%+ cook
|= =table ~[[%table table]]
parse-table
::
%+ cook
|= =string ~[[%string string]]
parse-string
==
::
:: label
::
+$ label name
@ -532,17 +618,51 @@
==
:: Blok
::
+$ blok (lest stat)
+$ blok [body=(lest stat) ret=(unit ret)]
++ print-blok
|= [=blok]
^- tape
%- zing
%+ join "\0a"
(turn blok print-stat)
%+ weld
(turn body.blok print-stat)
?~ ret.blok ~
~[(print-ret u.ret.blok)]
++ parse-blok
%+ knee *blok
|.
(most wss parse-stat)
;~ plug
(most wss parse-stat)
::
%- punt
;~ pfix
wss
parse-ret
==
==
:: ret
::
+$ ret exprlist
++ print-ret
|= =ret
^- tape
%- zing
:~
"return "
(print-exprlist ret)
==
++ parse-ret
%+ knee *ret
|.
%+ cook
|= [[* =exprlist] *] exprlist
;~ plug
;~ (glue wss)
(jest 'return')
parse-exprlist
==
(punt (just ';'))
==
:: Helpers
::
++ commaed

View File

@ -44,3 +44,14 @@ foo = {
3.0, 3.1416, 314.16e-2, 0.31416E1, 34e1,
0x0.1E, 0xA23p-4, 0xA23p-4, 0X1.921FB54442D18P+1, 0x1.fp10
}
do
foo = 1
return 8, foo;
end
print('the way of the future')
print 'hello'
h{key1 = 'Sonmi~451'}