From ad74107a2c4debd359b0eca98fa5288ba1e2e194 Mon Sep 17 00:00:00 2001 From: iko Date: Sat, 18 May 2024 14:33:40 +0300 Subject: [PATCH] Added somw loops --- zod/luau/lib/lua.hoon | 37 +++++++++++++++++++++++++++++++++++++ zod/luau/tests/foo.lua | 12 ++++++++++++ 2 files changed, 49 insertions(+) diff --git a/zod/luau/lib/lua.hoon b/zod/luau/lib/lua.hoon index 4552415..7bc8b9a 100644 --- a/zod/luau/lib/lua.hoon +++ b/zod/luau/lib/lua.hoon @@ -467,6 +467,8 @@ [%label label] [%goto label] [%func-call functioncall] + [%while cond=expr body=blok] + [%repeat body=blok cond=expr] [%break ~] [%empty ~] == @@ -478,6 +480,25 @@ :: (cold [%break ~] (jest 'break')) :: + %+ cook + |= [* cond=expr * body=blok *] [%while cond body] + ;~ (glue wss) + (jest 'while') + parse-expr + (jest 'do') + parse-blok + (jest 'end') + == + :: + %+ cook + |= [* body=blok * cond=expr] [%repeat body cond] + ;~ (glue wss) + (jest 'repeat') + parse-blok + (jest 'until') + parse-expr + == + :: %+ cook |= [* =label] [%goto label] ;~ (glue ws) @@ -531,6 +552,22 @@ "goto " (trip +.stat) == + %while + %- zing + :~ + "while " + (print-expr cond.stat) + " do\0a" + (print-blok body.stat) + == + %repeat + %- zing + :~ + "repeat\0a" + (print-blok body.stat) + "until " + (print-expr cond.stat) + == == :: functioncall :: diff --git a/zod/luau/tests/foo.lua b/zod/luau/tests/foo.lua index 79c7f7e..bcbbea0 100644 --- a/zod/luau/tests/foo.lua +++ b/zod/luau/tests/foo.lua @@ -59,3 +59,15 @@ h{key1 = 'Sonmi~451'} goto helli break + +while true do + break +end + +repeat +do + foo = 9 + ; +end +until true +