added while looping construct

This commit is contained in:
2025-09-07 15:26:42 +01:00
parent 6b7ded0c2f
commit ab2cba643d
2 changed files with 29 additions and 2 deletions

View File

@@ -154,6 +154,26 @@ handleSymbol h (ZorthASTIfElse (ifBranch,elseBranch)) = do
put $ Environment l'' state
liftIO $ hPutStr h $ ".L"<>l2<>":\n"
handleSymbol h (ZorthASTWhile (condition,body)) = do
(Environment l state) <- get
let bodyl = show $ l+1
let conditionl = show $ l+2
let restl = show $ l+3
put $ Environment (l+3) state
liftIO $ hPutStrLn h $ " jmp .L"<>conditionl
liftIO $ hPutStrLn h $ ".L"<>bodyl<>":"
compileZorthASTState h body
(Environment l' _) <- get
put $ Environment l' state
liftIO $ hPutStrLn h $ "\n.L"<>conditionl<>":"
compileZorthASTState h condition
(Environment l'' _) <- get
put $ Environment l'' state
liftIO $ hPutStrLn h $ " pop rax"
liftIO $ hPutStrLn h $ " cmp rax,0"
liftIO $ hPutStrLn h $ " jg .L"<>bodyl
liftIO $ hPutStrLn h $ ".L"<>restl<>":"
truthOperator :: Handle -> String -> IO ()
truthOperator h s =
hPutStr h $