@@ -48,6 +48,12 @@ floatToInt x = foreign_ tyInt "floatToInt" [(x, tyFloat)]
48floatExp x = foreign_ tyFloat "exp" [(x, tyFloat)]
48floatExp x = foreign_ tyFloat "exp" [(x, tyFloat)]
49floatLog x = foreign_ tyFloat "log" [(x, tyFloat)]
49floatLog x = foreign_ tyFloat "log" [(x, tyFloat)]
51+strIndex x i = foreign_ tyChar "strIndex" [(x, tyString), (i, tyInt)]
52+strHead x = foreign_ tyChar "strHead" [(x, tyString)]
53+strTail x = foreign_ tyString "strTail" [(x, tyString)]
54+strCons x xs = foreign_ tyString "strCons" [(x, tyChar), (xs, tyString)]
55+strRev x = foreign_ tyString "strrev" [(x, tyString)]
51primitives =
57primitives =
52 -- operators
58 -- operators
53 [Prim (UN "prim__addInt") (ty [IType, IType] IType) 2 (iBin (+))
59 [Prim (UN "prim__addInt") (ty [IType, IType] IType) 2 (iBin (+))
@@ -128,7 +134,17 @@ primitives =
128 Prim (UN "prim__floatExp") (ty [FlType] FlType) 1 (p_floatExp)
134 Prim (UN "prim__floatExp") (ty [FlType] FlType) 1 (p_floatExp)
129 ([E.name "x"], floatExp (fun "x")),
135 ([E.name "x"], floatExp (fun "x")),
130 Prim (UN "prim__floatLog") (ty [FlType] FlType) 1 (p_floatLog)
136 Prim (UN "prim__floatLog") (ty [FlType] FlType) 1 (p_floatLog)
131− ([E.name "x"], floatLog (fun "x"))
137+ ([E.name "x"], floatLog (fun "x")),
138+ Prim (UN "prim__strHead") (ty [StrType] ChType) 1 (p_strHead)
139+ ([E.name "x"], strHead (fun "x")),
140+ Prim (UN "prim__strTail") (ty [StrType] StrType) 1 (p_strTail)
141+ ([E.name "x"], strTail (fun "x")),
142+ Prim (UN "prim__strCons") (ty [ChType, StrType] StrType) 2 (p_strCons)
143+ ([E.name "x", E.name "xs"], strCons (fun "x") (fun "xs")),
144+ Prim (UN "prim__strIndex") (ty [StrType, IType] ChType) 2 (p_strIndex)
145+ ([E.name "x", E.name "i"], strIndex (fun "x") (fun "i")),
146+ Prim (UN "prim__strRev") (ty [StrType] StrType) 1 (p_strRev)
147+ ([E.name "x"], strRev (fun "x"))
134iBin op [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (op x y))
150iBin op [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (op x y))
@@ -182,6 +198,18 @@ p_floatExp _ = Nothing
182p_floatLog [VConstant (Fl x)] = Just $ VConstant (Fl (log x))
198p_floatLog [VConstant (Fl x)] = Just $ VConstant (Fl (log x))
183p_floatLog _ = Nothing
199p_floatLog _ = Nothing
201+p_strHead [VConstant (Str (x:xs))] = Just $ VConstant (Ch x)
202+p_strHead _ = Nothing
203+p_strTail [VConstant (Str (x:xs))] = Just $ VConstant (Str xs)
204+p_strTail _ = Nothing
205+p_strIndex [VConstant (Str xs), VConstant (I i)]
206+ | i < length xs = Just $ VConstant (Ch (xs!!i))
207+p_strIndex _ = Nothing
208+p_strCons [VConstant (Ch x), VConstant (Str xs)] = Just $ VConstant (Str (x:xs))
209+p_strCons _ = Nothing
210+p_strRev [VConstant (Str xs)] = Just $ VConstant (Str (reverse xs))
185elabPrim :: Prim -> Idris ()
213elabPrim :: Prim -> Idris ()
186elabPrim (Prim n ty i def epic)
214elabPrim (Prim n ty i def epic)
187 = do updateContext (addOperator n ty i def)
215 = do updateContext (addOperator n ty i def)