Integrated the garbage collector.
This commit is contained in:
parent
bbe0d77a19
commit
b3525db7fd
5 changed files with 21 additions and 12 deletions
|
|
@ -135,7 +135,7 @@ defaultStart =
|
||||||
, UnsafeRaw "declare i32 @printf(ptr noalias nocapture, ...)\n"
|
, UnsafeRaw "declare i32 @printf(ptr noalias nocapture, ...)\n"
|
||||||
, UnsafeRaw "declare i32 @exit(i32 noundef)\n"
|
, UnsafeRaw "declare i32 @exit(i32 noundef)\n"
|
||||||
, UnsafeRaw "declare ptr @malloc(i32 noundef)\n"
|
, UnsafeRaw "declare ptr @malloc(i32 noundef)\n"
|
||||||
, UnsafeRaw "declare void @_ZN2GC4Heap4initEv()\n"
|
, UnsafeRaw "declare external void @cheap_init()\n"
|
||||||
, UnsafeRaw "declare void @_ZN2GC4Heap5allocEm()\n"
|
, UnsafeRaw "declare external ptr @cheap_alloc(i64)\n"
|
||||||
, UnsafeRaw "declare void @_ZN2GC4Heap7disposeEv()\n"
|
, UnsafeRaw "declare external void @cheap_dispose()\n"
|
||||||
]
|
]
|
||||||
|
|
@ -127,12 +127,13 @@ compileScs (MIR.DData (MIR.Data typ ts) : xs) = do
|
||||||
compileScs xs
|
compileScs xs
|
||||||
|
|
||||||
firstMainContent :: [LLVMIr]
|
firstMainContent :: [LLVMIr]
|
||||||
firstMainContent = []
|
firstMainContent = [UnsafeRaw "call void @cheap_init()\n"]
|
||||||
|
|
||||||
lastMainContent :: LLVMValue -> [LLVMIr]
|
lastMainContent :: LLVMValue -> [LLVMIr]
|
||||||
lastMainContent var =
|
lastMainContent var =
|
||||||
[ UnsafeRaw $
|
[ UnsafeRaw $
|
||||||
"call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef " <> toIr var <> ")\n"
|
"call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef " <> toIr var <> ")\n"
|
||||||
|
, UnsafeRaw "call void @cheap_dispose()\n"
|
||||||
, Ret I64 (VInteger 0)
|
, Ret I64 (VInteger 0)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -169,6 +170,7 @@ emitECased t e cases = do
|
||||||
-- crashLbl <- TIR.Ident . ("crash_" <>) . show <$> getNewLabel
|
-- crashLbl <- TIR.Ident . ("crash_" <>) . show <$> getNewLabel
|
||||||
-- emit $ Label crashLbl
|
-- emit $ Label crashLbl
|
||||||
emit . UnsafeRaw $ "call i32 (ptr, ...) @printf(ptr noundef @.non_exhaustive_patterns, i64 noundef 6, i64 noundef 6)\n"
|
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"
|
emit . UnsafeRaw $ "call i32 @exit(i32 noundef 1)\n"
|
||||||
mapM_ (const increaseVarCount) [0 .. 1]
|
mapM_ (const increaseVarCount) [0 .. 1]
|
||||||
emit $ Br label
|
emit $ Br label
|
||||||
|
|
|
||||||
|
|
@ -225,7 +225,7 @@ llvmIrToString = go 0
|
||||||
(Alloca t) -> unwords ["alloca", toIr t, "\n"]
|
(Alloca t) -> unwords ["alloca", toIr t, "\n"]
|
||||||
(Malloca t) ->
|
(Malloca t) ->
|
||||||
concat
|
concat
|
||||||
[ "call ptr @malloc(i32 ", show t, ")\n"]
|
[ "call ptr @cheap_alloc(i64 ", show t, ")\n"]
|
||||||
(Store t1 val t2 (Ident id2)) ->
|
(Store t1 val t2 (Ident id2)) ->
|
||||||
concat
|
concat
|
||||||
[ "store ", toIr t1, " ", toIr val
|
[ "store ", toIr t1, " ", toIr val
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,15 @@ compileClang =
|
||||||
readCreateProcess . shell $
|
readCreateProcess . shell $
|
||||||
unwords
|
unwords
|
||||||
[ "clang++" -- , "-Lsrc/GC/lib/", "-l:libgcoll.a"
|
[ "clang++" -- , "-Lsrc/GC/lib/", "-l:libgcoll.a"
|
||||||
, "-fno-exceptions -x"
|
, "-fno-rtti"
|
||||||
, "ir"
|
, "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"
|
, "-o"
|
||||||
, "output/hello_world"
|
, "output/hello_world"
|
||||||
, "-"
|
, "-"
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
-- main = case (bind (fmap (\s . s + 1) (Just 5)) (\s . pure (s + 10))) of {
|
||||||
Just a => a ;
|
-- Just a => a ;
|
||||||
Nothing => minusOne ;
|
-- Nothing => minusOne ;
|
||||||
};
|
-- };
|
||||||
|
|
||||||
---- MAYBE MONAD ----
|
---- MAYBE MONAD ----
|
||||||
data Maybe () where {
|
data Maybe () where {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue