@@ -30,8 +30,15 @@ ref = E.ref
3030eOp :: EOp -> ([E.Name], ETm)
3131eOp op = ([E.name "x", E.name "y"], E.op_ op (E.fn "x") (E.fn "y"))
3232
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)])
36+
3337strToInt x = foreign_ tyInt "strToInt" [(x, tyString)]
3438intToStr 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)]
3542strToFloat x = foreign_ tyFloat "strToFloat" [(x, tyString)]
3643floatToStr x = foreign_ tyString "floatToStr" [(x, tyFloat)]
3744intToFloat x = foreign_ tyFloat "intToFloat" [(x, tyInt)]
@@ -60,6 +67,24 @@ primitives =
6067 (eOp E.gt_),
6168 Prim (UN ["prim__gteInt"]) (ty [IType, IType] IType) 2 (biBin (>=))
6269 (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"),
6388 Prim (UN ["prim__addFloat"]) (ty [FlType, FlType] FlType) 2 (fBin (+))
6489 (eOp E.plusF_),
6590 Prim (UN ["prim__subFloat"]) (ty [FlType, FlType] FlType) 2 (fBin (-))
@@ -85,6 +110,12 @@ primitives =
85110 ([E.name "x"], strToInt (fun "x")),
86111 Prim (UN ["prim__intToStr"]) (ty [IType] StrType) 1 (c_intToStr)
87112 ([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")),
88119 Prim (UN ["prim__strToFloat"]) (ty [StrType] FlType) 1 (c_strToFloat)
89120 ([E.name "x"], strToFloat (fun "x")),
90121 Prim (UN ["prim__floatToStr"]) (ty [FlType] StrType) 1 (c_floatToStr)
@@ -102,7 +133,14 @@ primitives =
102133iBin op [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (op x y))
103134iBin _ _ = Nothing
104135
136+bBin op [VConstant (BI x), VConstant (BI y)] = Just $ VConstant (BI (op x y))
137+bBin _ _ = Nothing
138+
139+bBini op [VConstant (BI x), VConstant (BI y)] = Just $ VConstant (I (op x y))
140+bBini _ _ = Nothing
141+
105142biBin 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)
106144
107145fBin op [VConstant (Fl x), VConstant (Fl y)] = Just $ VConstant (Fl (op x y))
108146fBin _ _ = Nothing
@@ -119,6 +157,14 @@ c_intToStr _ = Nothing
119157c_strToInt [VConstant (Str x)] = Just $ VConstant (I (read x))
120158c_strToInt _ = Nothing
121159
160+c_intToBigInt [VConstant (I x)] = Just $ VConstant (BI (fromIntegral x))
161+c_intToBigInt _ = Nothing
162+
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
167+
122168c_floatToStr [VConstant (Fl x)] = Just $ VConstant (Str (show x))
123169c_floatToStr _ = Nothing
124170c_strToFloat [VConstant (Str x)] = Just $ VConstant (Fl (read x))