~jojo/Carth

d93637f4e578208451b8af1a374927e1ab84f78d — JoJo 1 year, 11 months ago f1a780c
Add primitive types Nat,{Nat,Int}{8,16,32}

Useful for FFI. No way of constructing them or casting between them
yet (except for FFI).
3 files changed, 28 insertions(+), 0 deletions(-)

M src/Ast.hs
M src/Codegen.hs
M src/Parse.hs
M src/Ast.hs => src/Ast.hs +14 -0
@@ 49,6 49,13 @@ data TVar

data TPrim
    = TUnit
    | TNat8
    | TNat16
    | TNat32
    | TNat
    | TInt8
    | TInt16
    | TInt32
    | TInt
    | TDouble
    | TChar


@@ 320,6 327,13 @@ prettyTFun a b =
prettyTPrim :: TPrim -> String
prettyTPrim = \case
    TUnit -> "Unit"
    TNat8 -> "Nat8"
    TNat16 -> "Nat16"
    TNat32 -> "Nat32"
    TNat -> "Nat"
    TInt8 -> "Int8"
    TInt16 -> "Int16"
    TInt32 -> "Int32"
    TInt -> "Int"
    TDouble -> "Double"
    TChar -> "Char"

M src/Codegen.hs => src/Codegen.hs +7 -0
@@ 282,6 282,13 @@ toLlvmType :: MonoAst.Type -> Type
toLlvmType = \case
    TPrim tc -> case tc of
        TUnit -> typeUnit
        TNat8 -> i8
        TNat16 -> i16
        TNat32 -> i32
        TNat -> i64
        TInt8 -> i8
        TInt16 -> i16
        TInt32 -> i32
        TInt -> i64
        TDouble -> double
        TChar -> i32

M src/Parse.hs => src/Parse.hs +7 -0
@@ 262,6 262,13 @@ ns_tprim = try $ do
    s <- ns_big
    case s of
        "Unit" -> pure TUnit
        "Nat8" -> pure TNat8
        "Nat16" -> pure TNat16
        "Nat32" -> pure TNat32
        "Nat" -> pure TNat
        "Int8" -> pure TInt8
        "Int16" -> pure TInt16
        "Int32" -> pure TInt32
        "Int" -> pure TInt
        "Double" -> pure TDouble
        "Char" -> pure TChar