aboutsummaryrefslogtreecommitdiff
path: root/backend/CC/Backend/Dumb.hs
blob: b7703d7178f149ee7c8948af5a3e932e123978f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module CC.Backend.Dumb(builtins) where

import qualified Data.Map.Strict as Map

import CC.AST.Typed
import CC.Context


builtins :: Builtins
builtins =
    let values = Map.fromList
            [ ("print", TInt ==> TTup [])
            , ("fst", TTup [t1, t2] ==> t1)
            , ("snd", TTup [t1, t2] ==> t2)
            , ("_add", TInt ==> TInt ==> TInt)
            , ("_sub", TInt ==> TInt ==> TInt)
            , ("_mul", TInt ==> TInt ==> TInt) ]
        prelude = "type Nil = ()\n\
                  \type Cons a = (a, List a)\n\
                  \alias List a = { Nil | Cons a }\n\
                  \cons :: a -> List a -> Cons a\n\
                  \cons x l = Cons (x, l)\n\
                  \nil :: Nil\n\
                  \nil = Nil ()\n"
    in Builtins values prelude
  where
    t1 = TyVar Instantiable 1
    t2 = TyVar Instantiable 2
    infixr ==>
    (==>) = TFun