on master help sign in
Primitives for interconversion of Bits32 and Int
b3ba46eBenjamin Saunders
rts/idris_bitstring.c+4
@@ -56,6 +56,10 @@ VAL idris_b64(VM *vm, VAL a) {
56 return cl;
56 return cl;
57}
57}
58
58
59+VAL idris_castB32Int(VM *vm, VAL a) {
60+ return MKINT(a->info.bits32);
61+}
62+
59VAL idris_b8Plus(VM *vm, VAL a, VAL b) {
63VAL idris_b8Plus(VM *vm, VAL a, VAL b) {
60 VAL cl = allocate(vm, sizeof(Closure), 0);
64 VAL cl = allocate(vm, sizeof(Closure), 0);
61 SETTY(cl, BITS8);
65 SETTY(cl, BITS8);
src/IRTS/CodegenC.hs+6−4
@@ -297,10 +297,12 @@ doOp v LReadStr [x] = v ++ "idris_readStr(vm, GETPTR(" ++ creg x ++ "))"
297doOp _ LPrintNum [x] = "printf(\"%ld\\n\", GETINT(" ++ creg x ++ "))"
297doOp _ LPrintNum [x] = "printf(\"%ld\\n\", GETINT(" ++ creg x ++ "))"
298doOp _ LPrintStr [x] = "fputs(GETSTR(" ++ creg x ++ "), stdout)"
298doOp _ LPrintStr [x] = "fputs(GETSTR(" ++ creg x ++ "), stdout)"
299
299
300−doOp v LB8 [x] = v ++ "idris_b8(" ++ creg x ++ ")"
300+doOp v LIntB8 [x] = v ++ "idris_b8(" ++ creg x ++ ")"
301−doOp v LB16 [x] = v ++ "idris_b16(" ++ creg x ++ ")"
301+doOp v LIntB16 [x] = v ++ "idris_b16(" ++ creg x ++ ")"
302−doOp v LB32 [x] = v ++ "idris_b32(" ++ creg x ++ ")"
302+doOp v LIntB32 [x] = v ++ "idris_b32(" ++ creg x ++ ")"
303−doOp v LB64 [x] = v ++ "idris_b64(" ++ creg x ++ ")"
303+doOp v LIntB64 [x] = v ++ "idris_b64(" ++ creg x ++ ")"
304+
305+doOp v LB32Int [x] = v ++ "idris_castB32Int(" ++ creg x ++ ")"
304
306
305doOp v LB8Plus [x, y] = v ++ "idris_b8Plus(" ++ creg x ++ "," ++ creg y ++ ")"
307doOp v LB8Plus [x, y] = v ++ "idris_b8Plus(" ++ creg x ++ "," ++ creg y ++ ")"
306doOp v LB8Minus [x, y] = v ++ "idris_b8Minus(" ++ creg x ++ "," ++ creg y ++ ")"
308doOp v LB8Minus [x, y] = v ++ "idris_b8Minus(" ++ creg x ++ "," ++ creg y ++ ")"
src/IRTS/Lang.hs+1−2
@@ -40,8 +40,6 @@ data PrimFn = LPlus | LMinus | LTimes | LDiv | LMod
40 | LIntBig | LBigInt | LStrBig | LBigStr
40 | LIntBig | LBigInt | LStrBig | LBigStr
41 | LPrintNum | LPrintStr | LReadStr
41 | LPrintNum | LPrintStr | LReadStr
42
42
43− | LB8 | LB16 | LB32 | LB64
44−
45 | LB8Plus | LB8Minus | LB8Times | LB8UDiv | LB8SDiv
43 | LB8Plus | LB8Minus | LB8Times | LB8UDiv | LB8SDiv
46 | LB8Z16 | LB8Z32 | LB8Z64 | LB8S16 | LB8S32 | LB8S64 -- Zero/Sign extension
44 | LB8Z16 | LB8Z32 | LB8Z64 | LB8S16 | LB8S32 | LB8S64 -- Zero/Sign extension
47 | LB16Plus | LB16Minus | LB16Times | LB16UDiv | LB16SDiv
45 | LB16Plus | LB16Minus | LB16Times | LB16UDiv | LB16SDiv
@@ -50,6 +48,7 @@ data PrimFn = LPlus | LMinus | LTimes | LDiv | LMod
50 | LB32Z64 | LB32S64 | LB32T8 | LB32T16
48 | LB32Z64 | LB32S64 | LB32T8 | LB32T16
51 | LB64Plus | LB64Minus | LB64Times | LB64UDiv | LB64SDiv
49 | LB64Plus | LB64Minus | LB64Times | LB64UDiv | LB64SDiv
52 | LB64T8 | LB64T16 | LB64T32
50 | LB64T8 | LB64T16 | LB64T32
51+ | LIntB8 | LIntB16 | LIntB32 | LIntB64 | LB32Int
53
52
54 | LFExp | LFLog | LFSin | LFCos | LFTan | LFASin | LFACos | LFATan
53 | LFExp | LFLog | LFSin | LFCos | LFTan | LFASin | LFACos | LFATan
55 | LFSqrt | LFFloor | LFCeil
54 | LFSqrt | LFFloor | LFCeil
src/Idris/Primitives.hs+12−8
@@ -157,14 +157,16 @@ primitives =
157 Prim (UN "prim__truncB64_32") (ty [B64Type] B32Type) 1 trunc64_32
157 Prim (UN "prim__truncB64_32") (ty [B64Type] B32Type) 1 trunc64_32
158 (1, LB64T32) total,
158 (1, LB64T32) total,
159
159
160− Prim (UN "prim__intToBits8") (ty [IType] B8Type) 1 intToBits8
160+ Prim (UN "prim__intToB8") (ty [IType] B8Type) 1 intToBits8
161− (1, LB8) total,
161+ (1, LIntB8) total,
162− Prim (UN "prim__intToBits16") (ty [IType] B16Type) 1 intToBits16
162+ Prim (UN "prim__intToB16") (ty [IType] B16Type) 1 intToBits16
163− (1, LB16) total,
163+ (1, LIntB16) total,
164− Prim (UN "prim__intToBits32") (ty [IType] B32Type) 1 intToBits32
164+ Prim (UN "prim__intToB32") (ty [IType] B32Type) 1 intToBits32
165− (1, LB32) total,
165+ (1, LIntB32) total,
166− Prim (UN "prim__intToBits64") (ty [IType] B64Type) 1 intToBits64
166+ Prim (UN "prim__intToB64") (ty [IType] B64Type) 1 intToBits64
167+ (1, LIntB64) total,
168+ Prim (UN "prim__B32ToInt") (ty [B32Type] IType) 1 bits32ToInt
167− (1, LB64) total,
169+ (1, LB32Int) total,
168
170
169 Prim (UN "prim__addBigInt") (ty [BIType, BIType] BIType) 2 (bBin (+))
171 Prim (UN "prim__addBigInt") (ty [BIType, BIType] BIType) 2 (bBin (+))
170 (2, LBPlus) total,
172 (2, LBPlus) total,
@@ -409,6 +411,8 @@ intToBits32 _ = Nothing
409intToBits64 [VConstant (I x)] = Just $ toB64 x
411intToBits64 [VConstant (I x)] = Just $ toB64 x
410intToBits64 _ = Nothing
412intToBits64 _ = Nothing
411
413
414+bits32ToInt [VConstant (B32 x)] = Just $ VConstant (I (fromIntegral x))
415+
412c_intToStr [VConstant (I x)] = Just $ VConstant (Str (show x))
416c_intToStr [VConstant (I x)] = Just $ VConstant (Str (show x))
413c_intToStr _ = Nothing
417c_intToStr _ = Nothing
414c_strToInt [VConstant (Str x)] = case reads x of
418c_strToInt [VConstant (Str x)] = case reads x of