From b84f5f5e53f2df58dd38601cd7cb90dd7c8ae05a Mon Sep 17 00:00:00 2001 From: bunny Date: Tue, 9 Sep 2025 13:04:32 +0100 Subject: [PATCH] added memory manipulation constructs --- app/Compiler.hs | 27 ++++++++++++++++++++++++--- app/Parser.hs | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/Compiler.hs b/app/Compiler.hs index 1b7dd8c..ec19513 100644 --- a/app/Compiler.hs +++ b/app/Compiler.hs @@ -99,6 +99,25 @@ handleSymbol h (ZorthASTWord "dup") = do \ push rax\n" return () + +handleSymbol h (ZorthASTWord "mem") = do + liftIO $ hPutStr h + " push mem\n" + return () + +handleSymbol h (ZorthASTWord "!") = do + liftIO $ hPutStr h + " pop rbx\n\ + \ pop rax\n\ + \ mov qword[rax], rbx\n" + return () + +handleSymbol h (ZorthASTWord "@") = do + liftIO $ hPutStr h + " pop rax\n\ + \ push qword[rax]\n" + return () + handleSymbol h (ZorthASTWord "rot") = do liftIO $ hPutStr h " pop rax\n\ @@ -221,6 +240,8 @@ compileZorth _ [] = return () compileZorth h xs = do forthPrelude h compileZorthAST h xs $ Environment 0 M.empty - hPutStr h " mov rax,60\n\ - \ mov rdi,0\n\ - \ syscall\n" \ No newline at end of file + hPutStr h " mov rax,60\n\ + \ mov rdi,0\n\ + \ syscall\n" + hPutStr h "section .bss\n\ + \ mem: resq 640000\n" \ No newline at end of file diff --git a/app/Parser.hs b/app/Parser.hs index a1e8502..4249e6c 100644 --- a/app/Parser.hs +++ b/app/Parser.hs @@ -15,7 +15,7 @@ data ZorthExpr = ZorthASTInteger Int | ZorthASTComment String deriving Show -word1 :: Parser String +word1 :: Parser String word1 = do x <- sat (\x -> x /= '\n' && x /= ' ') xs <- word