diff --git a/src/Codegen/CompilerState.hs b/src/Codegen/CompilerState.hs index a6c100a..3aa4123 100644 --- a/src/Codegen/CompilerState.hs +++ b/src/Codegen/CompilerState.hs @@ -135,7 +135,7 @@ defaultStart = , UnsafeRaw "declare i32 @printf(ptr noalias nocapture, ...)\n" , UnsafeRaw "declare i32 @exit(i32 noundef)\n" , UnsafeRaw "declare ptr @malloc(i32 noundef)\n" - , UnsafeRaw "declare void @_ZN2GC4Heap4initEv()\n" - , UnsafeRaw "declare void @_ZN2GC4Heap5allocEm()\n" - , UnsafeRaw "declare void @_ZN2GC4Heap7disposeEv()\n" + , UnsafeRaw "declare external void @cheap_init()\n" + , UnsafeRaw "declare external ptr @cheap_alloc(i64)\n" + , UnsafeRaw "declare external void @cheap_dispose()\n" ] \ No newline at end of file diff --git a/src/Codegen/Emits.hs b/src/Codegen/Emits.hs index c41e340..0309514 100644 --- a/src/Codegen/Emits.hs +++ b/src/Codegen/Emits.hs @@ -127,12 +127,13 @@ compileScs (MIR.DData (MIR.Data typ ts) : xs) = do compileScs xs firstMainContent :: [LLVMIr] -firstMainContent = [] +firstMainContent = [UnsafeRaw "call void @cheap_init()\n"] lastMainContent :: LLVMValue -> [LLVMIr] lastMainContent var = [ UnsafeRaw $ "call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef " <> toIr var <> ")\n" + , UnsafeRaw "call void @cheap_dispose()\n" , Ret I64 (VInteger 0) ] @@ -169,6 +170,7 @@ emitECased t e cases = do -- crashLbl <- TIR.Ident . ("crash_" <>) . show <$> getNewLabel -- emit $ Label crashLbl emit . UnsafeRaw $ "call i32 (ptr, ...) @printf(ptr noundef @.non_exhaustive_patterns, i64 noundef 6, i64 noundef 6)\n" + emit . UnsafeRaw $ "call void @cheap_dispose()\n" emit . UnsafeRaw $ "call i32 @exit(i32 noundef 1)\n" mapM_ (const increaseVarCount) [0 .. 1] emit $ Br label diff --git a/src/Codegen/LlvmIr.hs b/src/Codegen/LlvmIr.hs index 0ef6ac0..ac9432a 100644 --- a/src/Codegen/LlvmIr.hs +++ b/src/Codegen/LlvmIr.hs @@ -225,7 +225,7 @@ llvmIrToString = go 0 (Alloca t) -> unwords ["alloca", toIr t, "\n"] (Malloca t) -> concat - [ "call ptr @malloc(i32 ", show t, ")\n"] + [ "call ptr @cheap_alloc(i64 ", show t, ")\n"] (Store t1 val t2 (Ident id2)) -> concat [ "store ", toIr t1, " ", toIr val diff --git a/src/Compiler.hs b/src/Compiler.hs index 0b34936..c486cc4 100644 --- a/src/Compiler.hs +++ b/src/Compiler.hs @@ -15,8 +15,15 @@ compileClang = readCreateProcess . shell $ unwords [ "clang++" -- , "-Lsrc/GC/lib/", "-l:libgcoll.a" - , "-fno-exceptions -x" - , "ir" + , "-fno-rtti" + , "src/GC/lib/cheap.cpp" + , "src/GC/lib/event.cpp" + , "src/GC/lib/heap.cpp" + , "src/GC/lib/profiler.cpp" + , "-Wall -Wextra -g -std=gnu++20 -stdlib=libstdc++" + , "-Isrc/GC/include" + , "-x" + , "ir" -- , "-Lsrc/GC/lib -l:gcoll.a" , "-o" , "output/hello_world" , "-" diff --git a/test_program.crf b/test_program.crf index 14cd86c..b584ff8 100644 --- a/test_program.crf +++ b/test_program.crf @@ -1,9 +1,9 @@ --- main = head (Cons (sum (repeat 10 5)) Nil); +main = head (Cons (sum (repeat 5 9223372036854775807)) Nil); --9223372036854775807 -main = case (bind (fmap (\s . s + 1) (Just 5)) (\s . pure (s + 10))) of { - Just a => a ; - Nothing => minusOne ; -}; +-- main = case (bind (fmap (\s . s + 1) (Just 5)) (\s . pure (s + 10))) of { +-- Just a => a ; +-- Nothing => minusOne ; +-- }; ---- MAYBE MONAD ---- data Maybe () where {