@@ -6,6 +6,8 @@ import Idris.ElabDecls
66import Idris.ElabTerm
77import Idris.AbsSyntax
88
9+import RTS.SC
10+
911import Core.TT
1012import Core.Evaluate
1113
@@ -17,6 +19,7 @@ data Prim = Prim { p_name :: Name,
1719 p_arity :: Int,
1820 p_def :: [Value] -> Maybe Value,
1921 p_epic :: ([E.Name], E.Term),
22+ p_sc :: ([CType], CType, SPrim),
2023 p_total :: Totality
2124 }
2225
@@ -79,137 +82,146 @@ partial = Partial NotCovering
7982primitives =
8083 -- operators
8184 [Prim (UN "prim__addInt") (ty [IType, IType] IType) 2 (iBin (+))
82− (eOp E.plus_) total,
85+ (eOp E.plus_) ([sInt, sInt], sInt, AddI) total,
8386 Prim (UN "prim__subInt") (ty [IType, IType] IType) 2 (iBin (-))
84− (eOp E.minus_) total,
87+ (eOp E.minus_)
88+ ([sInt, sInt], sInt, SubI) total,
8589 Prim (UN "prim__mulInt") (ty [IType, IType] IType) 2 (iBin (*))
86− (eOp E.times_) total,
90+ (eOp E.times_) ([sInt, sInt], sInt, MulI) total,
8791 Prim (UN "prim__divInt") (ty [IType, IType] IType) 2 (iBin (div))
88− (eOp E.divide_) partial,
92+ (eOp E.divide_) ([sInt, sInt], sInt, DivI) partial,
8993 Prim (UN "prim__eqInt") (ty [IType, IType] IType) 2 (biBin (==))
90− (eOp E.eq_) total,
94+ (eOp E.eq_) ([sInt, sInt], sInt, EqI) total,
9195 Prim (UN "prim__ltInt") (ty [IType, IType] IType) 2 (biBin (<))
92− (eOp E.lt_) total,
96+ (eOp E.lt_) ([sInt, sInt], sInt, LtI) total,
9397 Prim (UN "prim__lteInt") (ty [IType, IType] IType) 2 (biBin (<=))
94− (eOp E.lte_) total,
98+ (eOp E.lte_) ([sInt, sInt], sInt, LteI) total,
9599 Prim (UN "prim__gtInt") (ty [IType, IType] IType) 2 (biBin (>))
96− (eOp E.gt_) total,
100+ (eOp E.gt_) ([sInt, sInt], sInt, GtI) total,
97101 Prim (UN "prim__gteInt") (ty [IType, IType] IType) 2 (biBin (>=))
98− (eOp E.gte_) total,
102+ (eOp E.gte_) ([sInt, sInt], sInt, GteI) total,
99103 Prim (UN "prim__eqChar") (ty [ChType, ChType] IType) 2 (bcBin (==))
100− (eOp E.eq_) total,
104+ (eOp E.eq_) ([sChar, sChar], sInt, EqC) total,
101105 Prim (UN "prim__ltChar") (ty [ChType, ChType] IType) 2 (bcBin (<))
102− (eOp E.lt_) total,
106+ (eOp E.lt_) ([sChar, sChar], sInt, LtC) total,
103107 Prim (UN "prim__lteChar") (ty [ChType, ChType] IType) 2 (bcBin (<=))
104− (eOp E.lte_) total,
108+ (eOp E.lte_) ([sChar, sChar], sInt, LteC) total,
105109 Prim (UN "prim__gtChar") (ty [ChType, ChType] IType) 2 (bcBin (>))
106− (eOp E.gt_) total,
110+ (eOp E.gt_) ([sChar, sChar], sInt, GtC) total,
107111 Prim (UN "prim__gteChar") (ty [ChType, ChType] IType) 2 (bcBin (>=))
108− (eOp E.gte_) total,
112+ (eOp E.gte_) ([sChar, sChar], sInt, GteC) total,
109113 Prim (UN "prim__addBigInt") (ty [BIType, BIType] BIType) 2 (bBin (+))
110− (eOpFn tyBigInt tyBigInt "addBig") total,
114+ (eOpFn tyBigInt tyBigInt "addBig")
115+ ([sBigInt, sBigInt], sBigInt, AddBI) total,
111116 Prim (UN "prim__subBigInt") (ty [BIType, BIType] BIType) 2 (bBin (-))
112− (eOpFn tyBigInt tyBigInt "subBig") total,
117+ (eOpFn tyBigInt tyBigInt "subBig") ([sBigInt, sBigInt], sBigInt, SubBI) total,
113118 Prim (UN "prim__mulBigInt") (ty [BIType, BIType] BIType) 2 (bBin (*))
114− (eOpFn tyBigInt tyBigInt "mulBig") total,
119+ (eOpFn tyBigInt tyBigInt "mulBig") ([sBigInt, sBigInt], sBigInt, MulBI) total,
115120 Prim (UN "prim__divBigInt") (ty [BIType, BIType] BIType) 2 (bBin (div))
116− (eOpFn tyBigInt tyBigInt "divBig") partial,
121+ (eOpFn tyBigInt tyBigInt "divBig") ([sBigInt, sBigInt], sBigInt,DivBI) partial,
117122 Prim (UN "prim__eqBigInt") (ty [BIType, BIType] IType) 2 (bbBin (==))
118− (eOpFn tyBigInt tyInt "eqBig") total,
123+ (eOpFn tyBigInt tyInt "eqBig") ([sBigInt, sBigInt], sInt, EqBI) total,
119124 Prim (UN "prim__ltBigInt") (ty [BIType, BIType] IType) 2 (bbBin (<))
120− (eOpFn tyBigInt tyInt "ltBig") total,
125+ (eOpFn tyBigInt tyInt "ltBig") ([sBigInt, sBigInt], sInt, LtBI) total,
121126 Prim (UN "prim__lteBigInt") (ty [BIType, BIType] IType) 2 (bbBin (<=))
122− (eOpFn tyBigInt tyInt "leBig") total,
127+ (eOpFn tyBigInt tyInt "leBig") ([sBigInt, sBigInt], sInt, LteBI) total,
123128 Prim (UN "prim__gtBigInt") (ty [BIType, BIType] IType) 2 (bbBin (>))
124− (eOpFn tyBigInt tyInt "gtBig") total,
129+ (eOpFn tyBigInt tyInt "gtBig") ([sBigInt, sBigInt], sInt, GtBI) total,
125130 Prim (UN "prim__gtBigInt") (ty [BIType, BIType] IType) 2 (bbBin (>=))
126− (eOpFn tyBigInt tyInt "geBig") total,
131+ (eOpFn tyBigInt tyInt "geBig") ([sBigInt, sBigInt], sInt, GteBI) total,
127132 Prim (UN "prim__addFloat") (ty [FlType, FlType] FlType) 2 (fBin (+))
128− (eOp E.plusF_) total,
133+ (eOp E.plusF_) ([sFloat, sFloat], sFloat, AddF) total,
129134 Prim (UN "prim__subFloat") (ty [FlType, FlType] FlType) 2 (fBin (-))
130− (eOp E.minusF_) total,
135+ (eOp E.minusF_) ([sFloat, sFloat], sFloat, SubF) total,
131136 Prim (UN "prim__mulFloat") (ty [FlType, FlType] FlType) 2 (fBin (*))
132− (eOp E.timesF_) total,
137+ (eOp E.timesF_) ([sFloat, sFloat], sFloat, MulF) total,
133138 Prim (UN "prim__divFloat") (ty [FlType, FlType] FlType) 2 (fBin (/))
134− (eOp E.divideF_) total,
139+ (eOp E.divideF_) ([sFloat, sFloat], sFloat, DivF) total,
135140 Prim (UN "prim__eqFloat") (ty [FlType, FlType] IType) 2 (bfBin (==))
136− (eOp E.eqF_) total,
141+ (eOp E.eqF_) ([sFloat, sFloat], sInt, EqF) total,
137142 Prim (UN "prim__ltFloat") (ty [FlType, FlType] IType) 2 (bfBin (<))
138− (eOp E.ltF_) total,
143+ (eOp E.ltF_) ([sFloat, sFloat], sInt, LtF) total,
139144 Prim (UN "prim__lteFloat") (ty [FlType, FlType] IType) 2 (bfBin (<=))
140− (eOp E.lteF_) total,
145+ (eOp E.lteF_) ([sFloat, sFloat], sInt, LteF) total,
141146 Prim (UN "prim__gtFloat") (ty [FlType, FlType] IType) 2 (bfBin (>))
142− (eOp E.gtF_) total,
147+ (eOp E.gtF_) ([sFloat, sFloat], sInt, GtF) total,
143148 Prim (UN "prim__gteFloat") (ty [FlType, FlType] IType) 2 (bfBin (>=))
144− (eOp E.gteF_) total,
149+ (eOp E.gteF_) ([sFloat, sFloat], sInt, GteF) total,
145150 Prim (UN "prim__concat") (ty [StrType, StrType] StrType) 2 (sBin (++))
146− ([E.name "x", E.name "y"], (fun "append") @@ fun "x" @@ fun "y") total,
151+ ([E.name "x", E.name "y"], (fun "append") @@ fun "x" @@ fun "y")
152+ ([sString, sString], sString, ConcatS) total,
147153 Prim (UN "prim__eqString") (ty [StrType, StrType] IType) 2 (bsBin (==))
148− ([E.name "x", E.name "y"], strEq (fun "x") (fun "y")) total,
154+ ([E.name "x", E.name "y"], strEq (fun "x") (fun "y"))
155+ ([sString, sString], sInt, EqS) total,
149156 Prim (UN "prim__ltString") (ty [StrType, StrType] IType) 2 (bsBin (<))
150− ([E.name "x", E.name "y"], strLt (fun "x") (fun "y")) total,
157+ ([E.name "x", E.name "y"], strLt (fun "x") (fun "y"))
158+ ([sString, sString], sInt, LtS) total,
151159 -- Conversions
152160 Prim (UN "prim__strToInt") (ty [StrType] IType) 1 (c_strToInt)
153− ([E.name "x"], strToInt (fun "x")) total,
161+ ([E.name "x"], strToInt (fun "x")) ([sString], sInt, StoI) total,
154162 Prim (UN "prim__intToStr") (ty [IType] StrType) 1 (c_intToStr)
155− ([E.name "x"], intToStr (fun "x")) total,
163+ ([E.name "x"], intToStr (fun "x")) ([sInt], sString, ItoS) total,
156164 Prim (UN "prim__charToInt") (ty [ChType] IType) 1 (c_charToInt)
157− ([E.name "x"], charToInt (fun "x")) total,
165+ ([E.name "x"], charToInt (fun "x")) ([sChar], sInt, CtoI) total,
158166 Prim (UN "prim__intToChar") (ty [IType] ChType) 1 (c_intToChar)
159− ([E.name "x"], intToChar (fun "x")) total,
167+ ([E.name "x"], intToChar (fun "x")) ([sInt], sChar, ItoC) total,
160168 Prim (UN "prim__intToBigInt") (ty [IType] BIType) 1 (c_intToBigInt)
161− ([E.name "x"], intToBigInt (fun "x")) total,
169+ ([E.name "x"], intToBigInt (fun "x")) ([sInt], sBigInt, ItoBI) total,
162170 Prim (UN "prim__bigIntToInt") (ty [BIType] IType) 1 (c_bigIntToInt)
163− ([E.name "x"], bigIntToInt (fun "x")) total,
171+ ([E.name "x"], bigIntToInt (fun "x")) ([sBigInt], sInt, BItoI) total,
164172 Prim (UN "prim__strToBigInt") (ty [StrType] BIType) 1 (c_strToBigInt)
165− ([E.name "x"], strToBigInt (fun "x")) total,
173+ ([E.name "x"], strToBigInt (fun "x")) ([sString], sBigInt, StoBI) total,
166174 Prim (UN "prim__bigIntToStr") (ty [BIType] StrType) 1 (c_bigIntToStr)
167− ([E.name "x"], bigIntToStr (fun "x")) total,
175+ ([E.name "x"], bigIntToStr (fun "x")) ([sBigInt], sString, BItoS) total,
168176 Prim (UN "prim__strToFloat") (ty [StrType] FlType) 1 (c_strToFloat)
169− ([E.name "x"], strToFloat (fun "x")) total,
177+ ([E.name "x"], strToFloat (fun "x")) ([sString], sFloat, StoF) total,
170178 Prim (UN "prim__floatToStr") (ty [FlType] StrType) 1 (c_floatToStr)
171− ([E.name "x"], floatToStr (fun "x")) total,
179+ ([E.name "x"], floatToStr (fun "x")) ([sFloat], sString, FtoS) total,
172180 Prim (UN "prim__intToFloat") (ty [IType] FlType) 1 (c_intToFloat)
173− ([E.name "x"], intToFloat (fun "x")) total,
181+ ([E.name "x"], intToFloat (fun "x")) ([sInt], sFloat, ItoF) total,
174182 Prim (UN "prim__floatToInt") (ty [FlType] IType) 1 (c_floatToInt)
175− ([E.name "x"], floatToInt (fun "x")) total,
183+ ([E.name "x"], floatToInt (fun "x")) ([sFloat], sInt, FtoI) total,
176184
177185 Prim (UN "prim__floatExp") (ty [FlType] FlType) 1 (p_floatExp)
178− ([E.name "x"], floatExp (fun "x")) total,
186+ ([E.name "x"], floatExp (fun "x")) ([sFloat], sFloat, ExpF) total,
179187 Prim (UN "prim__floatLog") (ty [FlType] FlType) 1 (p_floatLog)
180− ([E.name "x"], floatLog (fun "x")) total,
188+ ([E.name "x"], floatLog (fun "x")) ([sFloat], sFloat, LogF) total,
181189 Prim (UN "prim__floatSin") (ty [FlType] FlType) 1 (p_floatSin)
182− ([E.name "x"], floatSin (fun "x")) total,
190+ ([E.name "x"], floatSin (fun "x")) ([sFloat], sFloat, SinF) total,
183191 Prim (UN "prim__floatCos") (ty [FlType] FlType) 1 (p_floatCos)
184− ([E.name "x"], floatCos (fun "x")) total,
192+ ([E.name "x"], floatCos (fun "x")) ([sFloat], sFloat, CosF) total,
185193 Prim (UN "prim__floatTan") (ty [FlType] FlType) 1 (p_floatTan)
186− ([E.name "x"], floatTan (fun "x")) total,
194+ ([E.name "x"], floatTan (fun "x")) ([sFloat], sFloat, TanF) total,
187195 Prim (UN "prim__floatASin") (ty [FlType] FlType) 1 (p_floatASin)
188− ([E.name "x"], floatASin (fun "x")) total,
196+ ([E.name "x"], floatASin (fun "x")) ([sFloat], sFloat, ASinF) total,
189197 Prim (UN "prim__floatACos") (ty [FlType] FlType) 1 (p_floatACos)
190− ([E.name "x"], floatACos (fun "x")) total,
198+ ([E.name "x"], floatACos (fun "x")) ([sFloat], sFloat, ACosF) total,
191199 Prim (UN "prim__floatATan") (ty [FlType] FlType) 1 (p_floatATan)
192− ([E.name "x"], floatATan (fun "x")) total,
200+ ([E.name "x"], floatATan (fun "x")) ([sFloat], sFloat, ATanF) total,
193201 Prim (UN "prim__floatSqrt") (ty [FlType] FlType) 1 (p_floatSqrt)
194− ([E.name "x"], floatSqrt (fun "x")) total,
202+ ([E.name "x"], floatSqrt (fun "x")) ([sFloat], sFloat, SqrtF) total,
195203 Prim (UN "prim__floatFloor") (ty [FlType] FlType) 1 (p_floatFloor)
196− ([E.name "x"], floatFloor (fun "x")) total,
204+ ([E.name "x"], floatFloor (fun "x")) ([sFloat], sFloat, FloorF) total,
197205 Prim (UN "prim__floatCeil") (ty [FlType] FlType) 1 (p_floatCeil)
198− ([E.name "x"], floatCeil (fun "x")) total,
206+ ([E.name "x"], floatCeil (fun "x")) ([sFloat], sFloat, CeilF) total,
199207
200208 Prim (UN "prim__strHead") (ty [StrType] ChType) 1 (p_strHead)
201− ([E.name "x"], strHead (fun "x")) partial,
209+ ([E.name "x"], strHead (fun "x")) ([sString], sChar, HeadS) partial,
202210 Prim (UN "prim__strTail") (ty [StrType] StrType) 1 (p_strTail)
203− ([E.name "x"], strTail (fun "x")) partial,
211+ ([E.name "x"], strTail (fun "x")) ([sString], sString, TailS) partial,
204212 Prim (UN "prim__strCons") (ty [ChType, StrType] StrType) 2 (p_strCons)
205− ([E.name "x", E.name "xs"], strCons (fun "x") (fun "xs")) total,
213+ ([E.name "x", E.name "xs"], strCons (fun "x") (fun "xs"))
214+ ([sChar, sString], sString, ConsS) total,
206215 Prim (UN "prim__strIndex") (ty [StrType, IType] ChType) 2 (p_strIndex)
207− ([E.name "x", E.name "i"], strIndex (fun "x") (fun "i")) partial,
216+ ([E.name "x", E.name "i"], strIndex (fun "x") (fun "i"))
217+ ([sString, sInt], sChar, IndexS) partial,
208218 Prim (UN "prim__strRev") (ty [StrType] StrType) 1 (p_strRev)
209− ([E.name "x"], strRev (fun "x")) total,
219+ ([E.name "x"], strRev (fun "x"))
220+ ([sString], sString, RevS) total,
210221
211222 Prim (UN "prim__believe_me") believeTy 3 (p_believeMe)
212− ([E.name "a", E.name "b", E.name "x"], fun "x") total -- ahem
223+ ([E.name "a", E.name "b", E.name "x"], fun "x")
224+ ([Nothing], Nothing, BelieveMe) total -- ahem
213225 ]
214226
215227p_believeMe [_,_,x] = Just x
@@ -311,11 +323,12 @@ p_strRev [VConstant (Str xs)] = Just $ VConstant (Str (reverse xs))
311323p_strRev _ = Nothing
312324
313325elabPrim :: Prim -> Idris ()
314−elabPrim (Prim n ty i def epic tot)
326+elabPrim (Prim n ty i def epic sc tot)
315327 = do updateContext (addOperator n ty i def)
316328 setTotality n tot
317329 i <- getIState
318− putIState i { idris_prims = (n, epic) : idris_prims i }
330+ putIState i { idris_prims = (n, epic) : idris_prims i,
331+ idris_scprims = (n, sc) : idris_scprims i }
319332
320333elabPrims :: Idris ()
321334elabPrims = do mapM_ (elabDecl toplevel)