Various codegen fixes
This commit is contained in:
parent
45578a79b1
commit
22dcbc6a13
7 changed files with 99 additions and 77 deletions
|
|
@ -16,8 +16,15 @@ insertionSort xs = case xs of
|
|||
Nil => xs
|
||||
Nil => Nil
|
||||
|
||||
main = head (insertionSort (Cons 5 (Cons 4 (Cons 3 (Cons 2 (Cons 1 Nil))))))
|
||||
main = head (insertionSort (revRange 1250))
|
||||
|
||||
head xs = case xs of
|
||||
Cons x _ => x
|
||||
|
||||
revRange x = case x of
|
||||
0 => Cons x Nil
|
||||
x => Cons x (revRange (x + minusOne))
|
||||
|
||||
-- represents minus one :)
|
||||
minusOne : Int ;
|
||||
minusOne = 9223372036854775807 + 9223372036854775807 + 1;
|
||||
18
sample-programs/loop.crf
Normal file
18
sample-programs/loop.crf
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
main = for 0 1000
|
||||
|
||||
for x n = case n of
|
||||
0 => 0
|
||||
n => for (revRange 1000) (n + minusOne)
|
||||
|
||||
data List (a) where
|
||||
Nil : List (a)
|
||||
Cons : a -> List (a) -> List (a)
|
||||
|
||||
-- create a list of x to 0
|
||||
revRange x = case x of
|
||||
0 => Cons x Nil
|
||||
x => Cons x (revRange (x + minusOne))
|
||||
|
||||
-- represents minus one :)
|
||||
minusOne : Int ;
|
||||
minusOne = 9223372036854775807 + 9223372036854775807 + 1;
|
||||
|
|
@ -2,17 +2,14 @@ module Codegen.CompilerState where
|
|||
|
||||
import Auxiliary (snoc)
|
||||
import Codegen.Auxillary (type2LlvmType, typeByteSize)
|
||||
import Codegen.LlvmIr as LIR (LLVMIr (UnsafeRaw), LLVMType)
|
||||
import Control.Monad.State (
|
||||
StateT,
|
||||
gets,
|
||||
modify,
|
||||
)
|
||||
import Codegen.LlvmIr as LIR (LLVMIr (UnsafeRaw),
|
||||
LLVMType)
|
||||
import Control.Monad.State (StateT, gets, modify)
|
||||
import Data.Map (Map)
|
||||
import Data.Map qualified as Map
|
||||
import qualified Data.Map as Map
|
||||
import Grammar.ErrM (Err)
|
||||
import Monomorphizer.MonomorphizerIr as MIR
|
||||
import TypeChecker.TypeCheckerIr qualified as TIR
|
||||
import qualified TypeChecker.TypeCheckerIr as TIR
|
||||
|
||||
-- | The record used as the code generator state
|
||||
data CodeGenerator = CodeGenerator
|
||||
|
|
@ -146,4 +143,5 @@ gcStart =
|
|||
, UnsafeRaw "declare external void @cheap_dispose()\n"
|
||||
, UnsafeRaw "declare external ptr @cheap_the()\n"
|
||||
, UnsafeRaw "declare external void @cheap_set_profiler(ptr, i1)\n"
|
||||
, UnsafeRaw "declare external void @cheap_profiler_log_options(ptr, i64)\n"
|
||||
]
|
||||
|
|
@ -8,18 +8,15 @@ import Codegen.CompilerState
|
|||
import Codegen.LlvmIr as LIR
|
||||
import Control.Applicative ((<|>))
|
||||
import Control.Monad (when)
|
||||
import Control.Monad.State (
|
||||
gets,
|
||||
modify,
|
||||
)
|
||||
import Data.Bifunctor qualified as BI
|
||||
import Control.Monad.State (gets, modify)
|
||||
import qualified Data.Bifunctor as BI
|
||||
import Data.Char (ord)
|
||||
import Data.Coerce (coerce)
|
||||
import Data.Map qualified as Map
|
||||
import qualified Data.Map as Map
|
||||
import Data.Maybe (fromJust, fromMaybe)
|
||||
import Data.Tuple.Extra (dupe, first, second)
|
||||
import Monomorphizer.MonomorphizerIr as MIR
|
||||
import TypeChecker.TypeCheckerIr qualified as TIR
|
||||
import qualified TypeChecker.TypeCheckerIr as TIR
|
||||
|
||||
compileScs :: [MIR.Def] -> CompilerState ()
|
||||
compileScs [] = do
|
||||
|
|
@ -132,6 +129,7 @@ firstMainContent :: Bool -> [LLVMIr]
|
|||
firstMainContent True =
|
||||
[ UnsafeRaw "%prof = call ptr @cheap_the()\n"
|
||||
, UnsafeRaw "call void @cheap_set_profiler(ptr %prof, i1 true)\n"
|
||||
, UnsafeRaw "call void @cheap_profiler_log_options(ptr %prof, i64 30)\n"
|
||||
, UnsafeRaw "call void @cheap_init()\n"
|
||||
]
|
||||
firstMainContent False = []
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
module Compiler (compile) where
|
||||
|
||||
import System.Process.Extra (
|
||||
readCreateProcess,
|
||||
shell,
|
||||
)
|
||||
import System.Process.Extra (readCreateProcess, shell)
|
||||
|
||||
-- spawnWait s = spawnCommand s >>= \s >>= waitForProcess
|
||||
|
||||
|
|
@ -31,7 +28,9 @@ compileClang True =
|
|||
, "src/GC/lib/event.cpp"
|
||||
, "src/GC/lib/heap.cpp"
|
||||
, "src/GC/lib/profiler.cpp"
|
||||
, "-Wall -Wextra -g -std=gnu++20 -stdlib=libstdc++ -O3"
|
||||
, "-Wall -Wextra -g -std=gnu++20 -stdlib=libstdc++"
|
||||
, "-O3"
|
||||
--, "-tailcallopt"
|
||||
, "-Isrc/GC/include"
|
||||
, "-x"
|
||||
, "ir" -- , "-Lsrc/GC/lib -l:gcoll.a"
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define WRAPPER_DEBUG
|
||||
//#define WRAPPER_DEBUG
|
||||
|
||||
#ifdef WRAPPER_DEBUG
|
||||
typedef struct cheap
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
#include "chunk.hpp"
|
||||
#include "profiler.hpp"
|
||||
|
||||
#define HEAP_SIZE 65536
|
||||
#define HEAP_SIZE 240240240
|
||||
#define FREE_THRESH (uint)100
|
||||
#define HEAP_DEBUG
|
||||
|
||||
|
|
@ -17,7 +17,8 @@ namespace GC
|
|||
* Flags for the collect overlead for conditional
|
||||
* collection (mark/sweep/free/all).
|
||||
*/
|
||||
enum CollectOption {
|
||||
enum CollectOption
|
||||
{
|
||||
MARK = 1 << 0,
|
||||
SWEEP = 1 << 1,
|
||||
MARK_SWEEP = 1 << 2,
|
||||
|
|
@ -69,6 +70,7 @@ namespace GC
|
|||
// Temporary
|
||||
Chunk *try_recycle_chunks_new(size_t size);
|
||||
void free_overlap_new(Heap &heap);
|
||||
|
||||
public:
|
||||
/**
|
||||
* These are the only five functions which are exposed
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue