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 => xs
|
||||||
Nil => Nil
|
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
|
head xs = case xs of
|
||||||
Cons x _ => x
|
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 Auxiliary (snoc)
|
||||||
import Codegen.Auxillary (type2LlvmType, typeByteSize)
|
import Codegen.Auxillary (type2LlvmType, typeByteSize)
|
||||||
import Codegen.LlvmIr as LIR (LLVMIr (UnsafeRaw), LLVMType)
|
import Codegen.LlvmIr as LIR (LLVMIr (UnsafeRaw),
|
||||||
import Control.Monad.State (
|
LLVMType)
|
||||||
StateT,
|
import Control.Monad.State (StateT, gets, modify)
|
||||||
gets,
|
|
||||||
modify,
|
|
||||||
)
|
|
||||||
import Data.Map (Map)
|
import Data.Map (Map)
|
||||||
import Data.Map qualified as Map
|
import qualified Data.Map as Map
|
||||||
import Grammar.ErrM (Err)
|
import Grammar.ErrM (Err)
|
||||||
import Monomorphizer.MonomorphizerIr as MIR
|
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
|
-- | The record used as the code generator state
|
||||||
data CodeGenerator = CodeGenerator
|
data CodeGenerator = CodeGenerator
|
||||||
|
|
@ -146,4 +143,5 @@ gcStart =
|
||||||
, UnsafeRaw "declare external void @cheap_dispose()\n"
|
, UnsafeRaw "declare external void @cheap_dispose()\n"
|
||||||
, UnsafeRaw "declare external ptr @cheap_the()\n"
|
, UnsafeRaw "declare external ptr @cheap_the()\n"
|
||||||
, UnsafeRaw "declare external void @cheap_set_profiler(ptr, i1)\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 Codegen.LlvmIr as LIR
|
||||||
import Control.Applicative ((<|>))
|
import Control.Applicative ((<|>))
|
||||||
import Control.Monad (when)
|
import Control.Monad (when)
|
||||||
import Control.Monad.State (
|
import Control.Monad.State (gets, modify)
|
||||||
gets,
|
import qualified Data.Bifunctor as BI
|
||||||
modify,
|
|
||||||
)
|
|
||||||
import Data.Bifunctor qualified as BI
|
|
||||||
import Data.Char (ord)
|
import Data.Char (ord)
|
||||||
import Data.Coerce (coerce)
|
import Data.Coerce (coerce)
|
||||||
import Data.Map qualified as Map
|
import qualified Data.Map as Map
|
||||||
import Data.Maybe (fromJust, fromMaybe)
|
import Data.Maybe (fromJust, fromMaybe)
|
||||||
import Data.Tuple.Extra (dupe, first, second)
|
import Data.Tuple.Extra (dupe, first, second)
|
||||||
import Monomorphizer.MonomorphizerIr as MIR
|
import Monomorphizer.MonomorphizerIr as MIR
|
||||||
import TypeChecker.TypeCheckerIr qualified as TIR
|
import qualified TypeChecker.TypeCheckerIr as TIR
|
||||||
|
|
||||||
compileScs :: [MIR.Def] -> CompilerState ()
|
compileScs :: [MIR.Def] -> CompilerState ()
|
||||||
compileScs [] = do
|
compileScs [] = do
|
||||||
|
|
@ -132,6 +129,7 @@ firstMainContent :: Bool -> [LLVMIr]
|
||||||
firstMainContent True =
|
firstMainContent True =
|
||||||
[ UnsafeRaw "%prof = call ptr @cheap_the()\n"
|
[ UnsafeRaw "%prof = call ptr @cheap_the()\n"
|
||||||
, UnsafeRaw "call void @cheap_set_profiler(ptr %prof, i1 true)\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"
|
, UnsafeRaw "call void @cheap_init()\n"
|
||||||
]
|
]
|
||||||
firstMainContent False = []
|
firstMainContent False = []
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
module Compiler (compile) where
|
module Compiler (compile) where
|
||||||
|
|
||||||
import System.Process.Extra (
|
import System.Process.Extra (readCreateProcess, shell)
|
||||||
readCreateProcess,
|
|
||||||
shell,
|
|
||||||
)
|
|
||||||
|
|
||||||
-- spawnWait s = spawnCommand s >>= \s >>= waitForProcess
|
-- spawnWait s = spawnCommand s >>= \s >>= waitForProcess
|
||||||
|
|
||||||
|
|
@ -31,7 +28,9 @@ compileClang True =
|
||||||
, "src/GC/lib/event.cpp"
|
, "src/GC/lib/event.cpp"
|
||||||
, "src/GC/lib/heap.cpp"
|
, "src/GC/lib/heap.cpp"
|
||||||
, "src/GC/lib/profiler.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"
|
, "-Isrc/GC/include"
|
||||||
, "-x"
|
, "-x"
|
||||||
, "ir" -- , "-Lsrc/GC/lib -l:gcoll.a"
|
, "ir" -- , "-Lsrc/GC/lib -l:gcoll.a"
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define WRAPPER_DEBUG
|
//#define WRAPPER_DEBUG
|
||||||
|
|
||||||
#ifdef WRAPPER_DEBUG
|
#ifdef WRAPPER_DEBUG
|
||||||
typedef struct cheap
|
typedef struct cheap
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@
|
||||||
#include "chunk.hpp"
|
#include "chunk.hpp"
|
||||||
#include "profiler.hpp"
|
#include "profiler.hpp"
|
||||||
|
|
||||||
#define HEAP_SIZE 65536
|
#define HEAP_SIZE 240240240
|
||||||
#define FREE_THRESH (uint) 100
|
#define FREE_THRESH (uint)100
|
||||||
#define HEAP_DEBUG
|
#define HEAP_DEBUG
|
||||||
|
|
||||||
namespace GC
|
namespace GC
|
||||||
|
|
@ -17,7 +17,8 @@ namespace GC
|
||||||
* Flags for the collect overlead for conditional
|
* Flags for the collect overlead for conditional
|
||||||
* collection (mark/sweep/free/all).
|
* collection (mark/sweep/free/all).
|
||||||
*/
|
*/
|
||||||
enum CollectOption {
|
enum CollectOption
|
||||||
|
{
|
||||||
MARK = 1 << 0,
|
MARK = 1 << 0,
|
||||||
SWEEP = 1 << 1,
|
SWEEP = 1 << 1,
|
||||||
MARK_SWEEP = 1 << 2,
|
MARK_SWEEP = 1 << 2,
|
||||||
|
|
@ -44,11 +45,11 @@ namespace GC
|
||||||
}
|
}
|
||||||
|
|
||||||
char *const m_heap;
|
char *const m_heap;
|
||||||
size_t m_size {0};
|
size_t m_size{0};
|
||||||
char *m_heap_top {nullptr};
|
char *m_heap_top{nullptr};
|
||||||
// static Heap *m_instance {nullptr};
|
// static Heap *m_instance {nullptr};
|
||||||
uintptr_t *m_stack_top {nullptr};
|
uintptr_t *m_stack_top{nullptr};
|
||||||
bool m_profiler_enable {false};
|
bool m_profiler_enable{false};
|
||||||
|
|
||||||
std::vector<Chunk *> m_allocated_chunks;
|
std::vector<Chunk *> m_allocated_chunks;
|
||||||
std::vector<Chunk *> m_freed_chunks;
|
std::vector<Chunk *> m_freed_chunks;
|
||||||
|
|
@ -69,6 +70,7 @@ namespace GC
|
||||||
// Temporary
|
// Temporary
|
||||||
Chunk *try_recycle_chunks_new(size_t size);
|
Chunk *try_recycle_chunks_new(size_t size);
|
||||||
void free_overlap_new(Heap &heap);
|
void free_overlap_new(Heap &heap);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* These are the only five functions which are exposed
|
* These are the only five functions which are exposed
|
||||||
|
|
@ -86,8 +88,8 @@ namespace GC
|
||||||
void set_profiler_log_options(RecordOption flags);
|
void set_profiler_log_options(RecordOption flags);
|
||||||
|
|
||||||
// Stop the compiler from generating copy-methods
|
// Stop the compiler from generating copy-methods
|
||||||
Heap(Heap const&) = delete;
|
Heap(Heap const &) = delete;
|
||||||
Heap& operator=(Heap const&) = delete;
|
Heap &operator=(Heap const &) = delete;
|
||||||
|
|
||||||
#ifdef HEAP_DEBUG
|
#ifdef HEAP_DEBUG
|
||||||
void collect(CollectOption flags); // conditional collection
|
void collect(CollectOption flags); // conditional collection
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue