@@ -1,3 +1,5 @@
1+{-# LANGUAGE RankNTypes, ScopedTypeVariables #-}
1module Idris.Primitives(elabPrims) where
3module Idris.Primitives(elabPrims) where
3import Idris.ElabDecls
5import Idris.ElabDecls
@@ -6,35 +8,67 @@ import Idris.AbsSyntax
6import Core.TT
8import Core.TT
7import Core.Evaluate
9import Core.Evaluate
11+import Epic.Epic hiding (Term, Type, Name, fn)
12+import qualified Epic.Epic as E
9data Prim = Prim { p_name :: Name,
14data Prim = Prim { p_name :: Name,
10 p_type :: Type,
15 p_type :: Type,
11 p_arity :: Int,
16 p_arity :: Int,
12− p_def :: [Value] -> Maybe Value
17+ p_def :: [Value] -> Maybe Value,
18+ p_epic :: ([E.Name], E.Term)
15ty [] x = Constant x
21ty [] x = Constant x
16ty (t:ts) x = Bind (MN 0 "T") (Pi (Constant t)) (ty ts x)
22ty (t:ts) x = Bind (MN 0 "T") (Pi (Constant t)) (ty ts x)
30+eOp :: EOp -> ([E.Name], ETm)
31+eOp op = ([E.name "x", E.name "y"], E.op_ op (E.fn "x") (E.fn "y"))
18primitives =
33primitives =
19− [Prim (UN ["prim__addInt"]) (ty [IType, IType] IType) 2 (iBin (+)),
34+ [Prim (UN ["prim__addInt"]) (ty [IType, IType] IType) 2 (iBin (+))
20− Prim (UN ["prim__subInt"]) (ty [IType, IType] IType) 2 (iBin (-)),
36+ Prim (UN ["prim__subInt"]) (ty [IType, IType] IType) 2 (iBin (-))
21− Prim (UN ["prim__mulInt"]) (ty [IType, IType] IType) 2 (iBin (*)),
38+ Prim (UN ["prim__mulInt"]) (ty [IType, IType] IType) 2 (iBin (*))
22− Prim (UN ["prim__divInt"]) (ty [IType, IType] IType) 2 (iBin (div)),
40+ Prim (UN ["prim__divInt"]) (ty [IType, IType] IType) 2 (iBin (div))
23− Prim (UN ["prim__eqInt"]) (ty [IType, IType] IType) 2 (biBin (==)),
42+ Prim (UN ["prim__eqInt"]) (ty [IType, IType] IType) 2 (biBin (==))
24− Prim (UN ["prim__ltInt"]) (ty [IType, IType] IType) 2 (biBin (<)),
44+ Prim (UN ["prim__ltInt"]) (ty [IType, IType] IType) 2 (biBin (<))
25− Prim (UN ["prim__lteInt"]) (ty [IType, IType] IType) 2 (biBin (<=)),
46+ Prim (UN ["prim__lteInt"]) (ty [IType, IType] IType) 2 (biBin (<=))
26− Prim (UN ["prim__gtInt"]) (ty [IType, IType] IType) 2 (biBin (>)),
48+ Prim (UN ["prim__gtInt"]) (ty [IType, IType] IType) 2 (biBin (>))
27− Prim (UN ["prim__gteInt"]) (ty [IType, IType] IType) 2 (biBin (>=)),
50+ Prim (UN ["prim__gteInt"]) (ty [IType, IType] IType) 2 (biBin (>=))
28− Prim (UN ["prim__addFloat"]) (ty [FlType, FlType] FlType) 2 (fBin (+)),
52+ Prim (UN ["prim__addFloat"]) (ty [FlType, FlType] FlType) 2 (fBin (+))
29− Prim (UN ["prim__subFloat"]) (ty [FlType, FlType] FlType) 2 (fBin (-)),
54+ Prim (UN ["prim__subFloat"]) (ty [FlType, FlType] FlType) 2 (fBin (-))
30− Prim (UN ["prim__mulFloat"]) (ty [FlType, FlType] FlType) 2 (fBin (*)),
56+ Prim (UN ["prim__mulFloat"]) (ty [FlType, FlType] FlType) 2 (fBin (*))
31− Prim (UN ["prim__divFloat"]) (ty [FlType, FlType] FlType) 2 (fBin (/)),
58+ Prim (UN ["prim__divFloat"]) (ty [FlType, FlType] FlType) 2 (fBin (/))
32− Prim (UN ["prim__eqFloat"]) (ty [FlType, FlType] IType) 2 (bfBin (==)),
60+ Prim (UN ["prim__eqFloat"]) (ty [FlType, FlType] IType) 2 (bfBin (==))
33− Prim (UN ["prim__ltFloat"]) (ty [FlType, FlType] IType) 2 (bfBin (<)),
62+ Prim (UN ["prim__ltFloat"]) (ty [FlType, FlType] IType) 2 (bfBin (<))
34− Prim (UN ["prim__lteFloat"]) (ty [FlType, FlType] IType) 2 (bfBin (<=)),
64+ Prim (UN ["prim__lteFloat"]) (ty [FlType, FlType] IType) 2 (bfBin (<=))
35− Prim (UN ["prim__gtFloat"]) (ty [FlType, FlType] IType) 2 (bfBin (>)),
66+ Prim (UN ["prim__gtFloat"]) (ty [FlType, FlType] IType) 2 (bfBin (>))
36− Prim (UN ["prim__gteFloat"]) (ty [FlType, FlType] IType) 2 (bfBin (>=)),
68+ Prim (UN ["prim__gteFloat"]) (ty [FlType, FlType] IType) 2 (bfBin (>=))
37 Prim (UN ["prim__concat"]) (ty [StrType, StrType] StrType) 2 (sBin (++))
70 Prim (UN ["prim__concat"]) (ty [StrType, StrType] StrType) 2 (sBin (++))
71+ ([E.name "x", E.name "y"], (fun "append") @@ fun "x" @@ fun "y")
40iBin op [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (op x y))
74iBin op [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (op x y))
@@ -53,7 +87,10 @@ sBin op [VConstant (Str x), VConstant (Str y)] = Just $ VConstant (Str (op x y))
53sBin _ _ = Nothing
87sBin _ _ = Nothing
55elabPrim :: Prim -> Idris ()
89elabPrim :: Prim -> Idris ()
90+elabPrim (Prim n ty i def epic)
56−elabPrim (Prim n ty i def) = updateContext (addOperator n ty i def)
91+ = do updateContext (addOperator n ty i def)
93+ putIState i { idris_prims = (n, epic) : idris_prims i }
58elabPrims :: Idris ()
95elabPrims :: Idris ()
59elabPrims = do mapM_ (elabDecl toplevel)
96elabPrims = do mapM_ (elabDecl toplevel)