on master help sign in
Merge branch 'unified-int-primitives-fix' of https://github.com/bitlisp/Idris-dev into bitlisp-unified-int-primitives-fix

Conflicts: lib/Data/Bits.idr

commitaf78968597f3b2f4cc82ef117e5a0be39a1f6a51 authorEdwin Brady <ecb10@st-andrews.ac.uk> dateWed 15 May 2013, 18:23 (13 years ago) parent544349ab7a1059
27 files changed+771−1041
effects/Effect/Memory.idr+4−4 effects/Effect/Random.idr+7−7 lib/Builtins.idr+4−4 lib/Data/Bits.idr+40−42 lib/Data/Mod2.idr−2 lib/IO.idr+19−3 lib/Network/Cgi.idr+1−1 lib/Prelude.idr+9−5 lib/Prelude/Cast.idr+7−7 lib/base.ipkg+3−1 rts/idris_bitstring.c+28 rts/idris_bitstring.h+4 rts/idris_gmp.c+28 rts/idris_gmp.h+2 rts/idris_rts.c+6−7 rts/idris_rts.h+4−3 src/Core/Execute.hs+34−14 src/IRTS/CodegenC.hs+95−180 src/IRTS/CodegenJava.hs+142−215 src/IRTS/CodegenJavaScript.hs+36−36 src/IRTS/Compiler.hs+7−1 src/IRTS/LParser.hs+27−27 src/IRTS/Lang.hs+29−26 src/Idris/Primitives.hs+224−445 test/test021/expected+2−2 test/test021/test021a.idr+5−5 test/test025/test025.idr+4−4
effects/Effect/Memory.idr+4−4
@@ -48,7 +48,7 @@ do_malloc size with (fromInteger (cast size) == size)
4848private
4949do_memset : Ptr -> Nat -> Bits8 -> Nat -> IO ()
5050do_memset ptr offset c size
51− = mkForeign (FFun "idris_memset" [FPtr, FInt, FAny Bits8, FInt] FUnit)
51+ = mkForeign (FFun "idris_memset" [FPtr, FInt, FChar, FInt] FUnit)
5252 ptr (cast offset) c (cast size)
5353
5454private
@@ -65,15 +65,15 @@ private
6565do_peek : Ptr -> Nat -> (size : Nat) -> IO (Vect Bits8 size)
6666do_peek _ _ O = return (Prelude.Vect.Nil)
6767do_peek ptr offset (S n)
68− = do b <- mkForeign (FFun "idris_peek" [FPtr, FInt] FInt) ptr (cast offset)
68+ = do b <- mkForeign (FFun "idris_peek" [FPtr, FInt] FChar) ptr (cast offset)
6969 bs <- do_peek ptr (S offset) n
70− Prelude.Monad.return (Prelude.Vect.(::) (prim__intToB8 b) bs)
70+ Prelude.Monad.return (Prelude.Vect.(::) b bs)
7171
7272private
7373do_poke : Ptr -> Nat -> Vect Bits8 size -> IO ()
7474do_poke _ _ [] = return ()
7575do_poke ptr offset (b::bs)
76− = do mkForeign (FFun "idris_poke" [FPtr, FInt, FAny Bits8] FUnit) ptr (cast offset) b
76+ = do mkForeign (FFun "idris_poke" [FPtr, FInt, FChar] FUnit) ptr (cast offset) b
7777 do_poke ptr (S offset) bs
7878
7979instance Handler RawMemory (IOExcept String) where
effects/Effect/Random.idr+7−7
@@ -3,19 +3,19 @@ module Effect.Random
33import Effects
44
55data Random : Type -> Type -> Type -> Type where
6− getRandom : Random Int Int Int
6+ getRandom : Random Integer Integer Integer
77
88using (m : Type -> Type)
99 instance Handler Random m where
1010 handle seed getRandom k
11− = let seed' = 1664525 * seed + 1013904223 in
11+ = let seed' = (1664525 * seed + 1013904223) `prim__sremBigInt` (pow 2 32) in
1212 k seed' seed'
13−
13+
1414RND : EFFECT
15−RND = MkEff Int Random
15+RND = MkEff Integer Random
1616
17−rndInt : Int -> Int -> Eff m [RND] Int
18−rndInt lower upper = do v <- getRandom
19− return (v `mod` (upper - lower) + lower)
17+rndInt : Integer -> Integer -> Eff m [RND] Integer
18+rndInt lower upper = do v <- getRandom
19+ return (v `prim__sremBigInt` (upper - lower) + lower)
2020
2121
lib/Builtins.idr+4−4
@@ -251,7 +251,7 @@ instance Num Integer where
251251 (*) = prim__mulBigInt
252252
253253 abs x = if x<0 then -x else x
254− fromInteger = prim__intToBigInt
254+ fromInteger = prim__sextInt_BigInt
255255
256256
257257instance Num Float where
@@ -260,15 +260,15 @@ instance Num Float where
260260 (*) = prim__mulFloat
261261
262262 abs x = if x<0 then -x else x
263− fromInteger = prim__intToFloat
263+ fromInteger = prim__toFloatInt
264264
265265partial
266266div : Int -> Int -> Int
267−div = prim__divInt
267+div = prim__sdivInt
268268
269269partial
270270mod : Int -> Int -> Int
271−mod = prim__modInt
271+mod = prim__sremInt
272272
273273
274274(/) : Float -> Float -> Float
lib/Data/Bits.idr+40−42
@@ -31,17 +31,17 @@ bitsUsed n = 8 * (2 `power` n)
3131natToBits' : machineTy n -> Nat -> machineTy n
3232natToBits' a O = a
3333natToBits' {n=n} a x with n
34− natToBits' a (S x') | O = natToBits' (prim__addB8 a (prim__intToB8 1)) x'
35− natToBits' a (S x') | S O = natToBits' {n = S O} (prim__addB16 a (prim__intToB16 1)) x'
36− natToBits' a (S x') | S (S O) = natToBits' {n=S (S O)} (prim__addB32 a (prim__intToB32 1)) x'
37− natToBits' a (S x') | S (S (S k)) = natToBits' {n = S (S (S k))} (prim__addB64 a (prim__intToB64 1)) x'
34+ natToBits' a (S x') | O = natToBits' (prim__addB8 a (prim__truncInt_B8 1)) x'
35+ natToBits' a (S x') | S O = natToBits' (prim__addB16 a (prim__truncInt_B16 1)) x'
36+ natToBits' a (S x') | S (S O) = natToBits' (prim__addB32 a (prim__truncInt_B32 1)) x'
37+ natToBits' a (S x') | S (S (S _)) = natToBits' (prim__addB64 a (prim__truncInt_B64 1)) x'
3838
3939natToBits : Nat -> machineTy n
4040natToBits {n=n} x with n
41− | O = natToBits' {n=O} (prim__intToB8 0) x
42− | S O = natToBits' {n=S O} (prim__intToB16 0) x
43− | S (S O) = natToBits' {n=S (S O)} (prim__intToB32 0) x
44− | S (S (S k)) = natToBits' {n=S (S (S k))} (prim__intToB64 0) x
41+ | O = natToBits' (prim__truncInt_B8 0) x
42+ | S O = natToBits' (prim__truncInt_B16 0) x
43+ | S (S O) = natToBits' (prim__truncInt_B32 0) x
44+ | S (S (S _)) = natToBits' (prim__truncInt_B64 0) x
4545
4646getPad : Nat -> machineTy n
4747getPad n = natToBits ((bitsUsed (nextBytes n)) - n)
@@ -154,7 +154,6 @@ xor' {n=n} x y with n
154154 | S (S O) = prim__xorB32 x y
155155 | S (S (S _)) = prim__xorB64 x y
156156
157−{-
158157public
159158xor : Bits n -> Bits n -> Bits n
160159xor (MkBits x) (MkBits y) = MkBits (xor' x y)
@@ -310,14 +309,14 @@ complement (MkBits x) = MkBits (complement' x)
310309zext' : machineTy (nextBytes n) -> machineTy (nextBytes (n+m))
311310zext' {n=n} {m=m} x with (nextBytes n, nextBytes (n+m))
312311 | (O, O) = believe_me x
313− | (O, S O) = believe_me (prim__zextB8_16 (believe_me x))
314− | (O, S (S O)) = believe_me (prim__zextB8_32 (believe_me x))
315− | (O, S (S (S _))) = believe_me (prim__zextB8_64 (believe_me x))
312+ | (O, S O) = believe_me (prim__zextB8_B16 (believe_me x))
313+ | (O, S (S O)) = believe_me (prim__zextB8_B32 (believe_me x))
314+ | (O, S (S (S _))) = believe_me (prim__zextB8_B64 (believe_me x))
316315 | (S O, S O) = believe_me x
317− | (S O, S (S O)) = believe_me (prim__zextB16_32 (believe_me x))
318− | (S O, S (S (S _))) = believe_me (prim__zextB16_64 (believe_me x))
316+ | (S O, S (S O)) = believe_me (prim__zextB16_B32 (believe_me x))
317+ | (S O, S (S (S _))) = believe_me (prim__zextB16_B64 (believe_me x))
319318 | (S (S O), S (S O)) = believe_me x
320− | (S (S O), S (S (S _))) = believe_me (prim__zextB32_64 (believe_me x))
319+ | (S (S O), S (S (S _))) = believe_me (prim__zextB32_B64 (believe_me x))
321320 | (S (S (S _)), S (S (S _))) = believe_me x
322321
323322public
@@ -328,13 +327,13 @@ zeroExtend (MkBits x) = MkBits (zext' x)
328327intToBits' : Int -> machineTy (nextBytes n)
329328intToBits' {n=n} x with (nextBytes n)
330329 | O = let pad = getPad {n=0} n in
331− prim__lshrB8 (prim__shlB8 (prim__intToB8 x) pad) pad
330+ prim__lshrB8 (prim__shlB8 (prim__truncInt_B8 x) pad) pad
332331 | S O = let pad = getPad {n=1} n in
333− prim__lshrB16 (prim__shlB16 (prim__intToB16 x) pad) pad
332+ prim__lshrB16 (prim__shlB16 (prim__truncInt_B16 x) pad) pad
334333 | S (S O) = let pad = getPad {n=2} n in
335− prim__lshrB32 (prim__shlB32 (prim__intToB32 x) pad) pad
334+ prim__lshrB32 (prim__shlB32 (prim__truncInt_B32 x) pad) pad
336335 | S (S (S _)) = let pad = getPad {n=3} n in
337− prim__lshrB64 (prim__shlB64 (prim__intToB64 x) pad) pad
336+ prim__lshrB64 (prim__shlB64 (prim__truncInt_B64 x) pad) pad
338337
339338public
340339intToBits : Int -> Bits n
@@ -345,10 +344,10 @@ instance Cast Int (Bits n) where
345344
346345bitsToInt' : machineTy n -> Int
347346bitsToInt' {n=n} x with n
348− | O = prim__B32ToInt (prim__zextB8_32 x)
349− | S O = prim__B32ToInt (prim__zextB16_32 x)
350− | S (S O) = prim__B32ToInt x
351− | S (S (S _)) = prim__B32ToInt (prim__truncB64_32 x)
347+ | O = prim__zextB8_Int x
348+ | S O = prim__zextB16_Int x
349+ | S (S O) = prim__zextB32_Int x
350+ | S (S (S _)) = prim__truncB64_Int x
352351
353352public
354353bitsToInt : Bits n -> Int
@@ -367,27 +366,27 @@ sext' {n=n} {m=m} x with (nextBytes n, nextBytes (n+m))
367366 | (O, O) = let pad = getPad {n=0} n in
368367 believe_me (prim__ashrB8 (prim__shlB8 (believe_me x) pad) pad)
369368 | (O, S O) = let pad = getPad {n=0} n in
370− believe_me (prim__ashrB16 (prim__sextB8_16 (prim__shlB8 (believe_me x) pad))
371− (prim__zextB8_16 pad))
369+ believe_me (prim__ashrB16 (prim__sextB8_B16 (prim__shlB8 (believe_me x) pad))
370+ (prim__zextB8_B16 pad))
372371 | (O, S (S O)) = let pad = getPad {n=0} n in
373− believe_me (prim__ashrB32 (prim__sextB8_32 (prim__shlB8 (believe_me x) pad))
374− (prim__zextB8_32 pad))
372+ believe_me (prim__ashrB32 (prim__sextB8_B32 (prim__shlB8 (believe_me x) pad))
373+ (prim__zextB8_B32 pad))
375374 | (O, S (S (S _))) = let pad = getPad {n=0} n in
376− believe_me (prim__ashrB64 (prim__sextB8_64 (prim__shlB8 (believe_me x) pad))
377− (prim__zextB8_64 pad))
375+ believe_me (prim__ashrB64 (prim__sextB8_B64 (prim__shlB8 (believe_me x) pad))
376+ (prim__zextB8_B64 pad))
378377 | (S O, S O) = let pad = getPad {n=1} n in
379378 believe_me (prim__ashrB16 (prim__shlB16 (believe_me x) pad) pad)
380379 | (S O, S (S O)) = let pad = getPad {n=1} n in
381− believe_me (prim__ashrB32 (prim__sextB16_32 (prim__shlB16 (believe_me x) pad))
382− (prim__zextB16_32 pad))
380+ believe_me (prim__ashrB32 (prim__sextB16_B32 (prim__shlB16 (believe_me x) pad))
381+ (prim__zextB16_B32 pad))
383382 | (S O, S (S (S _))) = let pad = getPad {n=1} n in
384− believe_me (prim__ashrB64 (prim__sextB16_64 (prim__shlB16 (believe_me x) pad))
385− (prim__zextB16_64 pad))
383+ believe_me (prim__ashrB64 (prim__sextB16_B64 (prim__shlB16 (believe_me x) pad))
384+ (prim__zextB16_B64 pad))
386385 | (S (S O), S (S O)) = let pad = getPad {n=2} n in
387386 believe_me (prim__ashrB32 (prim__shlB32 (believe_me x) pad) pad)
388387 | (S (S O), S (S (S _))) = let pad = getPad {n=2} n in
389− believe_me (prim__ashrB64 (prim__sextB32_64 (prim__shlB32 (believe_me x) pad))
390− (prim__zextB32_64 pad))
388+ believe_me (prim__ashrB64 (prim__sextB32_B64 (prim__shlB32 (believe_me x) pad))
389+ (prim__zextB32_B64 pad))
391390 | (S (S (S _)), S (S (S _))) = let pad = getPad {n=3} n in
392391 believe_me (prim__ashrB64 (prim__shlB64 (believe_me x) pad) pad)
393392
@@ -399,14 +398,14 @@ signExtend {m=m} (MkBits x) = MkBits (zeroUnused (sext' x))
399398trunc' : machineTy (nextBytes (n+m)) -> machineTy (nextBytes n)
400399trunc' {n=n} {m=m} x with (nextBytes n, nextBytes (n+m))
401400 | (O, O) = believe_me x
402− | (O, S O) = believe_me (prim__truncB16_8 (believe_me x))
403− | (O, S (S O)) = believe_me (prim__truncB32_8 (believe_me x))
404− | (O, S (S (S _))) = believe_me (prim__truncB64_8 (believe_me x))
401+ | (O, S O) = believe_me (prim__truncB16_B8 (believe_me x))
402+ | (O, S (S O)) = believe_me (prim__truncB32_B8 (believe_me x))
403+ | (O, S (S (S _))) = believe_me (prim__truncB64_B8 (believe_me x))
405404 | (S O, S O) = believe_me x
406− | (S O, S (S O)) = believe_me (prim__truncB32_16 (believe_me x))
407− | (S O, S (S (S _))) = believe_me (prim__truncB64_16 (believe_me x))
405+ | (S O, S (S O)) = believe_me (prim__truncB32_B16 (believe_me x))
406+ | (S O, S (S (S _))) = believe_me (prim__truncB64_B16 (believe_me x))
408407 | (S (S O), S (S O)) = believe_me x
409− | (S (S O), S (S (S _))) = believe_me (prim__truncB64_32 (believe_me x))
408+ | (S (S O), S (S (S _))) = believe_me (prim__truncB64_B32 (believe_me x))
410409 | (S (S (S _)), S (S (S _))) = believe_me x
411410
412411public
@@ -440,4 +439,3 @@ bitsToStr x = pack (helper last x)
440439instance Show (Bits n) where
441440 show = bitsToStr
442441
443−-}
lib/Data/Mod2.idr−2
@@ -4,7 +4,6 @@ import Data.Bits
44
55%default total
66
7−{-
87-- Integers modulo 2^n
98public
109data Mod2 : Nat -> Type where
@@ -63,4 +62,3 @@ modToStr x = pack (reverse (helper x))
6362
6463instance Show (Mod2 n) where
6564 show = modToStr
66−-}
lib/IO.idr+19−3
@@ -21,12 +21,28 @@ io_return x = prim__IO x
2121run__IO : IO () -> IO ()
2222run__IO v = io_bind v (\v' => io_return v')
2323
24−data FTy = FInt | FFloat | FChar | FString | FPtr | FAny Type | FUnit
24+data IntTy = ITNative | IT8 | IT16 | IT32 | IT64
25+data FTy = FIntT IntTy | FFloat | FString | FPtr | FAny Type | FUnit
26+
27+FInt : FTy
28+FInt = FIntT ITNative
29+
30+FChar : FTy
31+FChar = FIntT IT8
32+
33+FShort : FTy
34+FShort = FIntT IT16
35+
36+FLong : FTy
37+FLong = FIntT IT64
2538
2639interpFTy : FTy -> Type
27−interpFTy FInt = Int
40+interpFTy (FIntT ITNative) = Int
41+interpFTy (FIntT IT8) = Bits8
42+interpFTy (FIntT IT16) = Bits16
43+interpFTy (FIntT IT32) = Bits32
44+interpFTy (FIntT IT64) = Bits64
2845interpFTy FFloat = Float
29−interpFTy FChar = Char
3046interpFTy FString = String
3147interpFTy FPtr = Ptr
3248interpFTy (FAny t) = t
lib/Network/Cgi.idr+1−1
@@ -121,7 +121,7 @@ abstract
121121runCGI : CGI a -> IO a
122122runCGI prog = do
123123 clen_in <- getEnv "CONTENT_LENGTH"
124− let clen = prim__strToInt clen_in
124+ let clen = prim__fromStrInt clen_in
125125 content <- getContent clen
126126 query <- getEnv "QUERY_STRING"
127127 cookie <- getEnv "HTTP_COOKIE"
lib/Prelude.idr+9−5
@@ -29,10 +29,10 @@ instance Show Nat where
2929 show (S k) = "s" ++ show k
3030
3131instance Show Int where
32− show = prim__intToStr
32+ show = prim__toStrInt
3333
3434instance Show Integer where
35− show = prim__bigIntToStr
35+ show = prim__toStrBigInt
3636
3737instance Show Float where
3838 show = prim__floatToStr
@@ -148,6 +148,10 @@ instance Monad List where
148148%include "math.h"
149149%lib "m"
150150
151+pow : (Num a) => a -> Nat -> a
152+pow x O = 1
153+pow x (S n) = x * (pow x n)
154+
151155exp : Float -> Float
152156exp x = prim__floatExp x
153157
@@ -251,11 +255,11 @@ getLine = return (prim__readString prim__stdin)
251255
252256partial
253257putChar : Char -> IO ()
254−putChar c = mkForeign (FFun "putchar" [FChar] FUnit) c
258+putChar c = mkForeign (FFun "putchar" [FInt] FUnit) (cast c)
255259
256260partial
257261getChar : IO Char
258−getChar = mkForeign (FFun "getchar" [] FChar)
262+getChar = fmap cast $ mkForeign (FFun "getchar" [] FInt)
259263
260264---- some basic file handling
261265
@@ -323,7 +327,7 @@ ferror (FHandle h) = do err <- do_ferror h
323327
324328partial
325329nullPtr : Ptr -> IO Bool
326−nullPtr p = do ok <- mkForeign (FFun "isNull" [FPtr] FInt) p
330+nullPtr p = do ok <- mkForeign (FFun "isNull" [FPtr] FInt) p
327331 return (ok /= 0);
328332
329333partial
lib/Prelude/Cast.idr+7−7
@@ -6,24 +6,24 @@ class Cast from to where
66-- String casts
77
88instance Cast String Int where
9− cast = prim__strToInt
9+ cast = prim__fromStrInt
1010
1111instance Cast String Float where
1212 cast = prim__strToFloat
1313
1414instance Cast String Integer where
15− cast = prim__strToBigInt
15+ cast = prim__fromStrBigInt
1616
1717-- Int casts
1818
1919instance Cast Int String where
20− cast = prim__intToStr
20+ cast = prim__toStrInt
2121
2222instance Cast Int Float where
23− cast = prim__intToFloat
23+ cast = prim__toFloatInt
2424
2525instance Cast Int Integer where
26− cast = prim__intToBigInt
26+ cast = prim__sextInt_BigInt
2727
2828instance Cast Int Char where
2929 cast = prim__intToChar
@@ -34,12 +34,12 @@ instance Cast Float String where
3434 cast = prim__floatToStr
3535
3636instance Cast Float Int where
37− cast = prim__floatToInt
37+ cast = prim__fromFloatInt
3838
3939-- Integer casts
4040
4141instance Cast Integer String where
42− cast = prim__bigIntToStr
42+ cast = prim__toStrBigInt
4343
4444-- Char casts
4545
lib/base.ipkg+3−1
@@ -21,7 +21,9 @@ modules = Builtins, Prelude, IO, System,
2121
2222 Language.Reflection, Language.Reflection.Utils,
2323
24− Data.Morphisms, Data.Bits, Data.Mod2, Data.Z, Data.Sign,
24+ Data.Morphisms,
25+-- Data.Bits, Data.Mod2,
26+ Data.Z, Data.Sign,
2527 Data.SortedMap, Data.SortedSet, Data.BoundedList,
2628 Data.Vect.Quantifiers,
2729
rts/idris_bitstring.c+28
@@ -60,6 +60,34 @@ VAL idris_castB32Int(VM *vm, VAL a) {
6060 return MKINT((i_int)a->info.bits32);
6161}
6262
63+VAL idris_b8const(VM *vm, uint8_t a) {
64+ VAL cl = allocate(vm, sizeof(Closure), 0);
65+ SETTY(cl, BITS8);
66+ cl->info.bits8 = a;
67+ return cl;
68+}
69+
70+VAL idris_b16const(VM *vm, uint16_t a) {
71+ VAL cl = allocate(vm, sizeof(Closure), 0);
72+ SETTY(cl, BITS16);
73+ cl->info.bits16 = a;
74+ return cl;
75+}
76+
77+VAL idris_b32const(VM *vm, uint32_t a) {
78+ VAL cl = allocate(vm, sizeof(Closure), 0);
79+ SETTY(cl, BITS32);
80+ cl->info.bits32 = a;
81+ return cl;
82+}
83+
84+VAL idris_b64const(VM *vm, uint64_t a) {
85+ VAL cl = allocate(vm, sizeof(Closure), 0);
86+ SETTY(cl, BITS64);
87+ cl->info.bits64 = a;
88+ return cl;
89+}
90+
6391VAL idris_b8Plus(VM *vm, VAL a, VAL b) {
6492 VAL cl = allocate(vm, sizeof(Closure), 0);
6593 SETTY(cl, BITS8);
rts/idris_bitstring.h+4
@@ -11,6 +11,10 @@ VAL idris_b16(VM *vm, VAL a);
1111VAL idris_b32(VM *vm, VAL a);
1212VAL idris_b64(VM *vm, VAL a);
1313VAL idris_castB32Int(VM *vm, VAL a);
14+VAL idris_b8const(VM *vm, uint8_t a);
15+VAL idris_b16const(VM *vm, uint16_t a);
16+VAL idris_b32const(VM *vm, uint32_t a);
17+VAL idris_b64const(VM *vm, uint64_t a);
1418
1519VAL idris_b8Plus(VM *vm, VAL a, VAL b);
1620VAL idris_b8Minus(VM *vm, VAL a, VAL b);
rts/idris_gmp.c+28
@@ -52,6 +52,34 @@ VAL MKBIGMc(VM* vm, void* big) {
5252 return cl;
5353}
5454
55+VAL MKBIGUI(VM* vm, unsigned long val) {
56+ mpz_t* bigint;
57+ VAL cl = allocate(vm, sizeof(ClosureType) + sizeof(void*) +
58+ sizeof(mpz_t), 0);
59+ bigint = (mpz_t*)(((char*)cl) + sizeof(ClosureType) + sizeof(void*));
60+
61+ mpz_init_set_ui(*bigint, val);
62+
63+ SETTY(cl, BIGINT);
64+ cl -> info.ptr = (void*)bigint;
65+
66+ return cl;
67+}
68+
69+VAL MKBIGSI(VM* vm, signed long val) {
70+ mpz_t* bigint;
71+ VAL cl = allocate(vm, sizeof(ClosureType) + sizeof(void*) +
72+ sizeof(mpz_t), 0);
73+ bigint = (mpz_t*)(((char*)cl) + sizeof(ClosureType) + sizeof(void*));
74+
75+ mpz_init_set_si(*bigint, val);
76+
77+ SETTY(cl, BIGINT);
78+ cl -> info.ptr = (void*)bigint;
79+
80+ return cl;
81+}
82+
5583VAL GETBIG(VM * vm, VAL x) {
5684 if (ISINT(x)) {
5785 mpz_t* bigint;
rts/idris_gmp.h+2
@@ -5,6 +5,8 @@ VAL MKBIGI(int val);
55VAL MKBIGC(VM* vm, char* bigint);
66VAL MKBIGM(VM* vm, void* bigint);
77VAL MKBIGMc(VM* vm, void* bigint);
8+VAL MKBIGUI(VM* vm, unsigned long val);
9+VAL MKBIGSI(VM* vm, signed long val);
810
911VAL idris_bigPlus(VM*, VAL x, VAL y);
1012VAL idris_bigMinus(VM*, VAL x, VAL y);
rts/idris_rts.c+6−7
@@ -271,17 +271,16 @@ void dumpVal(VAL v) {
271271
272272}
273273
274−void idris_memset(void* ptr, i_int offset, VAL c, i_int size) {
275− memset(((uint8_t*)ptr) + offset, c->info.bits8, size);
274+void idris_memset(void* ptr, i_int offset, uint8_t c, i_int size) {
275+ memset(((uint8_t*)ptr) + offset, c, size);
276276}
277277
278−int idris_peek(void* ptr, i_int offset) {
279− uint8_t res = *(((uint8_t*)ptr) + offset);
280− return (int)res;
278+uint8_t idris_peek(void* ptr, i_int offset) {
279+ return *(((uint8_t*)ptr) + offset);
281280}
282281
283−void idris_poke(void* ptr, i_int offset, VAL data) {
284− *(((uint8_t*)ptr) + offset) = data->info.bits8;
282+void idris_poke(void* ptr, i_int offset, uint8_t data) {
283+ *(((uint8_t*)ptr) + offset) = data;
285284}
286285
287286void idris_memmove(void* dest, void* src, i_int dest_offset, i_int src_offset, i_int size) {
rts/idris_rts.h+4−3
@@ -125,6 +125,7 @@ typedef intptr_t i_int;
125125#define ISINT(x) ((((i_int)x)&1) == 1)
126126
127127#define INTOP(op,x,y) MKINT((i_int)((((i_int)x)>>1) op (((i_int)y)>>1)))
128+#define UINTOP(op,x,y) MKINT((i_int)((((uintptr_t)x)>>1) op (((uintptr_t)y)>>1)))
128129#define FLOATOP(op,x,y) MKFLOAT(vm, ((GETFLOAT(x)) op (GETFLOAT(y))))
129130#define FLOATBOP(op,x,y) MKINT((i_int)(((GETFLOAT(x)) op (GETFLOAT(y)))))
130131#define ADD(x,y) (void*)(((i_int)x)+(((i_int)y)-1))
@@ -207,9 +208,9 @@ VAL idris_castFloatStr(VM* vm, VAL i);
207208VAL idris_castStrFloat(VM* vm, VAL i);
208209
209210// Raw memory manipulation
210−void idris_memset(void* ptr, i_int offset, VAL c, i_int size);
211−int idris_peek(void* ptr, i_int offset);
212−void idris_poke(void* ptr, i_int offset, VAL data);
211+void idris_memset(void* ptr, i_int offset, uint8_t c, i_int size);
212+uint8_t idris_peek(void* ptr, i_int offset);
213+void idris_poke(void* ptr, i_int offset, uint8_t data);
213214void idris_memmove(void* dest, void* src, i_int dest_offset, i_int src_offset, i_int size);
214215
215216// String primitives
src/Core/Execute.hs+34−14
@@ -3,6 +3,9 @@ module Core.Execute (execute) where
33
44import Idris.AbsSyntax
55import Idris.AbsSyntaxTree
6+import IRTS.Lang( IntTy(..)
7+ , intTyToConst
8+ , FType(..))
69
710import Core.TT
811import Core.Evaluate
@@ -425,18 +428,16 @@ chooseAlt _ [] = Nothing
425428
426429
427430
428−data FTy = FInt | FFloat | FChar | FString | FPtr | FUnit deriving (Show, Read)
429−
430−idrisType :: FTy -> ExecVal
431+idrisType :: FType -> ExecVal
431432idrisType FUnit = EP Ref unitTy EErased
432433idrisType ft = EConstant (idr ft)
433− where idr FInt = IType
434− idr FFloat = FlType
434+ where idr (FInt ty) = intTyToConst ty
435+ idr FDouble = FlType
435436 idr FChar = ChType
436437 idr FString = StrType
437438 idr FPtr = PtrType
438439
439−data Foreign = FFun String [FTy] FTy deriving Show
440+data Foreign = FFun String [FType] FType deriving Show
440441
441442
442443call :: Foreign -> [ExecVal] -> Exec (Maybe ExecVal)
@@ -446,11 +447,19 @@ call (FFun name argTypes retType) args =
446447 Nothing -> return Nothing
447448 Just f -> do res <- call' f args retType
448449 return . Just . ioWrap $ res
449− where call' :: ForeignFun -> [ExecVal] -> FTy -> Exec ExecVal
450− call' (Fun _ h) args FInt = do res <- execIO $ callFFI h retCInt (prepArgs args)
451− return (EConstant (I (fromIntegral res)))
452− call' (Fun _ h) args FFloat = do res <- execIO $ callFFI h retCDouble (prepArgs args)
453− return (EConstant (Fl (realToFrac res)))
450+ where call' :: ForeignFun -> [ExecVal] -> FType -> Exec ExecVal
451+ call' (Fun _ h) args (FInt ITNative) = do res <- execIO $ callFFI h retCInt (prepArgs args)
452+ return (EConstant (I (fromIntegral res)))
453+ call' (Fun _ h) args (FInt IT8) = do res <- execIO $ callFFI h retCChar (prepArgs args)
454+ return (EConstant (B8 (fromIntegral res)))
455+ call' (Fun _ h) args (FInt IT16) = do res <- execIO $ callFFI h retCWchar (prepArgs args)
456+ return (EConstant (B16 (fromIntegral res)))
457+ call' (Fun _ h) args (FInt IT32) = do res <- execIO $ callFFI h retCInt (prepArgs args)
458+ return (EConstant (B32 (fromIntegral res)))
459+ call' (Fun _ h) args (FInt IT64) = do res <- execIO $ callFFI h retCLong (prepArgs args)
460+ return (EConstant (B64 (fromIntegral res)))
461+ call' (Fun _ h) args FDouble = do res <- execIO $ callFFI h retCDouble (prepArgs args)
462+ return (EConstant (Fl (realToFrac res)))
454463 call' (Fun _ h) args FChar = do res <- execIO $ callFFI h retCChar (prepArgs args)
455464 return (EConstant (Ch (castCCharToChar res)))
456465 call' (Fun _ h) args FString = do res <- execIO $ callFFI h retCString (prepArgs args)
@@ -467,6 +476,10 @@ call (FFun name argTypes retType) args =
467476
468477 prepArgs = map prepArg
469478 prepArg (EConstant (I i)) = argCInt (fromIntegral i)
479+ prepArg (EConstant (B8 i)) = argCChar (fromIntegral i)
480+ prepArg (EConstant (B16 i)) = argCWchar (fromIntegral i)
481+ prepArg (EConstant (B32 i)) = argCInt (fromIntegral i)
482+ prepArg (EConstant (B64 i)) = argCLong (fromIntegral i)
470483 prepArg (EConstant (Fl f)) = argCDouble (realToFrac f)
471484 prepArg (EConstant (Ch c)) = argCChar (castCharToCChar c) -- FIXME - castCharToCChar only safe for first 256 chars
472485 prepArg (EConstant (Str s)) = argString s
@@ -484,11 +497,18 @@ foreignFromTT t = case (unApplyV t) of
484497 return $ FFun name argFTy retFTy
485498 _ -> trace "failed to construct ffun" Nothing
486499
487−getFTy :: ExecVal -> Maybe FTy
500+getFTy :: ExecVal -> Maybe FType
501+getFTy (EApp (EP _ (UN "FIntT") _) (EP _ (UN intTy) _)) =
502+ case intTy of
503+ "ITNative" -> Just $ FInt ITNative
504+ "IT8" -> Just $ FInt IT8
505+ "IT16" -> Just $ FInt IT16
506+ "IT32" -> Just $ FInt IT32
507+ "IT64" -> Just $ FInt IT64
508+ _ -> Nothing
488509getFTy (EP _ (UN t) _) =
489510 case t of
490− "FInt" -> Just FInt
491− "FFloat" -> Just FFloat
511+ "FFloat" -> Just FDouble
492512 "FChar" -> Just FChar
493513 "FString" -> Just FString
494514 "FPtr" -> Just FPtr
src/IRTS/CodegenC.hs+95−180
@@ -10,6 +10,7 @@ import Paths_idris
1010import Util.System
1111
1212import Data.Char
13+import Data.List (intercalate)
1314import System.Process
1415import System.Exit
1516import System.IO
@@ -105,10 +106,10 @@ bcc i (ASSIGNCONST l c)
105106 mkConst (Fl f) = "MKFLOAT(vm, " ++ show f ++ ")"
106107 mkConst (Ch c) = "MKINT(" ++ show (fromEnum c) ++ ")"
107108 mkConst (Str s) = "MKSTR(vm, " ++ show s ++ ")"
108− mkConst (B8 b) = "MKB8(vm, " ++ show b ++")"
109− mkConst (B16 b) = "MKB16(vm, " ++ show b ++ ")"
110− mkConst (B32 b) = "MKB32(vm, " ++ show b ++ ")"
111− mkConst (B64 b) = "MKB64(vm, " ++ show b ++ ")"
109+ mkConst (B8 x) = "idris_b8const(vm, " ++ show x ++ ")"
110+ mkConst (B16 x) = "idris_b16const(vm, " ++ show x ++ ")"
111+ mkConst (B32 x) = "idris_b32const(vm, " ++ show x ++ ")"
112+ mkConst (B64 x) = "idris_b64const(vm, " ++ show x ++ ")"
112113 mkConst _ = "MKINT(42424242)"
113114bcc i (UPDATE l r) = indent i ++ creg l ++ " = " ++ creg r ++ ";\n"
114115bcc i (MKCON l tag args)
@@ -226,7 +227,10 @@ bcc i (NULL r) = indent i ++ creg r ++ " = NULL;\n" -- clear, so it'll be GCed
226227bcc i (ERROR str) = indent i ++ "fprintf(stderr, " ++ show str ++ "); assert(0); exit(-1);"
227228-- bcc i _ = indent i ++ "// not done yet\n"
228229
229−c_irts FInt l x = l ++ "MKINT((i_int)(" ++ x ++ "))"
230+
231+
232+c_irts (FInt ITNative) l x = l ++ "MKINT((i_int)(" ++ x ++ "))"
233+c_irts (FInt ty) l x = l ++ "idris_b" ++ show (intTyWidth ty) ++ "const(vm, " ++ x ++ ")"
230234c_irts FChar l x = l ++ "MKINT((i_int)(" ++ x ++ "))"
231235c_irts FString l x = l ++ "MKSTR(vm, " ++ x ++ ")"
232236c_irts FUnit l x = x
@@ -234,7 +238,8 @@ c_irts FPtr l x = l ++ "MKPTR(vm, " ++ x ++ ")"
234238c_irts FDouble l x = l ++ "MKFLOAT(vm, " ++ x ++ ")"
235239c_irts FAny l x = l ++ x
236240
237−irts_c FInt x = "GETINT(" ++ x ++ ")"
241+irts_c (FInt ITNative) x = "GETINT(" ++ x ++ ")"
242+irts_c (FInt ty) x = "(" ++ x ++ "->info.bits" ++ show (intTyWidth ty) ++ ")"
238243irts_c FChar x = "GETINT(" ++ x ++ ")"
239244irts_c FString x = "GETSTR(" ++ x ++ ")"
240245irts_c FUnit x = x
@@ -242,22 +247,33 @@ irts_c FPtr x = "GETPTR(" ++ x ++ ")"
242247irts_c FDouble x = "GETFLOAT(" ++ x ++ ")"
243248irts_c FAny x = x
244249
245−doOp v LPlus [l, r] = v ++ "ADD(" ++ creg l ++ ", " ++ creg r ++ ")"
246−doOp v LMinus [l, r] = v ++ "INTOP(-," ++ creg l ++ ", " ++ creg r ++ ")"
247−doOp v LTimes [l, r] = v ++ "MULT(" ++ creg l ++ ", " ++ creg r ++ ")"
248−doOp v LDiv [l, r] = v ++ "INTOP(/," ++ creg l ++ ", " ++ creg r ++ ")"
249−doOp v LMod [l, r] = v ++ "INTOP(%," ++ creg l ++ ", " ++ creg r ++ ")"
250−doOp v LAnd [l, r] = v ++ "INTOP(&," ++ creg l ++ ", " ++ creg r ++ ")"
251−doOp v LOr [l, r] = v ++ "INTOP(|," ++ creg l ++ ", " ++ creg r ++ ")"
252−doOp v LXOr [l, r] = v ++ "INTOP(^," ++ creg l ++ ", " ++ creg r ++ ")"
253−doOp v LSHL [l, r] = v ++ "INTOP(<<," ++ creg l ++ ", " ++ creg r ++ ")"
254−doOp v LSHR [l, r] = v ++ "INTOP(>>," ++ creg l ++ ", " ++ creg r ++ ")"
255−doOp v LCompl [x] = v ++ "INTOP(~," ++ creg x ++ ")"
256−doOp v LEq [l, r] = v ++ "INTOP(==," ++ creg l ++ ", " ++ creg r ++ ")"
257−doOp v LLt [l, r] = v ++ "INTOP(<," ++ creg l ++ ", " ++ creg r ++ ")"
258−doOp v LLe [l, r] = v ++ "INTOP(<=," ++ creg l ++ ", " ++ creg r ++ ")"
259−doOp v LGt [l, r] = v ++ "INTOP(>," ++ creg l ++ ", " ++ creg r ++ ")"
260−doOp v LGe [l, r] = v ++ "INTOP(>=," ++ creg l ++ ", " ++ creg r ++ ")"
250+bitOp v op ty args = v ++ "idris_b" ++ show (intTyWidth ty) ++ op ++ "(vm, " ++ intercalate ", " (map creg args) ++ ")"
251+
252+bitCoerce v op input output arg
253+ = v ++ "idris_b" ++ show (intTyWidth input) ++ op ++ show (intTyWidth output) ++ "(vm, " ++ creg arg ++ ")"
254+
255+signedTy :: IntTy -> String
256+signedTy t = "int" ++ show (intTyWidth t) ++ "_t"
257+
258+doOp v (LPlus ITNative) [l, r] = v ++ "ADD(" ++ creg l ++ ", " ++ creg r ++ ")"
259+doOp v (LMinus ITNative) [l, r] = v ++ "INTOP(-," ++ creg l ++ ", " ++ creg r ++ ")"
260+doOp v (LTimes ITNative) [l, r] = v ++ "MULT(" ++ creg l ++ ", " ++ creg r ++ ")"
261+doOp v (LUDiv ITNative) [l, r] = v ++ "UINTOP(/," ++ creg l ++ ", " ++ creg r ++ ")"
262+doOp v (LSDiv ITNative) [l, r] = v ++ "INTOP(/," ++ creg l ++ ", " ++ creg r ++ ")"
263+doOp v (LURem ITNative) [l, r] = v ++ "UINTOP(%," ++ creg l ++ ", " ++ creg r ++ ")"
264+doOp v (LSRem ITNative) [l, r] = v ++ "INTOP(%," ++ creg l ++ ", " ++ creg r ++ ")"
265+doOp v (LAnd ITNative) [l, r] = v ++ "INTOP(&," ++ creg l ++ ", " ++ creg r ++ ")"
266+doOp v (LOr ITNative) [l, r] = v ++ "INTOP(|," ++ creg l ++ ", " ++ creg r ++ ")"
267+doOp v (LXOr ITNative) [l, r] = v ++ "INTOP(^," ++ creg l ++ ", " ++ creg r ++ ")"
268+doOp v (LSHL ITNative) [l, r] = v ++ "INTOP(<<," ++ creg l ++ ", " ++ creg r ++ ")"
269+doOp v (LLSHR ITNative) [l, r] = v ++ "UINTOP(>>," ++ creg l ++ ", " ++ creg r ++ ")"
270+doOp v (LASHR ITNative) [l, r] = v ++ "INTOP(>>," ++ creg l ++ ", " ++ creg r ++ ")"
271+doOp v (LCompl ITNative) [x] = v ++ "INTOP(~," ++ creg x ++ ")"
272+doOp v (LEq ITNative) [l, r] = v ++ "INTOP(==," ++ creg l ++ ", " ++ creg r ++ ")"
273+doOp v (LLt ITNative) [l, r] = v ++ "INTOP(<," ++ creg l ++ ", " ++ creg r ++ ")"
274+doOp v (LLe ITNative) [l, r] = v ++ "INTOP(<=," ++ creg l ++ ", " ++ creg r ++ ")"
275+doOp v (LGt ITNative) [l, r] = v ++ "INTOP(>," ++ creg l ++ ", " ++ creg r ++ ")"
276+doOp v (LGe ITNative) [l, r] = v ++ "INTOP(>=," ++ creg l ++ ", " ++ creg r ++ ")"
261277
262278doOp v LFPlus [l, r] = v ++ "FLOATOP(+," ++ creg l ++ ", " ++ creg r ++ ")"
263279doOp v LFMinus [l, r] = v ++ "FLOATOP(-," ++ creg l ++ ", " ++ creg r ++ ")"
@@ -269,31 +285,30 @@ doOp v LFLe [l, r] = v ++ "FLOATBOP(<=," ++ creg l ++ ", " ++ creg r ++ ")"
269285doOp v LFGt [l, r] = v ++ "FLOATBOP(>," ++ creg l ++ ", " ++ creg r ++ ")"
270286doOp v LFGe [l, r] = v ++ "FLOATBOP(>=," ++ creg l ++ ", " ++ creg r ++ ")"
271287
272−doOp v LBPlus [l, r] = v ++ "idris_bigPlus(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
273−doOp v LBMinus [l, r] = v ++ "idris_bigMinus(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
274−doOp v LBDec [l] = v ++ "idris_bigMinus(vm, " ++ creg l ++ ", MKINT(1))"
275−doOp v LBTimes [l, r] = v ++ "idris_bigTimes(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
276−doOp v LBDiv [l, r] = v ++ "idris_bigDivide(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
277−doOp v LBMod [l, r] = v ++ "idris_bigMod(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
278−doOp v LBEq [l, r] = v ++ "idris_bigEq(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
279−doOp v LBLt [l, r] = v ++ "idris_bigLt(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
280−doOp v LBLe [l, r] = v ++ "idris_bigLe(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
281−doOp v LBGt [l, r] = v ++ "idris_bigGt(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
282−doOp v LBGe [l, r] = v ++ "idris_bigGe(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
288+doOp v (LPlus ITBig) [l, r] = v ++ "idris_bigPlus(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
289+doOp v (LMinus ITBig) [l, r] = v ++ "idris_bigMinus(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
290+doOp v (LTimes ITBig) [l, r] = v ++ "idris_bigTimes(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
291+doOp v (LSDiv ITBig) [l, r] = v ++ "idris_bigDivide(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
292+doOp v (LSRem ITBig) [l, r] = v ++ "idris_bigMod(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
293+doOp v (LEq ITBig) [l, r] = v ++ "idris_bigEq(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
294+doOp v (LLt ITBig) [l, r] = v ++ "idris_bigLt(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
295+doOp v (LLe ITBig) [l, r] = v ++ "idris_bigLe(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
296+doOp v (LGt ITBig) [l, r] = v ++ "idris_bigGt(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
297+doOp v (LGe ITBig) [l, r] = v ++ "idris_bigGe(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
283298
284299doOp v LStrConcat [l,r] = v ++ "idris_concat(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
285300doOp v LStrLt [l,r] = v ++ "idris_strlt(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
286301doOp v LStrEq [l,r] = v ++ "idris_streq(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
287302doOp v LStrLen [x] = v ++ "idris_strlen(vm, " ++ creg x ++ ")"
288303
289−doOp v LIntFloat [x] = v ++ "idris_castIntFloat(" ++ creg x ++ ")"
290−doOp v LFloatInt [x] = v ++ "idris_castFloatInt(" ++ creg x ++ ")"
291−doOp v LIntStr [x] = v ++ "idris_castIntStr(vm, " ++ creg x ++ ")"
292−doOp v LStrInt [x] = v ++ "idris_castStrInt(vm, " ++ creg x ++ ")"
293−doOp v LIntBig [x] = v ++ "idris_castIntBig(vm, " ++ creg x ++ ")"
294−doOp v LBigInt [x] = v ++ "idris_castBigInt(vm, " ++ creg x ++ ")"
295−doOp v LStrBig [x] = v ++ "idris_castStrBig(vm, " ++ creg x ++ ")"
296−doOp v LBigStr [x] = v ++ "idris_castBigStr(vm, " ++ creg x ++ ")"
304+doOp v (LIntFloat ITNative) [x] = v ++ "idris_castIntFloat(" ++ creg x ++ ")"
305+doOp v (LFloatInt ITNative) [x] = v ++ "idris_castFloatInt(" ++ creg x ++ ")"
306+doOp v (LSExt ITNative ITBig) [x] = v ++ "idris_castIntBig(vm, " ++ creg x ++ ")"
307+doOp v (LTrunc ITBig ITNative) [x] = v ++ "idris_castBigInt(vm, " ++ creg x ++ ")"
308+doOp v (LStrInt ITBig) [x] = v ++ "idris_castStrBig(vm, " ++ creg x ++ ")"
309+doOp v (LIntStr ITBig) [x] = v ++ "idris_castBigStr(vm, " ++ creg x ++ ")"
310+doOp v (LIntStr ITNative) [x] = v ++ "idris_castIntStr(vm, " ++ creg x ++ ")"
311+doOp v (LStrInt ITNative) [x] = v ++ "idris_castStrInt(vm, " ++ creg x ++ ")"
297312doOp v LFloatStr [x] = v ++ "idris_castFloatStr(vm, " ++ creg x ++ ")"
298313doOp v LStrFloat [x] = v ++ "idris_castStrFloat(vm, " ++ creg x ++ ")"
299314
@@ -301,143 +316,43 @@ doOp v LReadStr [x] = v ++ "idris_readStr(vm, GETPTR(" ++ creg x ++ "))"
301316doOp _ LPrintNum [x] = "printf(\"%ld\\n\", GETINT(" ++ creg x ++ "))"
302317doOp _ LPrintStr [x] = "fputs(GETSTR(" ++ creg x ++ "), stdout)"
303318
304−doOp v LIntB8 [x] = v ++ "idris_b8(vm, " ++ creg x ++ ")"
305−doOp v LIntB16 [x] = v ++ "idris_b16(vm, " ++ creg x ++ ")"
306−doOp v LIntB32 [x] = v ++ "idris_b32(vm, " ++ creg x ++ ")"
307−doOp v LIntB64 [x] = v ++ "idris_b64(vm, " ++ creg x ++ ")"
308−
309−doOp v LB32Int [x] = v ++ "idris_castB32Int(vm, " ++ creg x ++ ")"
310−
311−doOp v LB8Lt [x, y] = v ++ "idris_b8Lt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
312−doOp v LB8Lte [x, y] = v ++ "idris_b8Lte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
313−doOp v LB8Eq [x, y] = v ++ "idris_b8Eq(vm, " ++ creg x ++ "," ++ creg y ++ ")"
314−doOp v LB8Gte [x, y] = v ++ "idris_b8Gte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
315−doOp v LB8Gt [x, y] = v ++ "idris_b8Gt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
316−
317−doOp v LB8Shl [x, y] = v ++ "idris_b8Shl(vm, " ++ creg x ++ "," ++ creg y ++ ")"
318−doOp v LB8LShr [x, y] = v ++ "idris_b8Shr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
319−doOp v LB8AShr [x, y] = v ++ "idris_b8AShr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
320−doOp v LB8And [x, y] = v ++ "idris_b8And(vm, " ++ creg x ++ "," ++ creg y ++ ")"
321−doOp v LB8Or [x, y] = v ++ "idris_b8Or(vm, " ++ creg x ++ "," ++ creg y ++ ")"
322−doOp v LB8Xor [x, y] = v ++ "idris_b8Xor(vm, " ++ creg x ++ "," ++ creg y ++ ")"
323−doOp v LB8Compl [x] = v ++ "idris_b8Compl(vm, " ++ creg x ++ ")"
324−
325−doOp v LB8Plus [x, y] = v ++ "idris_b8Plus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
326−doOp v LB8Minus [x, y] = v ++ "idris_b8Minus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
327−doOp v LB8Times [x, y] = v ++ "idris_b8Times(vm, " ++ creg x ++ "," ++ creg y ++ ")"
328−doOp v LB8UDiv [x, y] = v ++ "idris_b8UDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
329−doOp v LB8SDiv [x, y] = v ++ "idris_b8SDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
330−doOp v LB8URem [x, y] = v ++ "idris_b8URem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
331−doOp v LB8SRem [x, y] = v ++ "idris_b8SRem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
332−
333−doOp v LB8Z16 [x] = v ++ "idris_b8Z16(vm, " ++ creg x ++ ")"
334−doOp v LB8Z32 [x] = v ++ "idris_b8Z32(vm, " ++ creg x ++ ")"
335−doOp v LB8Z64 [x] = v ++ "idris_b8Z64(vm, " ++ creg x ++ ")"
336−doOp v LB8S16 [x] = v ++ "idris_b8S16(vm, " ++ creg x ++ ")"
337−doOp v LB8S32 [x] = v ++ "idris_b8S32(vm, " ++ creg x ++ ")"
338−doOp v LB8S64 [x] = v ++ "idris_b8S64(vm, " ++ creg x ++ ")"
339−
340−doOp v LB16Lt [x, y] = v ++ "idris_b16Lt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
341−doOp v LB16Lte [x, y] = v ++ "idris_b16Lte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
342−doOp v LB16Eq [x, y] = v ++ "idris_b16Eq(vm, " ++ creg x ++ "," ++ creg y ++ ")"
343−doOp v LB16Gte [x, y] = v ++ "idris_b16Gte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
344−doOp v LB16Gt [x, y] = v ++ "idris_b16Gt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
345−
346−doOp v LB16Shl [x, y] = v ++ "idris_b16Shl(vm, " ++ creg x ++ "," ++ creg y ++ ")"
347−doOp v LB16LShr [x, y] = v ++ "idris_b16Shr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
348−doOp v LB16AShr [x, y] = v ++ "idris_b16AShr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
349−doOp v LB16And [x, y] = v ++ "idris_b16And(vm, " ++ creg x ++ "," ++ creg y ++ ")"
350−doOp v LB16Or [x, y] = v ++ "idris_b16Or(vm, " ++ creg x ++ "," ++ creg y ++ ")"
351−doOp v LB16Xor [x, y] = v ++ "idris_b16Xor(vm, " ++ creg x ++ "," ++ creg y ++ ")"
352−doOp v LB16Compl [x] = v ++ "idris_b16Compl(vm, " ++ creg x ++ ")"
353−
354−doOp v LB16Plus [x, y] =
355− v ++ "idris_b16Plus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
356−doOp v LB16Minus [x, y] =
357− v ++ "idris_b16Minus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
358−doOp v LB16Times [x, y] =
359− v ++ "idris_b16Times(vm, " ++ creg x ++ "," ++ creg y ++ ")"
360−doOp v LB16UDiv [x, y] =
361− v ++ "idris_b16UDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
362−doOp v LB16SDiv [x, y] =
363− v ++ "idris_b16SDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
364−doOp v LB16URem [x, y] =
365− v ++ "idris_b16URem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
366−doOp v LB16SRem [x, y] =
367− v ++ "idris_b16SRem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
368−
369−doOp v LB16Z32 [x] = v ++ "idris_b16Z32(vm, " ++ creg x ++ ")"
370−doOp v LB16Z64 [x] = v ++ "idris_b16Z64(vm, " ++ creg x ++ ")"
371−doOp v LB16S32 [x] = v ++ "idris_b16S32(vm, " ++ creg x ++ ")"
372−doOp v LB16S64 [x] = v ++ "idris_b16S64(vm, " ++ creg x ++ ")"
373−doOp v LB16T8 [x] = v ++ "idris_b16T8(vm, " ++ creg x ++ ")"
374−
375−doOp v LB32Lt [x, y] = v ++ "idris_b32Lt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
376−doOp v LB32Lte [x, y] = v ++ "idris_b32Lte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
377−doOp v LB32Eq [x, y] = v ++ "idris_b32Eq(vm, " ++ creg x ++ "," ++ creg y ++ ")"
378−doOp v LB32Gte [x, y] = v ++ "idris_b32Gte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
379−doOp v LB32Gt [x, y] = v ++ "idris_b32Gt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
380−
381−doOp v LB32Shl [x, y] = v ++ "idris_b32Shl(vm, " ++ creg x ++ "," ++ creg y ++ ")"
382−doOp v LB32LShr [x, y] = v ++ "idris_b32Shr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
383−doOp v LB32AShr [x, y] = v ++ "idris_b32AShr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
384−doOp v LB32And [x, y] = v ++ "idris_b32And(vm, " ++ creg x ++ "," ++ creg y ++ ")"
385−doOp v LB32Or [x, y] = v ++ "idris_b32Or(vm, " ++ creg x ++ "," ++ creg y ++ ")"
386−doOp v LB32Xor [x, y] = v ++ "idris_b32Xor(vm, " ++ creg x ++ "," ++ creg y ++ ")"
387−doOp v LB32Compl [x] = v ++ "idris_b32Compl(vm, " ++ creg x ++ ")"
388−
389−doOp v LB32Plus [x, y] =
390− v ++ "idris_b32Plus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
391−doOp v LB32Minus [x, y] =
392− v ++ "idris_b32Minus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
393−doOp v LB32Times [x, y] =
394− v ++ "idris_b32Times(vm, " ++ creg x ++ "," ++ creg y ++ ")"
395−doOp v LB32UDiv [x, y] =
396− v ++ "idris_b32UDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
397−doOp v LB32SDiv [x, y] =
398− v ++ "idris_b32SDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
399−doOp v LB32URem [x, y] =
400− v ++ "idris_b32URem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
401−doOp v LB32SRem [x, y] =
402− v ++ "idris_b32SRem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
403−
404−doOp v LB32Z64 [x] = v ++ "idris_b32Z64(vm, " ++ creg x ++ ")"
405−doOp v LB32S64 [x] = v ++ "idris_b32S64(vm, " ++ creg x ++ ")"
406−doOp v LB32T8 [x] = v ++ "idris_b32T8(vm, " ++ creg x ++ ")"
407−doOp v LB32T16 [x] = v ++ "idris_b32T16(vm, " ++ creg x ++ ")"
408−
409−doOp v LB64Lt [x, y] = v ++ "idris_b64Lt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
410−doOp v LB64Lte [x, y] = v ++ "idris_b64Lte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
411−doOp v LB64Eq [x, y] = v ++ "idris_b64Eq(vm, " ++ creg x ++ "," ++ creg y ++ ")"
412−doOp v LB64Gte [x, y] = v ++ "idris_b64Gte(vm, " ++ creg x ++ "," ++ creg y ++ ")"
413−doOp v LB64Gt [x, y] = v ++ "idris_b64Gt(vm, " ++ creg x ++ "," ++ creg y ++ ")"
414−
415−doOp v LB64Shl [x, y] = v ++ "idris_b64Shl(vm, " ++ creg x ++ "," ++ creg y ++ ")"
416−doOp v LB64LShr [x, y] = v ++ "idris_b64Shr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
417−doOp v LB64AShr [x, y] = v ++ "idris_b64AShr(vm, " ++ creg x ++ "," ++ creg y ++ ")"
418−doOp v LB64And [x, y] = v ++ "idris_b64And(vm, " ++ creg x ++ "," ++ creg y ++ ")"
419−doOp v LB64Or [x, y] = v ++ "idris_b64Or(vm, " ++ creg x ++ "," ++ creg y ++ ")"
420−doOp v LB64Xor [x, y] = v ++ "idris_b64Xor(vm, " ++ creg x ++ "," ++ creg y ++ ")"
421−doOp v LB64Compl [x] = v ++ "idris_b64Compl(vm, " ++ creg x ++ ")"
422−
423−doOp v LB64Plus [x, y] =
424− v ++ "idris_b64Plus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
425−doOp v LB64Minus [x, y] =
426− v ++ "idris_b64Minus(vm, " ++ creg x ++ "," ++ creg y ++ ")"
427−doOp v LB64Times [x, y] =
428− v ++ "idris_b64Times(vm, " ++ creg x ++ "," ++ creg y ++ ")"
429−doOp v LB64UDiv [x, y] =
430− v ++ "idris_b64UDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
431−doOp v LB64SDiv [x, y] =
432− v ++ "idris_b64SDiv(vm, " ++ creg x ++ "," ++ creg y ++ ")"
433−doOp v LB64URem [x, y] =
434− v ++ "idris_b64URem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
435−doOp v LB64SRem [x, y] =
436− v ++ "idris_b64SRem(vm, " ++ creg x ++ "," ++ creg y ++ ")"
437−
438−doOp v LB64T8 [x] = v ++ "idris_b64T8(vm, " ++ creg x ++ ")"
439−doOp v LB64T16 [x] = v ++ "idris_b64T16(vm, " ++ creg x ++ ")"
440−doOp v LB64T32 [x] = v ++ "idris_b64T32(vm, " ++ creg x ++ ")"
319+doOp v (LLt ty) [x, y] = bitOp v "Lt" ty [x, y]
320+doOp v (LLe ty) [x, y] = bitOp v "Lte" ty [x, y]
321+doOp v (LEq ty) [x, y] = bitOp v "Eq" ty [x, y]
322+doOp v (LGe ty) [x, y] = bitOp v "Gte" ty [x, y]
323+doOp v (LGt ty) [x, y] = bitOp v "Gt" ty [x, y]
324+
325+doOp v (LSHL ty) [x, y] = bitOp v "Shl" ty [x, y]
326+doOp v (LLSHR ty) [x, y] = bitOp v "Shr" ty [x, y]
327+doOp v (LASHR ty) [x, y] = bitOp v "AShr" ty [x, y]
328+doOp v (LAnd ty) [x, y] = bitOp v "And" ty [x, y]
329+doOp v (LOr ty) [x, y] = bitOp v "Or" ty [x, y]
330+doOp v (LXOr ty) [x, y] = bitOp v "Xor" ty [x, y]
331+doOp v (LCompl ty) [x] = bitOp v "Compl" ty [x]
332+
333+doOp v (LPlus ty) [x, y] = bitOp v "Plus" ty [x, y]
334+doOp v (LMinus ty) [x, y] = bitOp v "Minus" ty [x, y]
335+doOp v (LTimes ty) [x, y] = bitOp v "Times" ty [x, y]
336+doOp v (LUDiv ty) [x, y] = bitOp v "UDiv" ty [x, y]
337+doOp v (LSDiv ty) [x, y] = bitOp v "SDiv" ty [x, y]
338+doOp v (LURem ty) [x, y] = bitOp v "URem" ty [x, y]
339+doOp v (LSRem ty) [x, y] = bitOp v "SRem" ty [x, y]
340+
341+doOp v (LSExt from ITBig) [x] = v ++ "MKBIGSI(vm, (" ++ signedTy from ++ ")" ++ creg x ++ "->info.bits" ++ show (intTyWidth from) ++ ")"
342+doOp v (LSExt ITNative to) [x] = v ++ "idris_b" ++ show (intTyWidth to) ++ "const(vm, GETINT(" ++ creg x ++ "))"
343+doOp v (LSExt from ITNative) [x] = v ++ "MKINT((i_int)((" ++ signedTy from ++ ")" ++ creg x ++ "->info.bits" ++ show (intTyWidth from) ++ "))"
344+doOp v (LSExt from to) [x]
345+ | intTyWidth from < intTyWidth to = bitCoerce v "S" from to x
346+doOp v (LZExt ITNative to) [x] = v ++ "idris_b" ++ show (intTyWidth to) ++ "const(vm, (uintptr_t)GETINT(" ++ creg x ++ ")"
347+doOp v (LZExt from ITNative) [x] = v ++ "MKINT((i_int)" ++ creg x ++ "->info.bits" ++ show (intTyWidth from) ++ ")"
348+doOp v (LZExt from ITBig) [x] = v ++ "MKBIGUI(vm, " ++ creg x ++ "->info.bits" ++ show (intTyWidth from) ++ ")"
349+doOp v (LZExt from to) [x]
350+ | intTyWidth from < intTyWidth to = bitCoerce v "Z" from to x
351+doOp v (LTrunc ITNative to) [x] = v ++ "idris_b" ++ show (intTyWidth to) ++ "const(vm, GETINT(" ++ creg x ++ "))"
352+doOp v (LTrunc from ITNative) [x] = v ++ "MKINT((i_int)" ++ creg x ++ "->info.bits" ++ show (intTyWidth from) ++ ")"
353+doOp v (LTrunc ITBig to) [x] = v ++ "idris_b" ++ show (intTyWidth to) ++ "const(vm, mpz_get_ui(GETMPZ(" ++ creg x ++ "))"
354+doOp v (LTrunc from to) [x]
355+ | intTyWidth from > intTyWidth to = bitCoerce v "T" from to x
441356
442357doOp v LFExp [x] = v ++ "MKFLOAT(exp(GETFLOAT(" ++ creg x ++ ")))"
443358doOp v LFLog [x] = v ++ "MKFLOAT(log(GETFLOAT(" ++ creg x ++ ")))"
@@ -464,7 +379,7 @@ doOp v LStdErr [] = v ++ "MKPTR(vm, stderr)"
464379doOp v LFork [x] = v ++ "MKPTR(vm, vmThread(vm, " ++ cname (MN 0 "EVAL") ++ ", " ++ creg x ++ "))"
465380doOp v LPar [x] = v ++ creg x -- "MKPTR(vm, vmThread(vm, " ++ cname (MN 0 "EVAL") ++ ", " ++ creg x ++ "))"
466381doOp v LVMPtr [] = v ++ "MKPTR(vm, vm)"
467−doOp v LChInt args = v ++ creg (last args)
468−doOp v LIntCh args = v ++ creg (last args)
382+doOp v (LChInt ITNative) args = v ++ creg (last args)
383+doOp v (LIntCh ITNative) args = v ++ creg (last args)
469384doOp v LNoOp args = v ++ creg (last args)
470385doOp _ op _ = "FAIL /* " ++ show op ++ " */"
src/IRTS/CodegenJava.hs+142−215
@@ -16,6 +16,7 @@ import Control.Monad.Trans.State
1616import Data.Char
1717import Data.Maybe (fromJust)
1818import Data.List (isPrefixOf, isSuffixOf, intercalate, foldl')
19+import Data.Int
1920import qualified Data.Text as T
2021import qualified Data.Text.IO as TIO
2122import Language.Java.Parser
@@ -468,7 +469,39 @@ integerType :: ClassType
468469integerType = ClassType [(Ident "Integer", [])]
469470
470471longType :: ClassType
471−longType = ClassType [(Ident "Integer", [])]
472+longType = ClassType [(Ident "Long", [])]
473+
474+nextIntTy :: IntTy -> IntTy
475+nextIntTy IT8 = IT16
476+nextIntTy IT16 = IT32
477+nextIntTy IT32 = IT64
478+nextIntTy IT64 = IT64
479+nextIntTy ITNative = IT64
480+
481+intTyToIdent :: IntTy -> Ident
482+intTyToIdent IT8 = Ident "Byte"
483+intTyToIdent IT16 = Ident "Short"
484+intTyToIdent IT32 = Ident "Integer"
485+intTyToIdent IT64 = Ident "Long"
486+intTyToIdent ITNative = Ident "Integer"
487+intTyToIdent ITBig = Ident "BigInteger"
488+
489+intTyToClass :: IntTy -> ClassType
490+intTyToClass ty = ClassType [(intTyToIdent ty, [])]
491+
492+intTyToMethod :: IntTy -> String
493+intTyToMethod IT8 = "byteValue"
494+intTyToMethod IT16 = "shortValue"
495+intTyToMethod IT32 = "intValue"
496+intTyToMethod IT64 = "longValue"
497+intTyToMethod ITNative = "intValue"
498+
499+intTyToPrimTy :: IntTy -> PrimType
500+intTyToPrimTy IT8 = ByteT
501+intTyToPrimTy IT16 = ShortT
502+intTyToPrimTy IT32 = IntT
503+intTyToPrimTy IT64 = LongT
504+intTyToPrimTy ITNative = IntT
472505
473506bigIntegerType :: ClassType
474507bigIntegerType = ClassType [(Ident "BigInteger", [])]
@@ -962,7 +995,7 @@ mkStringAtIndex var indexExp =
962995 <$> mkVarAccess (Just stringType) var
963996
964997mkForeignType :: FType -> Maybe ClassType
965−mkForeignType FInt = return integerType
998+mkForeignType (FInt ty) = return (intTyToClass ty)
966999mkForeignType FChar = return integerType
9671000mkForeignType FString = return stringType
9681001mkForeignType FPtr = return objectType
@@ -971,14 +1004,14 @@ mkForeignType FAny = return objectType
9711004mkForeignType FUnit = Nothing
9721005
9731006mkForeignVarAccess :: FType -> LVar -> CodeGeneration Exp
974−mkForeignVarAccess FInt var =
975− (\ var -> MethodInv $ PrimaryMethodCall (var)
1007+mkForeignVarAccess (FInt ty) var =
1008+ (\ var -> MethodInv $ PrimaryMethodCall var
9761009 []
977− (Ident "intValue")
1010+ (Ident (intTyToMethod ty))
9781011 []
9791012 )
980− <$> mkVarAccess (Just integerType) var
981−mkForeignVarAccess FChar var = Cast (PrimType CharT) <$> mkForeignVarAccess FInt var
1013+ <$> mkVarAccess (Just $ intTyToClass ty) var
1014+mkForeignVarAccess FChar var = Cast (PrimType CharT) <$> mkForeignVarAccess (FInt IT32) var
9821015mkForeignVarAccess FDouble var =
9831016 (\ var -> MethodInv $ PrimaryMethodCall (var)
9841017 []
@@ -989,12 +1022,12 @@ mkForeignVarAccess FDouble var =
9891022mkForeignVarAccess otherType var = mkVarAccess (mkForeignType otherType) var
9901023
9911024mkFromForeignType :: FType -> Exp -> Exp
992−mkFromForeignType FInt from =
993− MethodInv $ TypeMethodCall (J.Name [Ident "Integer"])
1025+mkFromForeignType (FInt ty) from =
1026+ MethodInv $ TypeMethodCall (J.Name [intTyToIdent ty])
9941027 []
9951028 (Ident "valueOf")
9961029 [from]
997−mkFromForeignType FChar from = mkFromForeignType FInt from
1030+mkFromForeignType FChar from = mkFromForeignType (FInt IT32) from
9981031mkFromForeignType FDouble from =
9991032 MethodInv $ TypeMethodCall (J.Name [Ident "Double"])
10001033 []
@@ -1225,7 +1258,9 @@ mkExp (SCon conId name args) =
12251258mkExp (SCase var alts) = mkCase False var alts
12261259mkExp (SChkCase var alts) = mkCase True var alts
12271260mkExp (SProj var i) = mkProjection var i
1228−mkExp (SConst (I x)) = return $ mkPrimitive "Integer" (Int (toInteger x))
1261+mkExp (SConst (I x)) =
1262+ let x' :: Int32; x' = fromInteger (toInteger x) in
1263+ return $ mkPrimitive "Integer" (Int (fromInteger (toInteger x')))
12291264mkExp (SConst (BI x)) =
12301265 return $ InstanceCreation []
12311266 (ClassType [(Ident "BigInteger", [])])
@@ -1251,24 +1286,22 @@ mkExp (SConst (PtrType)) = return $ mkClass objectType
12511286mkExp (SConst (VoidType)) = return $ mkClass voidType
12521287mkExp (SConst (Forgot)) = return $ mkClass objectType
12531288mkExp (SForeign _ fType meth args) = mkForeignInvoke fType meth args
1254−mkExp (SOp LPlus args) = mkBinOpExp integerType Add args
1255−mkExp (SOp LMinus args) = mkBinOpExp integerType Sub args
1256−mkExp (SOp LTimes args) = mkBinOpExp integerType Mult args
1257−mkExp (SOp LDiv args) = mkBinOpExp integerType Div args
1258−mkExp (SOp LMod args) = mkBinOpExp integerType Rem args
1259−mkExp (SOp LAnd args) = mkBinOpExp integerType And args
1260−mkExp (SOp LOr args) = mkBinOpExp integerType Or args
1261−mkExp (SOp LXOr args) = mkBinOpExp integerType Xor args
1262−mkExp (SOp LCompl [var]) =
1263− PreBitCompl <$> mkVarAccess (Just $ integerType) var
1264−mkExp (SOp LSHL args) = mkBinOpExp integerType LShift args
1265−mkExp (SOp LSHR args) = mkBinOpExp integerType RShift args
1266−mkExp (SOp LEq args) =
1267− mkMethodOpChain1 (mkBoolToNumber integerType) objectType "equals" args
1268−mkExp (SOp LLt args) = mkLogicalBinOpExp integerType LThan args
1269−mkExp (SOp LLe args) = mkLogicalBinOpExp integerType LThanE args
1270−mkExp (SOp LGt args) = mkLogicalBinOpExp integerType GThan args
1271−mkExp (SOp LGe args) = mkLogicalBinOpExp integerType GThanE args
1289+mkExp (SOp (LPlus ITNative) args) = mkExp (SOp (LPlus IT32) args)
1290+mkExp (SOp (LMinus ITNative) args) = mkExp (SOp (LMinus IT32) args)
1291+mkExp (SOp (LTimes ITNative) args) = mkExp (SOp (LTimes IT32) args)
1292+mkExp (SOp (LSDiv ITNative) args) = mkExp (SOp (LSDiv IT32) args)
1293+mkExp (SOp (LSRem ITNative) args) = mkExp (SOp (LSRem IT32) args)
1294+mkExp (SOp (LAnd ITNative) args) = mkExp (SOp (LAnd IT32) args)
1295+mkExp (SOp (LOr ITNative) args) = mkExp (SOp (LOr IT32) args)
1296+mkExp (SOp (LXOr ITNative) args) = mkExp (SOp (LXOr IT32) args)
1297+mkExp (SOp (LCompl ITNative) args) = mkExp (SOp (LCompl IT32) args)
1298+mkExp (SOp (LSHL ITNative) args) = mkExp (SOp (LSHL IT32) args)
1299+mkExp (SOp (LASHR ITNative) args) = mkExp (SOp (LASHR IT32) args)
1300+mkExp (SOp (LEq ITNative) args) = mkExp (SOp (LEq IT32) args)
1301+mkExp (SOp (LLt ITNative) args) = mkExp (SOp (LLt IT32) args)
1302+mkExp (SOp (LLe ITNative) args) = mkExp (SOp (LLe IT32) args)
1303+mkExp (SOp (LGt ITNative) args) = mkExp (SOp (LGt IT32) args)
1304+mkExp (SOp (LGe ITNative) args) = mkExp (SOp (LGe IT32) args)
12721305mkExp (SOp LFPlus args) = mkBinOpExp doubleType Add args
12731306mkExp (SOp LFMinus args) = mkBinOpExp doubleType Sub args
12741307mkExp (SOp LFTimes args) = mkBinOpExp doubleType Mult args
@@ -1279,40 +1312,40 @@ mkExp (SOp LFLt args) = mkLogicalBinOpExp integerType LThan args
12791312mkExp (SOp LFLe args) = mkLogicalBinOpExp integerType LThanE args
12801313mkExp (SOp LFGt args) = mkLogicalBinOpExp integerType GThan args
12811314mkExp (SOp LFGe args) = mkLogicalBinOpExp integerType GThanE args
1282−mkExp (SOp LBPlus args) = mkMethodOpChain1 id bigIntegerType "add" args
1283−mkExp (SOp LBMinus args) = mkMethodOpChain1 id bigIntegerType "subtract" args
1284−mkExp (SOp LBTimes args) = mkMethodOpChain1 id bigIntegerType "multiply" args
1285−mkExp (SOp LBDiv args) = mkMethodOpChain1 id bigIntegerType "divide" args
1286−mkExp (SOp LBMod args) = mkMethodOpChain1 id bigIntegerType "mod" args
1287−mkExp (SOp LBEq args) =
1315+mkExp (SOp (LPlus ITBig) args) = mkMethodOpChain1 id bigIntegerType "add" args
1316+mkExp (SOp (LMinus ITBig) args) = mkMethodOpChain1 id bigIntegerType "subtract" args
1317+mkExp (SOp (LTimes ITBig) args) = mkMethodOpChain1 id bigIntegerType "multiply" args
1318+mkExp (SOp (LSDiv ITBig) args) = mkMethodOpChain1 id bigIntegerType "divide" args
1319+mkExp (SOp (LSRem ITBig) args) = mkMethodOpChain1 id bigIntegerType "mod" args
1320+mkExp (SOp (LEq ITBig) args) =
12881321 mkMethodOpChain1 (mkBoolToNumber bigIntegerType) bigIntegerType "equals" args
1289−mkExp (SOp LBLt args) =
1322+mkExp (SOp (LLt ITBig) args) =
12901323 mkMethodOpChain1 ( mkBoolToNumber bigIntegerType
12911324 . mkPartialOrder SLt
12921325 )
12931326 bigIntegerType
1294− "compare"
1327+ "compareTo"
12951328 args
1296−mkExp (SOp LBLe args) =
1329+mkExp (SOp (LLe ITBig) args) =
12971330 mkMethodOpChain1 ( mkBoolToNumber bigIntegerType
12981331 . mkPartialOrder SLe
12991332 )
13001333 bigIntegerType
1301− "compare"
1334+ "compareTo"
13021335 args
1303−mkExp (SOp LBGt args) =
1336+mkExp (SOp (LGt ITBig) args) =
13041337 mkMethodOpChain1 ( mkBoolToNumber bigIntegerType
13051338 . mkPartialOrder SGt
13061339 )
13071340 bigIntegerType
1308− "compare"
1341+ "compareTo"
13091342 args
1310−mkExp (SOp LBGe args) =
1343+mkExp (SOp (LGe ITBig) args) =
13111344 mkMethodOpChain1 ( mkBoolToNumber bigIntegerType
13121345 . mkPartialOrder SGe
13131346 )
13141347 bigIntegerType
1315− "compare"
1348+ "compareTo"
13161349 args
13171350mkExp (SOp LStrConcat args) =
13181351 mkMethodOpChain (\ exp -> InstanceCreation []
@@ -1329,158 +1362,56 @@ mkExp (SOp LStrLt args@[_, _]) =
13291362 . mkPartialOrder SLt
13301363 )
13311364 stringType
1332− "compare"
1365+ "compareTo"
13331366 args
13341367mkExp (SOp LStrEq args@[_, _]) =
13351368 mkMethodOpChain1 ( mkBoolToNumber integerType)
13361369 stringType
13371370 "equals"
13381371 args
1339−mkExp (SOp LStrLen [arg]) =
1372+mkExp (SOp LStrLen [arg]) =
13401373 (\ var -> MethodInv $ PrimaryMethodCall var [] (Ident "length") [])
13411374 <$> mkVarAccess (Just stringType) arg
1342−mkExp (SOp LIntFloat [arg]) =
1343− mkPrimitiveCast integerType doubleType arg
1344−mkExp (SOp LFloatInt [arg]) =
1345− mkPrimitiveCast doubleType integerType arg
1346−mkExp (SOp LIntStr [arg]) =
1347− mkToString integerType arg
1348−mkExp (SOp LStrInt [arg]) =
1349− mkPrimitiveCast stringType integerType arg
1375+mkExp (SOp (LIntFloat ity) [arg]) =
1376+ mkPrimitiveCast (intTyToClass ity) doubleType arg
1377+mkExp (SOp (LFloatInt ity) [arg]) =
1378+ mkPrimitiveCast doubleType (intTyToClass ity) arg
1379+mkExp (SOp (LIntStr ITBig) [arg]) =
1380+ (\ var -> InstanceCreation [] bigIntegerType [var] Nothing)
1381+ <$> mkVarAccess (Just stringType) arg
1382+mkExp (SOp (LIntStr ity) [arg]) =
1383+ mkToString (intTyToClass ity) arg
1384+mkExp (SOp (LStrInt ity) [arg]) =
1385+ mkPrimitiveCast stringType (intTyToClass ity) arg
13501386mkExp (SOp LFloatStr [arg]) =
13511387 mkToString doubleType arg
13521388mkExp (SOp LStrFloat [arg]) =
13531389 mkPrimitiveCast doubleType stringType arg
1354−mkExp (SOp LIntBig [arg]) =
1390+mkExp (SOp (LSExt ITNative ITBig) [arg]) =
13551391 mkPrimitiveCast integerType bigIntegerType arg
1356−mkExp (SOp LBigInt [arg]) =
1392+mkExp (SOp (LTrunc ITBig ITNative) [arg]) =
13571393 mkPrimitiveCast bigIntegerType integerType arg
1358−mkExp (SOp LStrBig [arg]) =
1359− (\ var -> InstanceCreation [] bigIntegerType [var] Nothing)
1360− <$> mkVarAccess (Just stringType) arg
1361−mkExp (SOp LBigStr [arg]) =
1362− mkToString bigIntegerType arg
1363−mkExp (SOp LChInt [arg]) =
1394+mkExp (SOp (LChInt ITNative) [arg]) =
13641395 mkVarAccess (Just integerType) arg
1365−mkExp (SOp LIntCh [arg]) =
1396+mkExp (SOp (LIntCh ITNative) [arg]) =
13661397 mkVarAccess (Just integerType) arg
13671398mkExp (SOp LPrintNum [arg]) =
13681399 mkSystemOutPrint <$> (mkVarAccess Nothing arg)
13691400mkExp (SOp LPrintStr [arg]) =
13701401 mkSystemOutPrint <$> (mkVarAccess (Just stringType) arg)
13711402mkExp (SOp LReadStr [arg]) = mkExp (SForeign LANG_C FString "idris_readStr" [(FPtr, arg)])
1372−mkExp (SOp LB8Lt args) = mkLogicalBinOpExp byteType LThan args
1373−mkExp (SOp LB8Lte args) = mkLogicalBinOpExp byteType LThanE args
1374−mkExp (SOp LB8Eq args) =
1375− mkMethodOpChain1 (mkBoolToNumber byteType) byteType "equals" args
1376−mkExp (SOp LB8Gt args) = mkLogicalBinOpExp byteType GThan args
1377−mkExp (SOp LB8Gte args) = mkLogicalBinOpExp byteType GThanE args
1378−mkExp (SOp LB8Plus args) = mkBinOpExp byteType Add args
1379−mkExp (SOp LB8Minus args) = mkBinOpExp byteType Sub args
1380−mkExp (SOp LB8Times args) = mkBinOpExp byteType Mult args
1381−mkExp (SOp LB8UDiv args) = mkBinOpExpConv "shortValue" ShortT byteType Div args
1382−mkExp (SOp LB8SDiv args) = mkBinOpExp byteType Div args
1383−mkExp (SOp LB8URem args) = mkBinOpExpConv "shortValue" ShortT byteType Rem args
1384−mkExp (SOp LB8SRem args) = mkBinOpExp byteType Rem args
1385−mkExp (SOp LB8Shl args) = mkBinOpExp byteType LShift args
1386−mkExp (SOp LB8LShr args) = mkBinOpExp byteType RRShift args
1387−mkExp (SOp LB8AShr args) = mkBinOpExp byteType RShift args
1388−mkExp (SOp LB8And args) = mkBinOpExp byteType And args
1389−mkExp (SOp LB8Or args) = mkBinOpExp byteType Or args
1390−mkExp (SOp LB8Xor args) = mkBinOpExp byteType Xor args
1391−mkExp (SOp LB8Compl [var]) =
1392− PreBitCompl <$> mkVarAccess (Just $ byteType) var
1393−mkExp (SOp LB8Z16 [var]) = mkZeroExt "shortValue" 8 byteType shortType var
1394−mkExp (SOp LB8Z32 [var]) = mkZeroExt "intValue" 8 byteType integerType var
1395−mkExp (SOp LB8Z64 [var]) = mkZeroExt "longValue" 8 byteType longType var
1396−mkExp (SOp LB8S16 [var]) = mkSignedExt "shortValue" byteType shortType var
1397−mkExp (SOp LB8S32 [var]) = mkSignedExt "intValue" byteType integerType var
1398−mkExp (SOp LB8S64 [var]) = mkSignedExt "longValue" byteType longType var
1399−mkExp (SOp LB16Lt args) = mkLogicalBinOpExp shortType LThan args
1400−mkExp (SOp LB16Lte args) = mkLogicalBinOpExp shortType LThanE args
1401−mkExp (SOp LB16Eq args) =
1402− mkMethodOpChain1 (mkBoolToNumber shortType) shortType "equals" args
1403−mkExp (SOp LB16Gt args) = mkLogicalBinOpExp shortType GThan args
1404−mkExp (SOp LB16Gte args) = mkLogicalBinOpExp shortType GThanE args
1405−mkExp (SOp LB16Plus args) = mkBinOpExp shortType Add args
1406−mkExp (SOp LB16Minus args) = mkBinOpExp shortType Sub args
1407−mkExp (SOp LB16Times args) = mkBinOpExp shortType Mult args
1408−mkExp (SOp LB16UDiv args) = mkBinOpExpConv "intValue" IntT shortType Div args
1409−mkExp (SOp LB16SDiv args) = mkBinOpExp shortType Div args
1410−mkExp (SOp LB16URem args) = mkBinOpExpConv "intValue" IntT shortType Rem args
1411−mkExp (SOp LB16SRem args) = mkBinOpExp shortType Rem args
1412−mkExp (SOp LB16Shl args) = mkBinOpExp shortType LShift args
1413−mkExp (SOp LB16LShr args) = mkBinOpExp shortType RRShift args
1414−mkExp (SOp LB16AShr args) = mkBinOpExp shortType RShift args
1415−mkExp (SOp LB16And args) = mkBinOpExp shortType And args
1416−mkExp (SOp LB16Or args) = mkBinOpExp shortType Or args
1417−mkExp (SOp LB16Xor args) = mkBinOpExp shortType Xor args
1418−mkExp (SOp LB16Compl [var]) =
1419− PreBitCompl <$> mkVarAccess (Just $ shortType) var
1420−mkExp (SOp LB16Z32 [var]) = mkZeroExt "intValue" 16 shortType integerType var
1421−mkExp (SOp LB16Z64 [var]) = mkZeroExt "longValue" 16 shortType longType var
1422−mkExp (SOp LB16S32 [var]) = mkSignedExt "intValue" shortType integerType var
1423−mkExp (SOp LB16S64 [var]) = mkSignedExt "longValue" shortType longType var
1424−mkExp (SOp LB16T8 [var]) =
1425− (\ var -> MethodInv $
1426− TypeMethodCall (J.Name [Ident "Byte"])
1427− []
1428− (Ident "valueOf")
1429− [ MethodInv
1430− $ PrimaryMethodCall var [] (Ident "byteValue") [] ]
1431− )
1432− <$> mkVarAccess (Just $ shortType) var
1433−mkExp (SOp LB32Lt args) = mkLogicalBinOpExp integerType LThan args
1434−mkExp (SOp LB32Lte args) = mkLogicalBinOpExp integerType LThanE args
1435−mkExp (SOp LB32Eq args) =
1436− mkMethodOpChain1 (mkBoolToNumber integerType) integerType "equals" args
1437−mkExp (SOp LB32Gt args) = mkLogicalBinOpExp integerType GThan args
1438−mkExp (SOp LB32Gte args) = mkLogicalBinOpExp integerType GThanE args
1439−mkExp (SOp LB32Plus args) = mkBinOpExp integerType Add args
1440−mkExp (SOp LB32Minus args) = mkBinOpExp integerType Sub args
1441−mkExp (SOp LB32Times args) = mkBinOpExp integerType Mult args
1442−mkExp (SOp LB32UDiv args) = mkBinOpExpConv "longValue" LongT integerType Div args
1443−mkExp (SOp LB32SDiv args) = mkBinOpExp integerType Div args
1444−mkExp (SOp LB32URem args) = mkBinOpExpConv "longValue" LongT integerType Rem args
1445−mkExp (SOp LB32SRem args) = mkBinOpExp integerType Rem args
1446−mkExp (SOp LB32Shl args) = mkBinOpExp integerType LShift args
1447−mkExp (SOp LB32LShr args) = mkBinOpExp integerType RRShift args
1448−mkExp (SOp LB32AShr args) = mkBinOpExp integerType RShift args
1449−mkExp (SOp LB32And args) = mkBinOpExp integerType And args
1450−mkExp (SOp LB32Or args) = mkBinOpExp integerType Or args
1451−mkExp (SOp LB32Xor args) = mkBinOpExp integerType Xor args
1452−mkExp (SOp LB32Compl [var]) =
1453− PreBitCompl <$> mkVarAccess (Just $ integerType) var
1454−mkExp (SOp LB32Z64 [var]) = mkZeroExt "longValue" 32 integerType longType var
1455−mkExp (SOp LB32S64 [var]) = mkSignedExt "longValue" integerType longType var
1456−mkExp (SOp LB32T8 [var]) =
1457− (\ var -> MethodInv
1458− $ TypeMethodCall (J.Name [Ident "Byte"])
1459− []
1460− (Ident "valueOf")
1461− [ MethodInv $ PrimaryMethodCall var [] (Ident "byteValue") [] ]
1462− )
1463− <$> mkVarAccess (Just $ integerType) var
1464−mkExp (SOp LB32T16 [var]) =
1465− (\ var -> MethodInv
1466− $ TypeMethodCall (J.Name [Ident "Short"])
1467− []
1468− (Ident "valueOf")
1469− [ MethodInv $ PrimaryMethodCall var [] (Ident "shortValue") [] ]
1470− )
1471− <$> mkVarAccess (Just $ integerType) var
1472−mkExp (SOp LB64Lt args) = mkLogicalBinOpExp longType LThan args
1473−mkExp (SOp LB64Lte args) = mkLogicalBinOpExp longType LThanE args
1474−mkExp (SOp LB64Eq args) =
1475− mkMethodOpChain1 (mkBoolToNumber longType) longType "equals" args
1476−mkExp (SOp LB64Gt args) = mkLogicalBinOpExp longType GThan args
1477−mkExp (SOp LB64Gte args) = mkLogicalBinOpExp longType GThanE args
1478−mkExp (SOp LB64Plus args) = mkBinOpExp longType Add args
1479−mkExp (SOp LB64Minus args) = mkBinOpExp longType Sub args
1480−mkExp (SOp LB64Times args) = mkBinOpExp longType Mult args
1481−mkExp (SOp LB64UDiv (arg:args)) = do
1403+mkExp (SOp (LLt ty) args) = mkLogicalBinOpExp (intTyToClass ty) LThan args
1404+mkExp (SOp (LLe ty) args) = mkLogicalBinOpExp (intTyToClass ty) LThanE args
1405+mkExp (SOp (LEq ty) args) =
1406+ mkMethodOpChain1 (mkBoolToNumber (intTyToClass ty)) (intTyToClass ty) "equals" args
1407+mkExp (SOp (LGt ty) args) = mkLogicalBinOpExp (intTyToClass ty) GThan args
1408+mkExp (SOp (LGe ty) args) = mkLogicalBinOpExp (intTyToClass ty) GThanE args
1409+mkExp (SOp (LPlus ty) args) = mkBinOpExp (intTyToClass ty) Add args
1410+mkExp (SOp (LMinus ty) args) = mkBinOpExp (intTyToClass ty) Sub args
1411+mkExp (SOp (LTimes ty) args) = mkBinOpExp (intTyToClass ty) Mult args
1412+mkExp (SOp (LUDiv IT64) (arg:args)) = do
14821413 (arg:args) <- mapM (mkVarAccess (Just longType)) (arg:args)
1483− return $ foldl' (\ exp arg ->
1414+ return $ foldl (\ exp arg ->
14841415 MethodInv $ PrimaryMethodCall
14851416 ( MethodInv $ PrimaryMethodCall
14861417 ( MethodInv $ TypeMethodCall (J.Name [Ident "BigInteger"])
@@ -1502,10 +1433,16 @@ mkExp (SOp LB64UDiv (arg:args)) = do
15021433 )
15031434 arg
15041435 args
1505−mkExp (SOp LB64SDiv args) = mkBinOpExp longType Div args
1506−mkExp (SOp LB64URem (arg:args)) = do
1436+mkExp (SOp (LUDiv ty) args) =
1437+ mkBinOpExpConv (intTyToMethod $ nextIntTy ty)
1438+ (intTyToPrimTy $ nextIntTy ty)
1439+ (intTyToClass ty)
1440+ Div
1441+ args
1442+mkExp (SOp (LSDiv ty) args) = mkBinOpExp (intTyToClass ty) Div args
1443+mkExp (SOp (LURem IT64) (arg:args)) = do
15071444 (arg:args) <- mapM (mkVarAccess (Just longType)) (arg:args)
1508− return $ foldl' (\ exp arg ->
1445+ return $ foldl (\ exp arg ->
15091446 MethodInv $ PrimaryMethodCall
15101447 ( MethodInv $ PrimaryMethodCall
15111448 ( MethodInv $ TypeMethodCall (J.Name [Ident "BigInteger"])
@@ -1527,46 +1464,36 @@ mkExp (SOp LB64URem (arg:args)) = do
15271464 )
15281465 arg
15291466 args
1530−mkExp (SOp LB64SRem args) = mkBinOpExp longType Rem args
1531−mkExp (SOp LB64Shl args) = mkBinOpExp longType LShift args
1532−mkExp (SOp LB64LShr args) = mkBinOpExp longType RRShift args
1533−mkExp (SOp LB64AShr args) = mkBinOpExp longType RShift args
1534−mkExp (SOp LB64And args) = mkBinOpExp longType And args
1535−mkExp (SOp LB64Or args) = mkBinOpExp longType Or args
1536−mkExp (SOp LB64Xor args) = mkBinOpExp longType Xor args
1537−mkExp (SOp LB64Compl [var]) =
1538− PreBitCompl <$> mkVarAccess (Just $ longType) var
1539−mkExp (SOp LB64T8 [var]) =
1540− (\ var -> MethodInv
1541− $ TypeMethodCall (J.Name [Ident "Byte"])
1542− []
1543− (Ident "valueOf")
1544− [ MethodInv
1545− $ PrimaryMethodCall var [] (Ident "byteValue") []
1546− ]
1547− )
1548− <$> mkVarAccess (Just $ longType) var
1549−mkExp (SOp LB64T16 [var]) =
1550− (\ var -> MethodInv
1551− $ TypeMethodCall (J.Name [Ident "Short"])
1552− []
1553− (Ident "valueOf")
1554− [ MethodInv $ PrimaryMethodCall var [] (Ident "shortValue") [] ]
1555− )
1556− <$> mkVarAccess (Just $ longType) var
1557−mkExp (SOp LB64T32 [var]) =
1558− (\ var -> MethodInv
1559− $ TypeMethodCall (J.Name [Ident "Integer"])
1560− []
1561− (Ident "valueOf")
1562− [ MethodInv $ PrimaryMethodCall var [] (Ident "intValue") [] ]
1467+mkExp (SOp (LURem ty) args) =
1468+ mkBinOpExpConv (intTyToMethod $ nextIntTy ty)
1469+ (intTyToPrimTy $ nextIntTy ty)
1470+ (intTyToClass ty)
1471+ Rem
1472+ args
1473+mkExp (SOp (LSRem ty) args) = mkBinOpExp (intTyToClass ty) Rem args
1474+mkExp (SOp (LSHL ty) args) = mkBinOpExp (intTyToClass ty) LShift args
1475+mkExp (SOp (LLSHR ty) args) = mkBinOpExp (intTyToClass ty) RRShift args
1476+mkExp (SOp (LASHR ty) args) = mkBinOpExp (intTyToClass ty) RShift args
1477+mkExp (SOp (LAnd ty) args) = mkBinOpExp (intTyToClass ty) And args
1478+mkExp (SOp (LOr ty) args) = mkBinOpExp (intTyToClass ty) Or args
1479+mkExp (SOp (LXOr ty) args) = mkBinOpExp (intTyToClass ty) Xor args
1480+mkExp (SOp (LCompl ty) [var]) = PreBitCompl <$> mkVarAccess (Just $ intTyToClass ty) var
1481+mkExp (SOp (LZExt from to) [var])
1482+ | intTyWidth from < intTyWidth to
1483+ = mkZeroExt (intTyToMethod to) (intTyWidth from) (intTyToClass from) (intTyToClass to) var
1484+mkExp (SOp (LSExt from to) [var])
1485+ | intTyWidth from < intTyWidth to
1486+ = mkSignedExt (intTyToMethod to) (intTyToClass from) (intTyToClass to) var
1487+mkExp (SOp (LTrunc from to) [var])
1488+ | intTyWidth from > intTyWidth to
1489+ = (\ var -> MethodInv $
1490+ TypeMethodCall (J.Name [intTyToIdent to])
1491+ []
1492+ (Ident "valueOf")
1493+ [ MethodInv
1494+ $ PrimaryMethodCall var [] (Ident (intTyToMethod to)) [] ]
15631495 )
1564− <$> mkVarAccess (Just $ longType) var
1565−mkExp (SOp LIntB8 [arg]) = mkExp (SOp LB32T8 [arg])
1566−mkExp (SOp LIntB16 [arg]) = mkExp (SOp LB32T16 [arg])
1567−mkExp (SOp LIntB32 [arg]) = mkExp (SV arg)
1568−mkExp (SOp LIntB64 [arg]) = mkExp (SOp LB32S64 [arg])
1569−mkExp (SOp LB32Int [arg]) = mkExp (SV arg)
1496+ <$> mkVarAccess (Just $ intTyToClass from) var
15701497mkExp (SOp LFExp [arg]) = mkMathFun "exp" arg
15711498mkExp (SOp LFLog [arg]) = mkMathFun "log" arg
15721499mkExp (SOp LFSin [arg]) = mkMathFun "sin" arg
src/IRTS/CodegenJavaScript.hs+36−36
@@ -203,58 +203,58 @@ translateExpression (SApp True name vars) =
203203 ++ ";\n});"
204204
205205translateExpression (SOp op vars)
206− | LPlus <- op
206+ | (LPlus _) <- op
207207 , (lhs:rhs:_) <- vars = translateBinaryOp "+" lhs rhs
208− | LMinus <- op
208+ | (LMinus _) <- op
209209 , (lhs:rhs:_) <- vars = translateBinaryOp "-" lhs rhs
210− | LTimes <- op
210+ | (LTimes _) <- op
211211 , (lhs:rhs:_) <- vars = translateBinaryOp "*" lhs rhs
212− | LDiv <- op
212+ | (LSDiv _) <- op
213213 , (lhs:rhs:_) <- vars = translateBinaryOp "/" lhs rhs
214− | LMod <- op
214+ | (LSRem _) <- op
215215 , (lhs:rhs:_) <- vars = translateBinaryOp "%" lhs rhs
216− | LEq <- op
216+ | (LEq _) <- op
217217 , (lhs:rhs:_) <- vars = translateBinaryOp "==" lhs rhs
218− | LLt <- op
218+ | (LLt _) <- op
219219 , (lhs:rhs:_) <- vars = translateBinaryOp "<" lhs rhs
220− | LLe <- op
220+ | (LLe _) <- op
221221 , (lhs:rhs:_) <- vars = translateBinaryOp "<=" lhs rhs
222− | LGt <- op
222+ | (LGt _) <- op
223223 , (lhs:rhs:_) <- vars = translateBinaryOp ">" lhs rhs
224− | LGe <- op
224+ | (LGe _) <- op
225225 , (lhs:rhs:_) <- vars = translateBinaryOp ">=" lhs rhs
226− | LAnd <- op
226+ | (LAnd _) <- op
227227 , (lhs:rhs:_) <- vars = translateBinaryOp "&" lhs rhs
228− | LOr <- op
228+ | (LOr _) <- op
229229 , (lhs:rhs:_) <- vars = translateBinaryOp "|" lhs rhs
230− | LXOr <- op
230+ | (LXOr _) <- op
231231 , (lhs:rhs:_) <- vars = translateBinaryOp "^" lhs rhs
232− | LSHL <- op
232+ | (LSHL _) <- op
233233 , (lhs:rhs:_) <- vars = translateBinaryOp "<<" rhs lhs
234− | LSHR <- op
234+ | (LASHR _) <- op
235235 , (lhs:rhs:_) <- vars = translateBinaryOp ">>" rhs lhs
236− | LCompl <- op
236+ | (LCompl _) <- op
237237 , (arg:_) <- vars = '~' : translateVariableName arg
238238
239− | LBPlus <- op
239+ | (LPlus ITBig) <- op
240240 , (lhs:rhs:_) <- vars = translateBinaryOp ".add(" lhs rhs ++ ")"
241− | LBMinus <- op
241+ | (LMinus ITBig) <- op
242242 , (lhs:rhs:_) <- vars = translateBinaryOp ".minus(" lhs rhs ++ ")"
243− | LBTimes <- op
243+ | (LTimes ITBig) <- op
244244 , (lhs:rhs:_) <- vars = translateBinaryOp ".times(" lhs rhs ++ ")"
245− | LBDiv <- op
245+ | (LSDiv ITBig) <- op
246246 , (lhs:rhs:_) <- vars = translateBinaryOp ".divide(" lhs rhs ++ ")"
247− | LBMod <- op
247+ | (LSRem ITBig) <- op
248248 , (lhs:rhs:_) <- vars = translateBinaryOp ".mod(" lhs rhs ++ ")"
249− | LBEq <- op
249+ | (LEq ITBig) <- op
250250 , (lhs:rhs:_) <- vars = translateBinaryOp ".equals(" lhs rhs ++ ")"
251− | LBLt <- op
251+ | (LLt ITBig) <- op
252252 , (lhs:rhs:_) <- vars = translateBinaryOp ".lesser(" lhs rhs ++ ")"
253− | LBLe <- op
253+ | (LLe ITBig) <- op
254254 , (lhs:rhs:_) <- vars = translateBinaryOp ".lesserOrEquals(" lhs rhs ++ ")"
255− | LBGt <- op
255+ | (LGt ITBig) <- op
256256 , (lhs:rhs:_) <- vars = translateBinaryOp ".greater(" lhs rhs ++ ")"
257− | LBGe <- op
257+ | (LGe ITBig) <- op
258258 , (lhs:rhs:_) <- vars = translateBinaryOp ".greaterOrEquals(" lhs rhs ++ ")"
259259
260260 | LFPlus <- op
@@ -285,29 +285,29 @@ translateExpression (SOp op vars)
285285 | LStrLen <- op
286286 , (arg:_) <- vars = translateVariableName arg ++ ".length"
287287
288− | LStrInt <- op
288+ | (LStrInt ITNative) <- op
289289 , (arg:_) <- vars = "parseInt(" ++ translateVariableName arg ++ ")"
290− | LIntStr <- op
290+ | (LIntStr ITNative) <- op
291291 , (arg:_) <- vars = "String(" ++ translateVariableName arg ++ ")"
292− | LIntBig <- op
292+ | (LSExt ITNative ITBig) <- op
293293 , (arg:_) <- vars = "__IDRRT__.bigInt(" ++ translateVariableName arg ++ ")"
294− | LBigInt <- op
294+ | (LTrunc ITBig ITNative) <- op
295295 , (arg:_) <- vars = translateVariableName arg ++ ".valueOf()"
296− | LBigStr <- op
296+ | (LIntStr ITBig) <- op
297297 , (arg:_) <- vars = translateVariableName arg ++ ".toString()"
298− | LStrBig <- op
298+ | (LStrInt ITBig) <- op
299299 , (arg:_) <- vars = "__IDRRT__.bigInt(" ++ translateVariableName arg ++ ")"
300300 | LFloatStr <- op
301301 , (arg:_) <- vars = "String(" ++ translateVariableName arg ++ ")"
302302 | LStrFloat <- op
303303 , (arg:_) <- vars = "parseFloat(" ++ translateVariableName arg ++ ")"
304− | LIntFloat <- op
304+ | (LIntFloat ITNative) <- op
305305 , (arg:_) <- vars = translateVariableName arg
306− | LFloatInt <- op
306+ | (LFloatInt ITNative) <- op
307307 , (arg:_) <- vars = translateVariableName arg
308− | LChInt <- op
308+ | (LChInt ITNative) <- op
309309 , (arg:_) <- vars = translateVariableName arg ++ ".charCodeAt(0)"
310− | LIntCh <- op
310+ | (LIntCh ITNative) <- op
311311 , (arg:_) <- vars =
312312 "String.fromCharCode(" ++ translateVariableName arg ++ ")"
313313
src/IRTS/Compiler.hs+7−1
@@ -284,15 +284,21 @@ getFTypes tm = case unApply tm of
284284 _ -> Nothing
285285
286286mkIty' (P _ (UN ty) _) = mkIty ty
287+mkIty' (App (P _ (UN "FIntT") _) (P _ (UN intTy) _)) = mkIntIty intTy
287288mkIty' _ = FAny
288289
289−mkIty "FInt" = FInt
290290mkIty "FFloat" = FDouble
291291mkIty "FChar" = FChar
292292mkIty "FString" = FString
293293mkIty "FPtr" = FPtr
294294mkIty "FUnit" = FUnit
295295
296+mkIntIty "ITNative" = FInt ITNative
297+mkIntIty "IT8" = FInt IT8
298+mkIntIty "IT16" = FInt IT16
299+mkIntIty "IT32" = FInt IT32
300+mkIntIty "IT64" = FInt IT64
301+
296302zname = NS (UN "O") ["Nat","Prelude"]
297303sname = NS (UN "S") ["Nat","Prelude"]
298304
src/IRTS/LParser.hs+27−27
@@ -92,39 +92,39 @@ pLDecl = do reserved "data"
9292
9393pLExp = buildExpressionParser optable pLExp'
9494
95−optable = [[binary "*" (\x y -> LOp LTimes [x,y]) AssocLeft,
96− binary "/" (\x y -> LOp LDiv [x,y]) AssocLeft,
95+optable = [[binary "*" (\x y -> LOp (LTimes ITNative) [x,y]) AssocLeft,
96+ binary "/" (\x y -> LOp (LSDiv ITNative) [x,y]) AssocLeft,
9797 binary "*." (\x y -> LOp LFTimes [x,y]) AssocLeft,
9898 binary "/." (\x y -> LOp LFDiv [x,y]) AssocLeft,
99− binary "*:" (\x y -> LOp LBTimes [x,y]) AssocLeft,
100− binary "/:" (\x y -> LOp LBDiv [x,y]) AssocLeft
99+ binary "*:" (\x y -> LOp (LTimes ITBig) [x,y]) AssocLeft,
100+ binary "/:" (\x y -> LOp (LSDiv ITBig) [x,y]) AssocLeft
101101 ],
102102 [
103− binary "+" (\x y -> LOp LPlus [x,y]) AssocLeft,
104− binary "-" (\x y -> LOp LMinus [x,y]) AssocLeft,
103+ binary "+" (\x y -> LOp (LPlus ITNative) [x,y]) AssocLeft,
104+ binary "-" (\x y -> LOp (LMinus ITNative) [x,y]) AssocLeft,
105105 binary "++" (\x y -> LOp LStrConcat [x,y]) AssocLeft,
106106 binary "+." (\x y -> LOp LFPlus [x,y]) AssocLeft,
107107 binary "-." (\x y -> LOp LFMinus [x,y]) AssocLeft,
108− binary "+:" (\x y -> LOp LBPlus [x,y]) AssocLeft,
109− binary "-:" (\x y -> LOp LBMinus [x,y]) AssocLeft
108+ binary "+:" (\x y -> LOp (LPlus ITBig) [x,y]) AssocLeft,
109+ binary "-:" (\x y -> LOp (LMinus ITBig) [x,y]) AssocLeft
110110 ],
111111 [
112− binary "==" (\x y -> LOp LEq [x, y]) AssocNone,
112+ binary "==" (\x y -> LOp (LEq ITNative) [x, y]) AssocNone,
113113 binary "==." (\x y -> LOp LFEq [x, y]) AssocNone,
114− binary "<" (\x y -> LOp LLt [x, y]) AssocNone,
114+ binary "<" (\x y -> LOp (LLt ITNative) [x, y]) AssocNone,
115115 binary "<." (\x y -> LOp LFLt [x, y]) AssocNone,
116− binary ">" (\x y -> LOp LGt [x, y]) AssocNone,
116+ binary ">" (\x y -> LOp (LGt ITNative) [x, y]) AssocNone,
117117 binary ">." (\x y -> LOp LFGt [x, y]) AssocNone,
118− binary "<=" (\x y -> LOp LLe [x, y]) AssocNone,
118+ binary "<=" (\x y -> LOp (LLe ITNative) [x, y]) AssocNone,
119119 binary "<=." (\x y -> LOp LFLe [x, y]) AssocNone,
120− binary ">=" (\x y -> LOp LGe [x, y]) AssocNone,
120+ binary ">=" (\x y -> LOp (LGe ITNative) [x, y]) AssocNone,
121121 binary ">=." (\x y -> LOp LFGe [x, y]) AssocNone,
122122
123− binary "==:" (\x y -> LOp LBEq [x, y]) AssocNone,
124− binary "<:" (\x y -> LOp LBLt [x, y]) AssocNone,
125− binary ">:" (\x y -> LOp LBGt [x, y]) AssocNone,
126− binary "<=:" (\x y -> LOp LBLe [x, y]) AssocNone,
127− binary ">=:" (\x y -> LOp LBGe [x, y]) AssocNone
123+ binary "==:" (\x y -> LOp (LEq ITBig) [x, y]) AssocNone,
124+ binary "<:" (\x y -> LOp (LLt ITBig) [x, y]) AssocNone,
125+ binary ">:" (\x y -> LOp (LGt ITBig) [x, y]) AssocNone,
126+ binary "<=:" (\x y -> LOp (LLe ITBig) [x, y]) AssocNone,
127+ binary ">=:" (\x y -> LOp (LGe ITBig) [x, y]) AssocNone
128128 ]]
129129
130130binary name f assoc = Infix (do reservedOp name; return f) assoc
@@ -164,7 +164,7 @@ pLExp' = try (do lchar '%'; pCast)
164164
165165pLang = do reserved "C"; return LANG_C
166166
167−pType = do reserved "Int"; return FInt
167+pType = do reserved "Int"; return (FInt ITNative)
168168 <|> do reserved "Float"; return FDouble
169169 <|> do reserved "String"; return FString
170170 <|> do reserved "Unit"; return FUnit
@@ -184,21 +184,21 @@ pCast = do reserved "FloatString"; lchar '('; e <- pLExp; lchar ')'
184184 <|> do reserved "StringFloat"; lchar '('; e <- pLExp; lchar ')'
185185 return (LOp LStrFloat [e])
186186 <|> do reserved "FloatInt"; lchar '('; e <- pLExp; lchar ')'
187− return (LOp LFloatInt [e])
187+ return (LOp (LFloatInt ITNative) [e])
188188 <|> do reserved "IntFloat"; lchar '('; e <- pLExp; lchar ')'
189− return (LOp LIntFloat [e])
189+ return (LOp (LIntFloat ITNative) [e])
190190 <|> do reserved "StringInt"; lchar '('; e <- pLExp; lchar ')'
191− return (LOp LStrInt [e])
191+ return (LOp (LStrInt ITNative) [e])
192192 <|> do reserved "IntString"; lchar '('; e <- pLExp; lchar ')'
193− return (LOp LIntStr [e])
193+ return (LOp (LIntStr ITNative) [e])
194194 <|> do reserved "BigInt"; lchar '('; e <- pLExp; lchar ')'
195− return (LOp LBigInt [e])
195+ return (LOp (LTrunc ITBig ITNative) [e])
196196 <|> do reserved "IntBig"; lchar '('; e <- pLExp; lchar ')'
197− return (LOp LIntBig [e])
197+ return (LOp (LSExt ITNative ITBig) [e])
198198 <|> do reserved "BigString"; lchar '('; e <- pLExp; lchar ')'
199− return (LOp LBigStr [e])
199+ return (LOp (LIntStr ITBig) [e])
200200 <|> do reserved "StringBig"; lchar '('; e <- pLExp; lchar ')'
201− return (LOp LStrBig [e])
201+ return (LOp (LStrInt ITBig) [e])
202202
203203pPrim :: LParser LExp
204204pPrim = do reserved "StrEq"; lchar '(';
src/IRTS/Lang.hs+29−26
@@ -3,6 +3,7 @@ module IRTS.Lang where
33import Core.TT
44import Control.Monad.State hiding(lift)
55import Data.List
6+import Foreign.Storable (sizeOf)
67import Debug.Trace
78
89data LVar = Loc Int | Glob Name
@@ -28,36 +29,38 @@ data LExp = LV LVar
2829-- Primitive operators. Backends are not *required* to implement all
2930-- of these, but should report an error if they are unable
3031
31−data PrimFn = LPlus | LMinus | LTimes | LDiv | LMod
32− | LAnd | LOr | LXOr | LCompl | LSHL| LSHR
33− | LEq | LLt | LLe | LGt | LGe
32+data IntTy = ITNative | IT8 | IT16 | IT32 | IT64 | ITBig
33+ deriving (Show, Eq)
34+
35+intTyWidth :: IntTy -> Int
36+intTyWidth IT8 = 8
37+intTyWidth IT16 = 16
38+intTyWidth IT32 = 32
39+intTyWidth IT64 = 64
40+intTyWidth ITNative = 8 * sizeOf (0 :: Int)
41+intTyWidth ITBig = error "IRTS.Lang.intTyWidth: Big integers have variable width"
42+
43+intTyToConst :: IntTy -> Const
44+intTyToConst IT8 = B8Type
45+intTyToConst IT16 = B16Type
46+intTyToConst IT32 = B32Type
47+intTyToConst IT64 = B64Type
48+intTyToConst ITBig = BIType
49+intTyToConst ITNative = IType
50+
51+data PrimFn = LPlus IntTy | LMinus IntTy | LTimes IntTy
52+ | LUDiv IntTy | LSDiv IntTy | LURem IntTy | LSRem IntTy
53+ | LAnd IntTy | LOr IntTy | LXOr IntTy | LCompl IntTy
54+ | LSHL IntTy | LLSHR IntTy | LASHR IntTy
55+ | LEq IntTy | LLt IntTy | LLe IntTy | LGt IntTy | LGe IntTy
56+ | LSExt IntTy IntTy | LZExt IntTy IntTy | LTrunc IntTy IntTy
3457 | LFPlus | LFMinus | LFTimes | LFDiv
3558 | LFEq | LFLt | LFLe | LFGt | LFGe
36− | LBPlus | LBMinus | LBDec | LBTimes | LBDiv | LBMod
37− | LBEq | LBLt | LBLe | LBGt | LBGe
3859 | LStrConcat | LStrLt | LStrEq | LStrLen
39− | LIntFloat | LFloatInt | LIntStr | LStrInt | LFloatStr | LStrFloat
40− | LIntBig | LBigInt | LStrBig | LBigStr | LChInt | LIntCh
60+ | LIntFloat IntTy | LFloatInt IntTy | LIntStr IntTy | LStrInt IntTy
61+ | LFloatStr | LStrFloat | LChInt IntTy | LIntCh IntTy
4162 | LPrintNum | LPrintStr | LReadStr
4263
43− | LB8Lt | LB8Lte | LB8Eq | LB8Gt | LB8Gte
44− | LB8Plus | LB8Minus | LB8Times | LB8UDiv | LB8SDiv | LB8URem | LB8SRem
45− | LB8Shl | LB8LShr | LB8AShr | LB8And | LB8Or | LB8Xor | LB8Compl
46− | LB8Z16 | LB8Z32 | LB8Z64 | LB8S16 | LB8S32 | LB8S64 -- Zero/Sign extension
47− | LB16Lt | LB16Lte | LB16Eq | LB16Gt | LB16Gte
48− | LB16Plus | LB16Minus | LB16Times | LB16UDiv | LB16SDiv | LB16URem | LB16SRem
49− | LB16Shl | LB16LShr | LB16AShr | LB16And | LB16Or | LB16Xor | LB16Compl
50− | LB16Z32 | LB16Z64 | LB16S32 | LB16S64 | LB16T8 -- and Truncation
51− | LB32Lt | LB32Lte | LB32Eq | LB32Gt | LB32Gte
52− | LB32Plus | LB32Minus | LB32Times | LB32UDiv | LB32SDiv | LB32URem | LB32SRem
53− | LB32Shl | LB32LShr | LB32AShr | LB32And | LB32Or | LB32Xor | LB32Compl
54− | LB32Z64 | LB32S64 | LB32T8 | LB32T16
55− | LB64Lt | LB64Lte | LB64Eq | LB64Gt | LB64Gte
56− | LB64Plus | LB64Minus | LB64Times | LB64UDiv | LB64SDiv | LB64URem | LB64SRem
57− | LB64Shl | LB64LShr | LB64AShr | LB64And | LB64Or | LB64Xor | LB64Compl
58− | LB64T8 | LB64T16 | LB64T32
59− | LIntB8 | LIntB16 | LIntB32 | LIntB64 | LB32Int
60−
6164 | LFExp | LFLog | LFSin | LFCos | LFTan | LFASin | LFACos | LFATan
6265 | LFSqrt | LFFloor | LFCeil
6366
@@ -76,7 +79,7 @@ data PrimFn = LPlus | LMinus | LTimes | LDiv | LMod
7679data FLang = LANG_C
7780 deriving (Show, Eq)
7881
79−data FType = FInt | FChar | FString | FUnit | FPtr | FDouble | FAny
82+data FType = FInt IntTy | FChar | FString | FUnit | FPtr | FDouble | FAny
8083 deriving (Show, Eq)
8184
8285data LAlt = LConCase Int Name [Name] LExp
src/Idris/Primitives.hs+224−445
@@ -1,4 +1,4 @@
1−{-# LANGUAGE RankNTypes, ScopedTypeVariables #-}
1+{-# LANGUAGE RankNTypes, ScopedTypeVariables, PatternGuards #-}
22
33module Idris.Primitives(elabPrims) where
44
@@ -34,280 +34,73 @@ partial = Partial NotCovering
3434
3535primitives =
3636 -- operators
37− [Prim (UN "prim__addInt") (ty [IType, IType] IType) 2 (iBin (+))
38− (2, LPlus) total,
39− Prim (UN "prim__subInt") (ty [IType, IType] IType) 2 (iBin (-))
40− (2, LMinus) total,
41− Prim (UN "prim__mulInt") (ty [IType, IType] IType) 2 (iBin (*))
42− (2, LTimes) total,
43− Prim (UN "prim__divInt") (ty [IType, IType] IType) 2 (iBin div)
44− (2, LDiv) partial,
45− Prim (UN "prim__modInt") (ty [IType, IType] IType) 2 (iBin mod)
46− (2, LMod) partial,
47− Prim (UN "prim__andInt") (ty [IType, IType] IType) 2 (iBin (.&.))
48− (2, LAnd) partial,
49− Prim (UN "prim__orInt") (ty [IType, IType] IType) 2 (iBin (.|.))
50− (2, LOr) partial,
51− Prim (UN "prim__xorInt") (ty [IType, IType] IType) 2 (iBin xor)
52− (2, LXOr) partial,
53− Prim (UN "prim__shLInt") (ty [IType, IType] IType) 2 (iBin shiftL)
54− (2, LSHL) partial,
55− Prim (UN "prim__shRInt") (ty [IType, IType] IType) 2 (iBin shiftR)
56− (2, LSHR) partial,
57− Prim (UN "prim__complInt") (ty [IType] IType) 1 (iUn complement)
58− (1, LCompl) partial,
59− Prim (UN "prim__eqInt") (ty [IType, IType] IType) 2 (biBin (==))
60− (2, LEq) total,
61− Prim (UN "prim__ltInt") (ty [IType, IType] IType) 2 (biBin (<))
62− (2, LLt) total,
63− Prim (UN "prim__lteInt") (ty [IType, IType] IType) 2 (biBin (<=))
64− (2, LLe) total,
65− Prim (UN "prim__gtInt") (ty [IType, IType] IType) 2 (biBin (>))
66− (2, LGt) total,
67− Prim (UN "prim__gteInt") (ty [IType, IType] IType) 2 (biBin (>=))
68− (2, LGe) total,
69− Prim (UN "prim__eqChar") (ty [ChType, ChType] IType) 2 (bcBin (==))
70− (2, LEq) total,
37+ [Prim (UN "prim__eqChar") (ty [ChType, ChType] IType) 2 (bcBin (==))
38+ (2, LEq ITNative) total,
7139 Prim (UN "prim__ltChar") (ty [ChType, ChType] IType) 2 (bcBin (<))
72− (2, LLt) total,
40+ (2, LLt ITNative) total,
7341 Prim (UN "prim__lteChar") (ty [ChType, ChType] IType) 2 (bcBin (<=))
74− (2, LLe) total,
42+ (2, LLe ITNative) total,
7543 Prim (UN "prim__gtChar") (ty [ChType, ChType] IType) 2 (bcBin (>))
76− (2, LGt) total,
44+ (2, LGt ITNative) total,
7745 Prim (UN "prim__gteChar") (ty [ChType, ChType] IType) 2 (bcBin (>=))
78− (2, LGe) total,
79−
80− Prim (UN "prim__ltB8") (ty [B8Type, B8Type] IType) 2 (b8Cmp (<))
81− (2, LB8Lt) total,
82− Prim (UN "prim__lteB8") (ty [B8Type, B8Type] IType) 2 (b8Cmp (<=))
83− (2, LB8Lte) total,
84− Prim (UN "prim__eqB8") (ty [B8Type, B8Type] IType) 2 (b8Cmp (==))
85− (2, LB8Eq) total,
86− Prim (UN "prim__gteB8") (ty [B8Type, B8Type] IType) 2 (b8Cmp (>))
87− (2, LB8Gte) total,
88− Prim (UN "prim__gtB8") (ty [B8Type, B8Type] IType) 2 (b8Cmp (>=))
89− (2, LB8Gt) total,
90− Prim (UN "prim__addB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (+))
91− (2, LB8Plus) total,
92− Prim (UN "prim__subB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (-))
93− (2, LB8Minus) total,
94− Prim (UN "prim__mulB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (*))
95− (2, LB8Times) total,
96− Prim (UN "prim__udivB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin div)
97− (2, LB8UDiv) partial,
98− Prim (UN "prim__sdivB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin s8div)
99− (2, LB8SDiv) partial,
100− Prim (UN "prim__uremB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin rem)
101− (2, LB8URem) partial,
102− Prim (UN "prim__sremB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin s8rem)
103− (2, LB8SRem) partial,
104− Prim (UN "prim__shlB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (\x y -> shiftL x (fromIntegral y)))
105− (2, LB8Shl) total,
106− Prim (UN "prim__lshrB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (\x y -> shiftR x (fromIntegral y)))
107− (2, LB8AShr) total,
108− Prim (UN "prim__ashrB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (\x y -> fromIntegral $
109− shiftR (fromIntegral x :: Int8)
110− (fromIntegral y)))
111− (2, LB8LShr) total,
112− Prim (UN "prim__andB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (.&.))
113− (2, LB8And) total,
114− Prim (UN "prim__orB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (.|.))
115− (2, LB8Or) total,
116− Prim (UN "prim__xorB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin xor)
117− (2, LB8Xor) total,
118− Prim (UN "prim__complB8") (ty [B8Type] B8Type) 1 (b8Un complement)
119− (1, LB8Compl) total,
120− Prim (UN "prim__zextB8_16") (ty [B8Type] B16Type) 1 zext8_16
121− (1, LB8Z16) total,
122− Prim (UN "prim__zextB8_32") (ty [B8Type] B32Type) 1 zext8_32
123− (1, LB8Z32) total,
124− Prim (UN "prim__zextB8_64") (ty [B8Type] B64Type) 1 zext8_64
125− (1, LB8Z64) total,
126− Prim (UN "prim__sextB8_16") (ty [B8Type] B16Type) 1 sext8_16
127− (1, LB8Z16) total,
128− Prim (UN "prim__sextB8_32") (ty [B8Type] B32Type) 1 sext8_32
129− (1, LB8Z32) total,
130− Prim (UN "prim__sextB8_64") (ty [B8Type] B64Type) 1 sext8_64
131− (1, LB8Z64) total,
132−
133− Prim (UN "prim__ltB16") (ty [B16Type, B16Type] IType) 2 (b16Cmp (<))
134− (2, LB16Lt) total,
135− Prim (UN "prim__lteB16") (ty [B16Type, B16Type] IType) 2 (b16Cmp (<=))
136− (2, LB16Lte) total,
137− Prim (UN "prim__eqB16") (ty [B16Type, B16Type] IType) 2 (b16Cmp (==))
138− (2, LB16Eq) total,
139− Prim (UN "prim__gteB16") (ty [B16Type, B16Type] IType) 2 (b16Cmp (>))
140− (2, LB16Gte) total,
141− Prim (UN "prim__gtB16") (ty [B16Type, B16Type] IType) 2 (b16Cmp (>=))
142− (2, LB16Gt) total,
143− Prim (UN "prim__addB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (+))
144− (2, LB16Plus) total,
145− Prim (UN "prim__subB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (-))
146− (2, LB16Minus) total,
147− Prim (UN "prim__mulB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (*))
148− (2, LB16Times) total,
149− Prim (UN "prim__udivB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin div)
150− (2, LB16UDiv) partial,
151− Prim (UN "prim__sdivB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin s16div)
152− (2, LB16SDiv) partial,
153− Prim (UN "prim__uremB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin rem)
154− (2, LB16URem) partial,
155− Prim (UN "prim__sremB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin s16rem)
156− (2, LB16SRem) partial,
157− Prim (UN "prim__shlB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (\x y -> shiftL x (fromIntegral y)))
158− (2, LB16Shl) total,
159− Prim (UN "prim__lshrB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (\x y -> shiftR x (fromIntegral y)))
160− (2, LB16AShr) total,
161− Prim (UN "prim__ashrB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (\x y -> fromIntegral $
162− shiftR (fromIntegral x :: Int16)
163− (fromIntegral y)))
164− (2, LB16LShr) total,
165− Prim (UN "prim__andB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (.&.))
166− (2, LB16And) total,
167− Prim (UN "prim__orB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (.|.))
168− (2, LB16Or) total,
169− Prim (UN "prim__xorB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin xor)
170− (2, LB16Xor) total,
171− Prim (UN "prim__complB16") (ty [B16Type] B16Type) 1 (b16Un complement)
172− (1, LB16Compl) total,
173− Prim (UN "prim__zextB16_32") (ty [B16Type] B32Type) 1 zext16_32
174− (1, LB16Z32) total,
175− Prim (UN "prim__zextB16_64") (ty [B16Type] B64Type) 1 zext16_64
176− (1, LB16Z64) total,
177− Prim (UN "prim__sextB16_32") (ty [B16Type] B32Type) 1 sext16_32
178− (1, LB16Z32) total,
179− Prim (UN "prim__sextB16_64") (ty [B16Type] B64Type) 1 sext16_64
180− (1, LB16Z64) total,
181− Prim (UN "prim__truncB16_8") (ty [B16Type] B8Type) 1 trunc16_8
182− (1, LB16T8) total,
183−
184− Prim (UN "prim__ltB32") (ty [B32Type, B32Type] IType) 2 (b32Cmp (<))
185− (2, LB32Lt) total,
186− Prim (UN "prim__lteB32") (ty [B32Type, B32Type] IType) 2 (b32Cmp (<=))
187− (2, LB32Lte) total,
188− Prim (UN "prim__eqB32") (ty [B32Type, B32Type] IType) 2 (b32Cmp (==))
189− (2, LB32Eq) total,
190− Prim (UN "prim__gteB32") (ty [B32Type, B32Type] IType) 2 (b32Cmp (>))
191− (2, LB32Gte) total,
192− Prim (UN "prim__gtB32") (ty [B32Type, B32Type] IType) 2 (b32Cmp (>=))
193− (2, LB32Gt) total,
194− Prim (UN "prim__addB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (+))
195− (2, LB32Plus) total,
196− Prim (UN "prim__subB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (-))
197− (2, LB32Minus) total,
198− Prim (UN "prim__mulB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (*))
199− (2, LB32Times) total,
200− Prim (UN "prim__udivB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin div)
201− (2, LB32UDiv) partial,
202− Prim (UN "prim__sdivB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin s32div)
203− (2, LB32SDiv) partial,
204− Prim (UN "prim__uremB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin rem)
205− (2, LB32URem) partial,
206− Prim (UN "prim__sremB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin s32rem)
207− (2, LB32SRem) partial,
208− Prim (UN "prim__shlB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (\x y -> shiftL x (fromIntegral y)))
209− (2, LB32Shl) total,
210− Prim (UN "prim__lshrB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (\x y -> shiftR x (fromIntegral y)))
211− (2, LB32AShr) total,
212− Prim (UN "prim__ashrB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (\x y -> fromIntegral $
213− shiftR (fromIntegral x :: Int32)
214− (fromIntegral y)))
215− (2, LB32LShr) total,
216− Prim (UN "prim__andB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (.&.))
217− (2, LB32And) total,
218− Prim (UN "prim__orB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (.|.))
219− (2, LB32Or) total,
220− Prim (UN "prim__xorB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin xor)
221− (2, LB32Xor) total,
222− Prim (UN "prim__complB32") (ty [B32Type] B32Type) 1 (b32Un complement)
223− (1, LB32Compl) total,
224− Prim (UN "prim__zextB32_64") (ty [B32Type] B64Type) 1 zext32_64
225− (1, LB32Z64) total,
226− Prim (UN "prim__sextB32_64") (ty [B32Type] B64Type) 1 sext32_64
227− (1, LB32Z64) total,
228− Prim (UN "prim__truncB32_8") (ty [B32Type] B8Type) 1 trunc32_8
229− (1, LB32T8) total,
230− Prim (UN "prim__truncB32_16") (ty [B32Type] B16Type) 1 trunc32_16
231− (1, LB32T16) total,
232−
233− Prim (UN "prim__ltB64") (ty [B64Type, B64Type] IType) 2 (b64Cmp (<))
234− (2, LB64Lt) total,
235− Prim (UN "prim__lteB64") (ty [B64Type, B64Type] IType) 2 (b64Cmp (<=))
236− (2, LB64Lte) total,
237− Prim (UN "prim__eqB64") (ty [B64Type, B64Type] IType) 2 (b64Cmp (==))
238− (2, LB64Eq) total,
239− Prim (UN "prim__gteB64") (ty [B64Type, B64Type] IType) 2 (b64Cmp (>))
240− (2, LB64Gte) total,
241− Prim (UN "prim__gtB64") (ty [B64Type, B64Type] IType) 2 (b64Cmp (>=))
242− (2, LB64Gt) total,
243− Prim (UN "prim__addB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (+))
244− (2, LB64Plus) total,
245− Prim (UN "prim__subB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (-))
246− (2, LB64Minus) total,
247− Prim (UN "prim__mulB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (*))
248− (2, LB64Times) total,
249− Prim (UN "prim__udivB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin div)
250− (2, LB64UDiv) partial,
251− Prim (UN "prim__sdivB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin s64div)
252− (2, LB64SDiv) partial,
253− Prim (UN "prim__uremB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin rem)
254− (2, LB64URem) partial,
255− Prim (UN "prim__sremB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin s64rem)
256− (2, LB64SRem) partial,
257− Prim (UN "prim__shlB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (\x y -> shiftL x (fromIntegral y)))
258− (2, LB64Shl) total,
259− Prim (UN "prim__lshrB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (\x y -> shiftR x (fromIntegral y)))
260− (2, LB64AShr) total,
261− Prim (UN "prim__ashrB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (\x y -> fromIntegral $
262− shiftR (fromIntegral x :: Int64)
263− (fromIntegral y)))
264− (2, LB64LShr) total,
265− Prim (UN "prim__andB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (.&.))
266− (2, LB64And) total,
267− Prim (UN "prim__orB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (.|.))
268− (2, LB64Or) total,
269− Prim (UN "prim__xorB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin xor)
270− (2, LB64Xor) total,
271− Prim (UN "prim__complB64") (ty [B64Type] B64Type) 1 (b64Un complement)
272− (1, LB64Compl) total,
273− Prim (UN "prim__truncB64_8") (ty [B64Type] B8Type) 1 trunc64_8
274− (1, LB64T8) total,
275− Prim (UN "prim__truncB64_16") (ty [B64Type] B16Type) 1 trunc64_16
276− (1, LB64T16) total,
277− Prim (UN "prim__truncB64_32") (ty [B64Type] B32Type) 1 trunc64_32
278− (1, LB64T32) total,
279−
280− Prim (UN "prim__intToB8") (ty [IType] B8Type) 1 intToBits8
281− (1, LIntB8) total,
282− Prim (UN "prim__intToB16") (ty [IType] B16Type) 1 intToBits16
283− (1, LIntB16) total,
284− Prim (UN "prim__intToB32") (ty [IType] B32Type) 1 intToBits32
285− (1, LIntB32) total,
286− Prim (UN "prim__intToB64") (ty [IType] B64Type) 1 intToBits64
287− (1, LIntB64) total,
288− Prim (UN "prim__B32ToInt") (ty [B32Type] IType) 1 bits32ToInt
289− (1, LB32Int) total,
290−
291− Prim (UN "prim__addBigInt") (ty [BIType, BIType] BIType) 2 (bBin (+))
292− (2, LBPlus) total,
293− Prim (UN "prim__subBigInt") (ty [BIType, BIType] BIType) 2 (bBin (-))
294− (2, LBMinus) total,
295− Prim (UN "prim__mulBigInt") (ty [BIType, BIType] BIType) 2 (bBin (*))
296− (2, LBTimes) total,
297− Prim (UN "prim__divBigInt") (ty [BIType, BIType] BIType) 2 (bBin div)
298− (2, LBDiv) partial,
299− Prim (UN "prim__modBigInt") (ty [BIType, BIType] BIType) 2 (bBin mod)
300− (2, LBMod) partial,
301− Prim (UN "prim__eqBigInt") (ty [BIType, BIType] IType) 2 (bbBin (==))
302− (2, LBEq) total,
303− Prim (UN "prim__ltBigInt") (ty [BIType, BIType] IType) 2 (bbBin (<))
304− (2, LBLt) total,
305− Prim (UN "prim__lteBigInt") (ty [BIType, BIType] IType) 2 (bbBin (<=))
306− (2, LBLe) total,
307− Prim (UN "prim__gtBigInt") (ty [BIType, BIType] IType) 2 (bbBin (>))
308− (2, LBGt) total,
309− Prim (UN "prim__gtBigInt") (ty [BIType, BIType] IType) 2 (bbBin (>=))
310− (2, LBGe) total,
46+ (2, LGe ITNative) total,
47+
48+ iCoerce IT8 IT16 "zext" zext LZExt,
49+ iCoerce IT8 IT32 "zext" zext LZExt,
50+ iCoerce IT8 IT64 "zext" zext LZExt,
51+ iCoerce IT8 ITBig "zext" zext LZExt,
52+ iCoerce IT8 ITNative "zext" zext LZExt,
53+ iCoerce IT16 IT32 "zext" zext LZExt,
54+ iCoerce IT16 IT64 "zext" zext LZExt,
55+ iCoerce IT16 ITBig "zext" zext LZExt,
56+ iCoerce IT16 ITNative "zext" zext LZExt,
57+ iCoerce IT32 IT64 "zext" zext LZExt,
58+ iCoerce IT32 ITBig "zext" zext LZExt,
59+ iCoerce IT32 ITNative "zext" zext LZExt,
60+ iCoerce IT64 ITBig "zext" zext LZExt,
61+ iCoerce ITNative ITBig "zext" zext LZExt,
62+ iCoerce ITNative IT64 "zext" zext LZExt,
63+ iCoerce ITNative IT32 "zext" zext LZExt,
64+ iCoerce ITNative IT16 "zext" zext LZExt,
65+
66+ iCoerce IT8 IT16 "sext" sext LSExt,
67+ iCoerce IT8 IT32 "sext" sext LSExt,
68+ iCoerce IT8 IT64 "sext" sext LSExt,
69+ iCoerce IT8 ITBig "sext" sext LSExt,
70+ iCoerce IT8 ITNative "sext" sext LSExt,
71+ iCoerce IT16 IT32 "sext" sext LSExt,
72+ iCoerce IT16 IT64 "sext" sext LSExt,
73+ iCoerce IT16 ITBig "sext" sext LSExt,
74+ iCoerce IT16 ITNative "sext" sext LSExt,
75+ iCoerce IT32 IT64 "sext" sext LSExt,
76+ iCoerce IT32 ITBig "sext" sext LSExt,
77+ iCoerce IT32 ITNative "sext" sext LSExt,
78+ iCoerce IT64 ITBig "sext" sext LSExt,
79+ iCoerce ITNative ITBig "sext" sext LSExt,
80+ iCoerce ITNative ITBig "sext" sext LSExt,
81+ iCoerce ITNative IT64 "sext" sext LSExt,
82+ iCoerce ITNative IT32 "sext" sext LSExt,
83+ iCoerce ITNative IT16 "sext" sext LSExt,
84+
85+ iCoerce IT16 IT8 "trunc" trunc LTrunc,
86+ iCoerce IT32 IT8 "trunc" trunc LTrunc,
87+ iCoerce IT64 IT8 "trunc" trunc LTrunc,
88+ iCoerce ITBig IT8 "trunc" trunc LTrunc,
89+ iCoerce ITNative IT8 "trunc" trunc LTrunc,
90+ iCoerce IT32 IT16 "trunc" trunc LTrunc,
91+ iCoerce IT64 IT16 "trunc" trunc LTrunc,
92+ iCoerce ITBig IT16 "trunc" trunc LTrunc,
93+ iCoerce ITNative IT16 "trunc" trunc LTrunc,
94+ iCoerce IT64 IT32 "trunc" trunc LTrunc,
95+ iCoerce ITBig IT32 "trunc" trunc LTrunc,
96+ iCoerce ITNative IT32 "trunc" trunc LTrunc,
97+ iCoerce ITBig IT64 "trunc" trunc LTrunc,
98+ iCoerce IT16 ITNative "trunc" trunc LTrunc,
99+ iCoerce IT32 ITNative "trunc" trunc LTrunc,
100+ iCoerce IT64 ITNative "trunc" trunc LTrunc,
101+ iCoerce ITBig ITNative "trunc" trunc LTrunc,
102+ iCoerce ITNative IT64 "trunc" trunc LTrunc,
103+
311104 Prim (UN "prim__addFloat") (ty [FlType, FlType] FlType) 2 (fBin (+))
312105 (2, LFPlus) total,
313106 Prim (UN "prim__subFloat") (ty [FlType, FlType] FlType) 2 (fBin (-))
@@ -335,30 +128,14 @@ primitives =
335128 Prim (UN "prim_lenString") (ty [StrType] IType) 1 (p_strLen)
336129 (1, LStrLen) total,
337130 -- Conversions
338− Prim (UN "prim__strToInt") (ty [StrType] IType) 1 (c_strToInt)
339− (1, LStrInt) total,
340− Prim (UN "prim__intToStr") (ty [IType] StrType) 1 (c_intToStr)
341− (1, LIntStr) total,
342131 Prim (UN "prim__charToInt") (ty [ChType] IType) 1 (c_charToInt)
343− (1, LChInt) total,
132+ (1, LChInt ITNative) total,
344133 Prim (UN "prim__intToChar") (ty [IType] ChType) 1 (c_intToChar)
345− (1, LIntCh) total,
346− Prim (UN "prim__intToBigInt") (ty [IType] BIType) 1 (c_intToBigInt)
347− (1, LIntBig) total,
348− Prim (UN "prim__bigIntToInt") (ty [BIType] IType) 1 (c_bigIntToInt)
349− (1, LBigInt) total,
350− Prim (UN "prim__strToBigInt") (ty [StrType] BIType) 1 (c_strToBigInt)
351− (1, LStrBig) total,
352− Prim (UN "prim__bigIntToStr") (ty [BIType] StrType) 1 (c_bigIntToStr)
353− (1, LBigStr) total,
134+ (1, LIntCh ITNative) total,
354135 Prim (UN "prim__strToFloat") (ty [StrType] FlType) 1 (c_strToFloat)
355136 (1, LStrFloat) total,
356137 Prim (UN "prim__floatToStr") (ty [FlType] StrType) 1 (c_floatToStr)
357138 (1, LFloatStr) total,
358− Prim (UN "prim__intToFloat") (ty [IType] FlType) 1 (c_intToFloat)
359− (1, LIntFloat) total,
360− Prim (UN "prim__floatToInt") (ty [FlType] IType) 1 (c_floatToInt)
361− (1, LFloatInt) total,
362139
363140 Prim (UN "prim__floatExp") (ty [FlType] FlType) 1 (p_floatExp)
364141 (1, LFExp) total,
@@ -402,7 +179,49 @@ primitives =
402179 (0, LStdIn) partial,
403180 Prim (UN "prim__believe_me") believeTy 3 (p_believeMe)
404181 (3, LNoOp) partial -- ahem
405− ]
182+ ] ++ concatMap intOps [IT8, IT16, IT32, IT64, ITBig, ITNative]
183+
184+intOps ity =
185+ [ iCmp ity "lt" (bCmp ity (<)) LLt total
186+ , iCmp ity "lte" (bCmp ity (<=)) LLe total
187+ , iCmp ity "eq" (bCmp ity (==)) LEq total
188+ , iCmp ity "gte" (bCmp ity (>=)) LGe total
189+ , iCmp ity "gt" (bCmp ity (>)) LGt total
190+ , iBinOp ity "add" (bitBin ity (+)) LPlus total
191+ , iBinOp ity "sub" (bitBin ity (-)) LMinus total
192+ , iBinOp ity "mul" (bitBin ity (*)) LTimes total
193+ , iBinOp ity "udiv" (bitBin ity div) LUDiv partial
194+ , iBinOp ity "sdiv" (bsdiv ity) LSDiv partial
195+ , iBinOp ity "urem" (bitBin ity rem) LURem partial
196+ , iBinOp ity "srem" (bsrem ity) LSRem partial
197+ , iBinOp ity "shl" (bitBin ity (\x y -> shiftL x (fromIntegral y))) LSHL total
198+ , iBinOp ity "lshr" (bitBin ity (\x y -> shiftR x (fromIntegral y))) LLSHR total
199+ , iBinOp ity "ashr" (bashr ity) LASHR total
200+ , iBinOp ity "and" (bitBin ity (.&.)) LAnd total
201+ , iBinOp ity "or" (bitBin ity (.|.)) LOr total
202+ , iBinOp ity "xor" (bitBin ity (xor)) LXOr total
203+ , iUnOp ity "compl" (bUn ity complement) LCompl total
204+ , Prim (UN $ "prim__toStr" ++ intTyName ity) (ty [intTyToConst ity] StrType) 1 intToStr
205+ (1, LIntStr ity) total
206+ , Prim (UN $ "prim__fromStr" ++ intTyName ity) (ty [StrType] (intTyToConst ity)) 1 (strToInt ity)
207+ (1, LStrInt ity) total
208+ , Prim (UN $ "prim__toFloat" ++ intTyName ity) (ty [intTyToConst ity] FlType) 1 intToFloat
209+ (1, LIntFloat ity) total
210+ , Prim (UN $ "prim__fromFloat" ++ intTyName ity) (ty [FlType] (intTyToConst ity)) 1 (floatToInt ity)
211+ (1, LFloatInt ity) total
212+ ]
213+
214+intTyName :: IntTy -> String
215+intTyName ITNative = "Int"
216+intTyName ITBig = "BigInt"
217+intTyName sized = "B" ++ show (intTyWidth sized)
218+
219+iCmp ity op impl irop totality = Prim (UN $ "prim__" ++ op ++ intTyName ity) (ty (replicate 2 $ intTyToConst ity) IType) 2 impl (2, irop ity) totality
220+iBinOp ity op impl irop totality = Prim (UN $ "prim__" ++ op ++ intTyName ity) (ty (replicate 2 $ intTyToConst ity) (intTyToConst ity)) 2 impl (2, irop ity) totality
221+iUnOp ity op impl irop totality = Prim (UN $ "prim__" ++ op ++ intTyName ity) (ty [intTyToConst ity] (intTyToConst ity)) 1 impl (1, irop ity) totality
222+iCoerce from to op impl irop =
223+ Prim (UN $ "prim__" ++ op ++ intTyName from ++ "_" ++ intTyName to)
224+ (ty [intTyToConst from] (intTyToConst to)) 1 (impl from to) (1, irop from to) total
406225
407226p_believeMe [_,_,x] = Just x
408227p_believeMe _ = Nothing
@@ -441,161 +260,127 @@ bsBin _ _ = Nothing
441260sBin op [VConstant (Str x), VConstant (Str y)] = Just $ VConstant (Str (op x y))
442261sBin _ _ = Nothing
443262
444−s8div :: Word8 -> Word8 -> Word8
445−s8div x y = fromIntegral (fromIntegral x `div` fromIntegral y :: Int8)
446−
447−s16div :: Word16 -> Word16 -> Word16
448−s16div x y = fromIntegral (fromIntegral x `div` fromIntegral y :: Int16)
449−
450−s32div :: Word32 -> Word32 -> Word32
451−s32div x y = fromIntegral (fromIntegral x `div` fromIntegral y :: Int32)
452−
453−s64div :: Word64 -> Word64 -> Word64
454−s64div x y = fromIntegral (fromIntegral x `div` fromIntegral y :: Int64)
455−
456−s8rem :: Word8 -> Word8 -> Word8
457−s8rem x y = fromIntegral (fromIntegral x `rem` fromIntegral y :: Int8)
458−
459−s16rem :: Word16 -> Word16 -> Word16
460−s16rem x y = fromIntegral (fromIntegral x `rem` fromIntegral y :: Int16)
461−
462−s32rem :: Word32 -> Word32 -> Word32
463−s32rem x y = fromIntegral (fromIntegral x `rem` fromIntegral y :: Int32)
464−
465−s64rem :: Word64 -> Word64 -> Word64
466−s64rem x y = fromIntegral (fromIntegral x `rem` fromIntegral y :: Int64)
467−
468−b8Bin op [VConstant (B8 x), VConstant (B8 y)] = Just $ VConstant (B8 (op x y))
469−b8Bin _ _ = Nothing
470−
471−b8Un op [VConstant (B8 x)] = Just $ VConstant (B8 (op x))
472−b8Un _ _ = Nothing
473−
474−b16Bin op [VConstant (B16 x), VConstant (B16 y)] = Just $ VConstant (B16 (op x y))
475−b16Bin _ _ = Nothing
476−
477−b16Un op [VConstant (B16 x)] = Just $ VConstant (B16 (op x))
478−b16Un _ _ = Nothing
479−
480−b32Bin op [VConstant (B32 x), VConstant (B32 y)] = Just $ VConstant (B32 (op x y))
481−b32Bin _ _ = Nothing
482−
483−b32Un op [VConstant (B32 x)] = Just $ VConstant (B32 (op x))
484−b32Un _ _ = Nothing
485−
486−b64Bin op [VConstant (B64 x), VConstant (B64 y)] = Just $ VConstant (B64 (op x y))
487−b64Bin _ _ = Nothing
488−
489−b64Un op [VConstant (B64 x)] = Just $ VConstant (B64 (op x))
490−b64Un _ _ = Nothing
491−
492−b8Cmp op [VConstant (B8 x), VConstant (B8 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
493−b8Cmp _ _ = Nothing
494−
495−b16Cmp op [VConstant (B16 x), VConstant (B16 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
496−b16Cmp _ _ = Nothing
497−
498−b32Cmp op [VConstant (B32 x), VConstant (B32 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
499−b32Cmp _ _ = Nothing
500−
501−b64Cmp op [VConstant (B64 x), VConstant (B64 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
502−b64Cmp _ _ = Nothing
503−
504−toB8 x = VConstant (B8 (fromIntegral x))
505−toB16 x = VConstant (B16 (fromIntegral x))
506−toB32 x = VConstant (B32 (fromIntegral x))
507−toB64 x = VConstant (B64 (fromIntegral x))
508−
509−zext8_16 [VConstant (B8 x)] = Just $ toB16 x
510−zext8_16 _ = Nothing
511−
512−zext8_32 [VConstant (B8 x)] = Just $ toB32 x
513−zext8_32 _ = Nothing
514−
515−zext8_64 [VConstant (B8 x)] = Just $ toB64 x
516−zext8_64 _ = Nothing
517−
518−sext8_16 [VConstant (B8 x)] = Just $ toB16 (fromIntegral x :: Int8)
519−sext8_16 _ = Nothing
520−
521−sext8_32 [VConstant (B8 x)] = Just $ toB32 (fromIntegral x :: Int8)
522−sext8_32 _ = Nothing
523−
524−sext8_64 [VConstant (B8 x)] = Just $ toB64 (fromIntegral x :: Int8)
525−sext8_64 _ = Nothing
526−
527−zext16_32 [VConstant (B16 x)] = Just $ toB32 x
528−zext16_32 _ = Nothing
529−
530−zext16_64 [VConstant (B16 x)] = Just $ toB64 x
531−zext16_64 _ = Nothing
532−
533−sext16_32 [VConstant (B16 x)] = Just $ toB32 (fromIntegral x :: Int16)
534−sext16_32 _ = Nothing
535−
536−sext16_64 [VConstant (B16 x)] = Just $ toB64 (fromIntegral x :: Int16)
537−sext16_64 _ = Nothing
538−
539−trunc16_8 [VConstant (B16 x)] = Just $ toB8 x
540−trunc16_8 _ = Nothing
541−
542−zext32_64 [VConstant (B32 x)] = Just $ toB64 x
543−zext32_64 _ = Nothing
544−
545−sext32_64 [VConstant (B32 x)] = Just $ toB64 (fromIntegral x :: Int32)
546−sext32_64 _ = Nothing
547−
548−trunc32_8 [VConstant (B32 x)] = Just $ toB8 x
549−trunc32_8 _ = Nothing
550−
551−trunc32_16 [VConstant (B32 x)] = Just $ toB16 x
552−trunc32_16 _ = Nothing
553−
554−trunc64_8 [VConstant (B64 x)] = Just $ toB8 x
555−trunc64_8 _ = Nothing
556−
557−trunc64_16 [VConstant (B64 x)] = Just $ toB16 x
558−trunc64_16 _ = Nothing
559−
560−trunc64_32 [VConstant (B64 x)] = Just $ toB32 x
561−trunc64_32 _ = Nothing
562−
563−intToBits8 [VConstant (I x)] = Just $ toB8 x
564−intToBits8 _ = Nothing
565−intToBits16 [VConstant (I x)] = Just $ toB16 x
566−intToBits16 _ = Nothing
567−intToBits32 [VConstant (I x)] = Just $ toB32 x
568−intToBits32 _ = Nothing
569−intToBits64 [VConstant (I x)] = Just $ toB64 x
570−intToBits64 _ = Nothing
571−
572−bits32ToInt [VConstant (B32 x)] = Just $ VConstant (I (fromIntegral x))
573−bits32ToInt _ = Nothing
574−
575−c_intToStr [VConstant (I x)] = Just $ VConstant (Str (show x))
576−c_intToStr _ = Nothing
577−c_strToInt [VConstant (Str x)] = case reads x of
578− [(n,"")] -> Just $ VConstant (I n)
579− _ -> Just $ VConstant (I 0)
580−c_strToInt _ = Nothing
263+bsrem IT8 [VConstant (B8 x), VConstant (B8 y)]
264+ = Just $ VConstant (B8 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int8)))
265+bsrem IT16 [VConstant (B16 x), VConstant (B16 y)]
266+ = Just $ VConstant (B16 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int16)))
267+bsrem IT32 [VConstant (B32 x), VConstant (B32 y)]
268+ = Just $ VConstant (B32 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int32)))
269+bsrem IT64 [VConstant (B64 x), VConstant (B64 y)]
270+ = Just $ VConstant (B64 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int64)))
271+bsrem ITNative [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (x `rem` y))
272+bsrem _ _ = Nothing
273+
274+bsdiv IT8 [VConstant (B8 x), VConstant (B8 y)]
275+ = Just $ VConstant (B8 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int8)))
276+bsdiv IT16 [VConstant (B16 x), VConstant (B16 y)]
277+ = Just $ VConstant (B16 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int16)))
278+bsdiv IT32 [VConstant (B32 x), VConstant (B32 y)]
279+ = Just $ VConstant (B32 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int32)))
280+bsdiv IT64 [VConstant (B64 x), VConstant (B64 y)]
281+ = Just $ VConstant (B64 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int64)))
282+bsdiv ITNative [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (x `div` y))
283+bsdiv _ _ = Nothing
284+
285+bashr IT8 [VConstant (B8 x), VConstant (B8 y)]
286+ = Just $ VConstant (B8 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int8)))
287+bashr IT16 [VConstant (B16 x), VConstant (B16 y)]
288+ = Just $ VConstant (B16 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int16)))
289+bashr IT32 [VConstant (B32 x), VConstant (B32 y)]
290+ = Just $ VConstant (B32 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int32)))
291+bashr IT64 [VConstant (B64 x), VConstant (B64 y)]
292+ = Just $ VConstant (B64 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int64)))
293+bashr ITNative [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (x `shiftR` y))
294+bashr _ _ = Nothing
295+
296+bUn :: IntTy -> (forall a. Bits a => a -> a) -> [Value] -> Maybe Value
297+bUn IT8 op [VConstant (B8 x)] = Just $ VConstant (B8 (op x))
298+bUn IT16 op [VConstant (B16 x)] = Just $ VConstant (B16 (op x))
299+bUn IT32 op [VConstant (B32 x)] = Just $ VConstant (B32 (op x))
300+bUn IT64 op [VConstant (B64 x)] = Just $ VConstant (B64 (op x))
301+bUn ITBig op [VConstant (BI x)] = Just $ VConstant (BI (op x))
302+bUn ITNative op [VConstant (I x)] = Just $ VConstant (I (op x))
303+bUn _ _ _ = Nothing
304+
305+bitBin :: IntTy -> (forall a. (Bits a, Integral a) => a -> a -> a) -> [Value] -> Maybe Value
306+bitBin IT8 op [VConstant (B8 x), VConstant (B8 y)] = Just $ VConstant (B8 (op x y))
307+bitBin IT16 op [VConstant (B16 x), VConstant (B16 y)] = Just $ VConstant (B16 (op x y))
308+bitBin IT32 op [VConstant (B32 x), VConstant (B32 y)] = Just $ VConstant (B32 (op x y))
309+bitBin IT64 op [VConstant (B64 x), VConstant (B64 y)] = Just $ VConstant (B64 (op x y))
310+bitBin ITBig op [VConstant (BI x), VConstant (BI y)] = Just $ VConstant (BI (op x y))
311+bitBin ITNative op [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (op x y))
312+bitBin _ _ _ = Nothing
313+
314+bCmp :: IntTy -> (forall a. Ord a => a -> a -> Bool) -> [Value] -> Maybe Value
315+bCmp IT8 op [VConstant (B8 x), VConstant (B8 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
316+bCmp IT16 op [VConstant (B16 x), VConstant (B16 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
317+bCmp IT32 op [VConstant (B32 x), VConstant (B32 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
318+bCmp IT64 op [VConstant (B64 x), VConstant (B64 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
319+bCmp ITBig op [VConstant (BI x), VConstant (BI y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
320+bCmp ITNative op [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
321+bCmp _ _ _ = Nothing
322+
323+toInt IT8 x = VConstant (B8 (fromIntegral x))
324+toInt IT16 x = VConstant (B16 (fromIntegral x))
325+toInt IT32 x = VConstant (B32 (fromIntegral x))
326+toInt IT64 x = VConstant (B64 (fromIntegral x))
327+toInt ITBig x = VConstant (BI (fromIntegral x))
328+toInt ITNative x = VConstant (I (fromIntegral x))
329+
330+intToInt IT8 out [VConstant (B8 x)] = Just $ toInt out x
331+intToInt IT16 out [VConstant (B16 x)] = Just $ toInt out x
332+intToInt IT32 out [VConstant (B32 x)] = Just $ toInt out x
333+intToInt IT64 out [VConstant (B64 x)] = Just $ toInt out x
334+intToInt ITBig out [VConstant (BI x)] = Just $ toInt out x
335+intToInt ITNative out [VConstant (I x)] = Just $ toInt out x
336+intToInt _ _ _ = Nothing
337+
338+zext from ITBig val = intToInt from ITBig val
339+zext ITBig _ _ = Nothing
340+zext from to val
341+ | intTyWidth from < intTyWidth to = intToInt from to val
342+zext _ _ _ = Nothing
343+
344+sext IT8 out [VConstant (B8 x)] = Just $ toInt out (fromIntegral x :: Int8)
345+sext IT16 out [VConstant (B16 x)] = Just $ toInt out (fromIntegral x :: Int16)
346+sext IT32 out [VConstant (B32 x)] = Just $ toInt out (fromIntegral x :: Int32)
347+sext IT64 out [VConstant (B64 x)] = Just $ toInt out (fromIntegral x :: Int64)
348+sext ITBig _ _ = Nothing
349+sext from to val = intToInt from to val
350+
351+trunc ITBig to val = intToInt ITBig to val
352+trunc _ ITBig _ = Nothing
353+trunc from to val | intTyWidth from > intTyWidth to = intToInt from to val
354+trunc _ _ _ = Nothing
355+
356+getInt :: [Value] -> Maybe Integer
357+getInt [VConstant (B8 x)] = Just . toInteger $ x
358+getInt [VConstant (B16 x)] = Just . toInteger $ x
359+getInt [VConstant (B32 x)] = Just . toInteger $ x
360+getInt [VConstant (B64 x)] = Just . toInteger $ x
361+getInt [VConstant (I x)] = Just . toInteger $ x
362+getInt [VConstant (BI x)] = Just x
363+getInt _ = Nothing
364+
365+intToStr val | Just i <- getInt val = Just $ VConstant (Str (show i))
366+intToStr _ = Nothing
367+
368+strToInt ity [VConstant (Str x)] = case reads x of
369+ [(n,"")] -> Just $ toInt ity (n :: Integer)
370+ _ -> Just $ VConstant (I 0)
371+strToInt _ _ = Nothing
372+
373+intToFloat val | Just i <- getInt val = Just $ VConstant (Fl (fromIntegral i))
374+intToFloat _ = Nothing
375+
376+floatToInt ity [VConstant (Fl x)] = Just $ toInt ity (truncate x :: Integer)
377+floatToInt _ _ = Nothing
581378
582379c_intToChar [VConstant (I x)] = Just $ VConstant (Ch (toEnum x))
583380c_intToChar _ = Nothing
584381c_charToInt [VConstant (Ch x)] = Just $ VConstant (I (fromEnum x))
585382c_charToInt _ = Nothing
586383
587−c_intToBigInt [VConstant (I x)] = Just $ VConstant (BI (fromIntegral x))
588−c_intToBigInt _ = Nothing
589−c_bigIntToInt [VConstant (BI x)] = Just $ VConstant (I (fromInteger x))
590−c_bigIntToInt _ = Nothing
591−
592−c_bigIntToStr [VConstant (BI x)] = Just $ VConstant (Str (show x))
593−c_bigIntToStr _ = Nothing
594−c_strToBigInt [VConstant (Str x)] = case reads x of
595− [(n,"")] -> Just $ VConstant (BI n)
596− _ -> Just $ VConstant (BI 0)
597−c_strToBigInt _ = Nothing
598−
599384c_floatToStr [VConstant (Fl x)] = Just $ VConstant (Str (show x))
600385c_floatToStr _ = Nothing
601386c_strToFloat [VConstant (Str x)] = case reads x of
@@ -603,12 +388,6 @@ c_strToFloat [VConstant (Str x)] = case reads x of
603388 _ -> Just $ VConstant (Fl 0)
604389c_strToFloat _ = Nothing
605390
606−c_floatToInt [VConstant (Fl x)] = Just $ VConstant (I (truncate x))
607−c_floatToInt _ = Nothing
608−
609−c_intToFloat [VConstant (I x)] = Just $ VConstant (Fl (fromIntegral x))
610−c_intToFloat _ = Nothing
611−
612391p_fPrim f [VConstant (Fl x)] = Just $ VConstant (Fl (f x))
613392p_fPrim f _ = Nothing
614393
test/test021/expected+2−2
@@ -2,5 +2,5 @@
22, WORLD!!!
33, ]
443
5−23
6−Answer: 107
5+15
6+Answer: 99
test/test021/test021a.idr+5−5
@@ -6,18 +6,18 @@ import Effect.Random
66import Effect.StdIO
77
88data Expr = Var String
9− | Val Int
9+ | Val Integer
1010 | Add Expr Expr
11− | Random Int
11+ | Random Integer
1212
1313Env : Type
14−Env = List (String, Int)
14+Env = List (String, Integer)
1515
1616-- Evaluator : Type -> Type
1717-- Evaluator t
1818-- = Eff m [EXCEPTION String, RND, STATE Env] t
1919
20−eval : Expr -> Eff IO [EXCEPTION String, STDIO, RND, STATE Env] Int
20+eval : Expr -> Eff IO [EXCEPTION String, STDIO, RND, STATE Env] Integer
2121eval (Var x) = do vs <- get
2222 case lookup x vs of
2323 Nothing => raise ("No such variable " ++ x)
@@ -31,7 +31,7 @@ eval (Random upper) = do val <- rndInt 0 upper
3131testExpr : Expr
3232testExpr = Add (Add (Var "foo") (Val 42)) (Random 100)
3333
34−runEval : List (String, Int) -> Expr -> IO Int
34+runEval : List (String, Integer) -> Expr -> IO Integer
3535runEval args expr = run [(), (), 123456, args] (eval expr)
3636
3737main : IO ()
test/test025/test025.idr+4−4
@@ -9,23 +9,23 @@ MemoryIO td ts r = Eff (IOExcept String) [ Dst ::: RAW_MEMORY td
99 , Src ::: RAW_MEMORY ts ] r
1010
1111inpVect : Vect Bits8 5
12−inpVect = map prim__intToB8 [0, 1, 2, 3, 5]
12+inpVect = map prim__truncInt_B8 [0, 1, 2, 3, 5]
1313
1414sub1 : Vect Bits8 n -> Vect Bits8 n
15−sub1 xs = map (prim__intToB8 . (\ x => x - 1) . prim__B32ToInt . prim__sextB8_32) xs
15+sub1 xs = map (prim__truncInt_B8 . (\ x => x - 1) . prim__zextB8_Int) xs
1616
1717testMemory : MemoryIO () () (Vect Int 4)
1818testMemory = do Src :- allocate 5
1919 Src :- poke 0 inpVect oh
2020 Dst :- allocate 5
21− Dst :- initialize (prim__intToB8 1) 2 oh
21+ Dst :- initialize (prim__truncInt_B8 1) 2 oh
2222 move 2 2 3 oh oh
2323 Src :- free
2424 end <- Dst :- peek 4 1 oh
2525 Dst :- poke 4 (sub1 end) oh
2626 res <- Dst :- peek 1 4 oh
2727 Dst :- free
28− return (map (prim__B32ToInt . prim__sextB8_32) res)
28+ return (map (prim__zextB8_Int) res)
2929
3030main : IO ()
3131main = do ioe_run (run [Dst := (), Src := ()] testMemory)