@@ -30,8 +30,15 @@ ref = E.ref
30eOp :: EOp -> ([E.Name], ETm)
30eOp :: EOp -> ([E.Name], ETm)
31eOp op = ([E.name "x", E.name "y"], E.op_ op (E.fn "x") (E.fn "y"))
31eOp op = ([E.name "x", E.name "y"], E.op_ op (E.fn "x") (E.fn "y"))
33+eOpFn :: E.Type -> E.Type -> String -> ([E.Name], ETm)
34+eOpFn ty rty op = ([E.name "x", E.name "y"],
35+ foreign_ rty op [(E.fn "x", ty), (E.fn "y", ty)])
33strToInt x = foreign_ tyInt "strToInt" [(x, tyString)]
37strToInt x = foreign_ tyInt "strToInt" [(x, tyString)]
34intToStr x = foreign_ tyString "intToStr" [(x, tyInt)]
38intToStr x = foreign_ tyString "intToStr" [(x, tyInt)]
39+intToBigInt x = foreign_ tyBigInt "intToBigInt" [(x, tyInt)]
40+strToBigInt x = foreign_ tyBigInt "strToBig" [(x, tyString)]
41+bigIntToStr x = foreign_ tyString "bigToStr" [(x, tyBigInt)]
35strToFloat x = foreign_ tyFloat "strToFloat" [(x, tyString)]
42strToFloat x = foreign_ tyFloat "strToFloat" [(x, tyString)]
36floatToStr x = foreign_ tyString "floatToStr" [(x, tyFloat)]
43floatToStr x = foreign_ tyString "floatToStr" [(x, tyFloat)]
37intToFloat x = foreign_ tyFloat "intToFloat" [(x, tyInt)]
44intToFloat x = foreign_ tyFloat "intToFloat" [(x, tyInt)]
@@ -60,6 +67,24 @@ primitives =
60 (eOp E.gt_),
67 (eOp E.gt_),
61 Prim (UN ["prim__gteInt"]) (ty [IType, IType] IType) 2 (biBin (>=))
68 Prim (UN ["prim__gteInt"]) (ty [IType, IType] IType) 2 (biBin (>=))
62 (eOp E.gte_),
69 (eOp E.gte_),
70+ Prim (UN ["prim__addBigInt"]) (ty [BIType, BIType] BIType) 2 (bBin (+))
71+ (eOpFn tyBigInt tyBigInt "addBig"),
72+ Prim (UN ["prim__subBigInt"]) (ty [BIType, BIType] BIType) 2 (bBin (-))
73+ (eOpFn tyBigInt tyBigInt "subBig"),
74+ Prim (UN ["prim__mulBigInt"]) (ty [BIType, BIType] BIType) 2 (bBin (*))
75+ (eOpFn tyBigInt tyBigInt "mulBig"),
76+ Prim (UN ["prim__divBigInt"]) (ty [BIType, BIType] BIType) 2 (bBin (div))
77+ (eOpFn tyBigInt tyBigInt "divBig"),
78+ Prim (UN ["prim__eqBigInt"]) (ty [BIType, BIType] IType) 2 (bbBin (==))
79+ (eOpFn tyBigInt tyInt "eqBig"),
80+ Prim (UN ["prim__ltBigInt"]) (ty [BIType, BIType] IType) 2 (bbBin (<))
81+ (eOpFn tyBigInt tyInt "ltBig"),
82+ Prim (UN ["prim__lteBigInt"]) (ty [BIType, BIType] IType) 2 (bbBin (<=))
83+ (eOpFn tyBigInt tyInt "leBig"),
84+ Prim (UN ["prim__gtBigInt"]) (ty [BIType, BIType] IType) 2 (bbBin (>))
85+ (eOpFn tyBigInt tyInt "gtBig"),
86+ Prim (UN ["prim__gtBigInt"]) (ty [BIType, BIType] IType) 2 (bbBin (>=))
87+ (eOpFn tyBigInt tyInt "geBig"),
63 Prim (UN ["prim__addFloat"]) (ty [FlType, FlType] FlType) 2 (fBin (+))
88 Prim (UN ["prim__addFloat"]) (ty [FlType, FlType] FlType) 2 (fBin (+))
64 (eOp E.plusF_),
89 (eOp E.plusF_),
65 Prim (UN ["prim__subFloat"]) (ty [FlType, FlType] FlType) 2 (fBin (-))
90 Prim (UN ["prim__subFloat"]) (ty [FlType, FlType] FlType) 2 (fBin (-))
@@ -85,6 +110,12 @@ primitives =
85 ([E.name "x"], strToInt (fun "x")),
110 ([E.name "x"], strToInt (fun "x")),
86 Prim (UN ["prim__intToStr"]) (ty [IType] StrType) 1 (c_intToStr)
111 Prim (UN ["prim__intToStr"]) (ty [IType] StrType) 1 (c_intToStr)
87 ([E.name "x"], intToStr (fun "x")),
112 ([E.name "x"], intToStr (fun "x")),
113+ Prim (UN ["prim__intToBigInt"]) (ty [IType] BIType) 1 (c_intToBigInt)
114+ ([E.name "x"], intToBigInt (fun "x")),
115+ Prim (UN ["prim__strToBigInt"]) (ty [StrType] BIType) 1 (c_strToBigInt)
116+ ([E.name "x"], strToBigInt (fun "x")),
117+ Prim (UN ["prim__bigIntToStr"]) (ty [BIType] StrType) 1 (c_bigIntToStr)
118+ ([E.name "x"], bigIntToStr (fun "x")),
88 Prim (UN ["prim__strToFloat"]) (ty [StrType] FlType) 1 (c_strToFloat)
119 Prim (UN ["prim__strToFloat"]) (ty [StrType] FlType) 1 (c_strToFloat)
89 ([E.name "x"], strToFloat (fun "x")),
120 ([E.name "x"], strToFloat (fun "x")),
90 Prim (UN ["prim__floatToStr"]) (ty [FlType] StrType) 1 (c_floatToStr)
121 Prim (UN ["prim__floatToStr"]) (ty [FlType] StrType) 1 (c_floatToStr)
@@ -102,7 +133,14 @@ primitives =
102iBin op [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (op x y))
133iBin op [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (op x y))
103iBin _ _ = Nothing
134iBin _ _ = Nothing
136+bBin op [VConstant (BI x), VConstant (BI y)] = Just $ VConstant (BI (op x y))
139+bBini op [VConstant (BI x), VConstant (BI y)] = Just $ VConstant (I (op x y))
105biBin op = iBin (\x y -> if (op x y) then 1 else 0)
142biBin op = iBin (\x y -> if (op x y) then 1 else 0)
143+bbBin op = bBini (\x y -> if (op x y) then 1 else 0)
107fBin op [VConstant (Fl x), VConstant (Fl y)] = Just $ VConstant (Fl (op x y))
145fBin op [VConstant (Fl x), VConstant (Fl y)] = Just $ VConstant (Fl (op x y))
108fBin _ _ = Nothing
146fBin _ _ = Nothing
@@ -119,6 +157,14 @@ c_intToStr _ = Nothing
119c_strToInt [VConstant (Str x)] = Just $ VConstant (I (read x))
157c_strToInt [VConstant (Str x)] = Just $ VConstant (I (read x))
120c_strToInt _ = Nothing
158c_strToInt _ = Nothing
160+c_intToBigInt [VConstant (I x)] = Just $ VConstant (BI (fromIntegral x))
161+c_intToBigInt _ = Nothing
163+c_bigIntToStr [VConstant (BI x)] = Just $ VConstant (Str (show x))
164+c_bigIntToStr _ = Nothing
165+c_strToBigInt [VConstant (Str x)] = Just $ VConstant (BI (read x))
166+c_strToBigInt _ = Nothing
122c_floatToStr [VConstant (Fl x)] = Just $ VConstant (Str (show x))
168c_floatToStr [VConstant (Fl x)] = Just $ VConstant (Str (show x))
123c_floatToStr _ = Nothing
169c_floatToStr _ = Nothing
124c_strToFloat [VConstant (Str x)] = Just $ VConstant (Fl (read x))
170c_strToFloat [VConstant (Str x)] = Just $ VConstant (Fl (read x))