1module Idris.Primitives(elabPrims) where
9data Prim = Prim { p_name :: Name,
12 p_def :: [Value] -> Maybe Value
16ty (t:ts) x = Bind (MN 0 "T") (Pi (Constant t)) (ty ts x)
19 [Prim (UN ["prim__addInt"]) (ty [IType, IType] IType) 2 (iBin (+)),
20 Prim (UN ["prim__subInt"]) (ty [IType, IType] IType) 2 (iBin (-)),
21 Prim (UN ["prim__mulInt"]) (ty [IType, IType] IType) 2 (iBin (*)),
22 Prim (UN ["prim__divInt"]) (ty [IType, IType] IType) 2 (iBin (div)),
23 Prim (UN ["prim__eqInt"]) (ty [IType, IType] IType) 2 (biBin (==)),
24 Prim (UN ["prim__ltInt"]) (ty [IType, IType] IType) 2 (biBin (<)),
25 Prim (UN ["prim__lteInt"]) (ty [IType, IType] IType) 2 (biBin (<=)),
26 Prim (UN ["prim__gtInt"]) (ty [IType, IType] IType) 2 (biBin (>)),
27 Prim (UN ["prim__gteInt"]) (ty [IType, IType] IType) 2 (biBin (>=)),
28 Prim (UN ["prim__addFloat"]) (ty [FlType, FlType] FlType) 2 (fBin (+)),
29 Prim (UN ["prim__subFloat"]) (ty [FlType, FlType] FlType) 2 (fBin (-)),
30 Prim (UN ["prim__mulFloat"]) (ty [FlType, FlType] FlType) 2 (fBin (*)),
31 Prim (UN ["prim__divFloat"]) (ty [FlType, FlType] FlType) 2 (fBin (/)),
32 Prim (UN ["prim__eqFloat"]) (ty [FlType, FlType] IType) 2 (bfBin (==)),
33 Prim (UN ["prim__ltFloat"]) (ty [FlType, FlType] IType) 2 (bfBin (<)),
34 Prim (UN ["prim__lteFloat"]) (ty [FlType, FlType] IType) 2 (bfBin (<=)),
35 Prim (UN ["prim__gtFloat"]) (ty [FlType, FlType] IType) 2 (bfBin (>)),
36 Prim (UN ["prim__gteFloat"]) (ty [FlType, FlType] IType) 2 (bfBin (>=))
39iBin op [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (op x y))
42biBin op = iBin (\x y -> if (op x y) then 1 else 0)
44fBin op [VConstant (Fl x), VConstant (Fl y)] = Just $ VConstant (Fl (op x y))
47bfBin op [VConstant (Fl x), VConstant (Fl y)] = let i = (if op x y then 1 else 0) in
48 Just $ VConstant (I i)
51elabPrim :: Prim -> Idris ()
52elabPrim (Prim n ty i def) = updateContext (addOperator n ty i def)
55elabPrims = do elabDecl toplevel (PData inferDecl)
56 mapM_ elabPrim primitives
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list