@@ -1925,7 +1925,7 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of
1925
1925
1926
1926
-- Enum
1927
1927
" Clash.Sized.Internal.BitVector.toEnum##"
1928
- | [i] <- intLiterals ' args
1928
+ | [i] <- intCLiterals ' args
1929
1929
-> let Bit msk val = BitVector. toEnum ## (fromInteger i)
1930
1930
in reduce (mkBitLit ty (toInteger msk) (toInteger val))
1931
1931
@@ -2140,7 +2140,8 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of
2140
2140
2141
2141
" Clash.Sized.Internal.BitVector.fromEnum#"
2142
2142
| Just (_, kn) <- extractKnownNat tcm tys
2143
- , Just val <- reifyNat kn (liftBitVector2Int (toInteger . BitVector. fromEnum # ) args)
2143
+ , let resTy = getResultTy tcm ty tys
2144
+ , Just val <- reifyNat kn (liftBitVector2CInt tcm resTy (toInteger . BitVector. fromEnum # ) args)
2144
2145
-> reduce val
2145
2146
2146
2147
-- Bounded
@@ -2317,13 +2318,14 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of
2317
2318
2318
2319
-- Enum
2319
2320
" Clash.Sized.Internal.Index.toEnum#"
2320
- | [i] <- intLiterals ' args
2321
+ | [i] <- intCLiterals ' args
2321
2322
, Just (nTy, mb) <- extractKnownNat tcm tys
2322
2323
-> reduce (mkIndexLit ty nTy mb i)
2323
2324
2324
2325
" Clash.Sized.Internal.Index.fromEnum#"
2325
2326
| [i] <- indexLiterals' args
2326
- -> reduce (integerToIntLiteral i)
2327
+ -> let resTy = getResultTy tcm ty tys
2328
+ in reduce (mkIntCLit tcm i resTy)
2327
2329
2328
2330
-- Bounded
2329
2331
" Clash.Sized.Internal.Index.maxBound#"
@@ -2433,13 +2435,14 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of
2433
2435
2434
2436
-- Enum
2435
2437
" Clash.Sized.Internal.Signed.toEnum#"
2436
- | [i] <- intLiterals ' args
2438
+ | [i] <- intCLiterals ' args
2437
2439
, Just (litTy, mb) <- extractKnownNat tcm tys
2438
2440
-> reduce (mkSignedLit ty litTy mb i)
2439
2441
2440
2442
" Clash.Sized.Internal.Signed.fromEnum#"
2441
2443
| [i] <- signedLiterals' args
2442
- -> reduce (integerToIntLiteral i)
2444
+ -> let resTy = getResultTy tcm ty tys
2445
+ in reduce (mkIntCLit tcm i resTy)
2443
2446
2444
2447
-- Bounded
2445
2448
" Clash.Sized.Internal.Signed.minBound#"
@@ -2650,13 +2653,14 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of
2650
2653
2651
2654
-- Enum
2652
2655
" Clash.Sized.Internal.Unsigned.toEnum#"
2653
- | [i] <- intLiterals ' args
2656
+ | [i] <- intCLiterals ' args
2654
2657
, Just (litTy, mb) <- extractKnownNat tcm tys
2655
2658
-> reduce (mkUnsignedLit ty litTy mb i)
2656
2659
2657
2660
" Clash.Sized.Internal.Unsigned.fromEnum#"
2658
2661
| [i] <- unsignedLiterals' args
2659
- -> reduce (integerToIntLiteral i)
2662
+ -> let resTy = getResultTy tcm ty tys
2663
+ in reduce (mkIntCLit tcm i resTy)
2660
2664
2661
2665
-- Bounded
2662
2666
" Clash.Sized.Internal.Unsigned.minBound#"
@@ -4047,6 +4051,9 @@ intLiterals = pairOf intLiteral
4047
4051
intLiterals' :: [Value ] -> [Integer ]
4048
4052
intLiterals' = listOf intLiteral
4049
4053
4054
+ intCLiterals' :: [Value ] -> [Integer ]
4055
+ intCLiterals' = listOf intCLiteral
4056
+
4050
4057
intLiteral :: Value -> Maybe Integer
4051
4058
intLiteral x = case x of
4052
4059
Lit (IntLiteral i) -> Just i
@@ -4182,6 +4189,14 @@ bitVectorLitIntLit tcm tys args
4182
4189
| otherwise
4183
4190
= Nothing
4184
4191
4192
+ mkIntCLit :: TyConMap -> Integer -> Type -> Term
4193
+ mkIntCLit tcm lit resTy =
4194
+ App (Data intDc) (Literal (IntLiteral lit))
4195
+ where
4196
+ (_, tyView -> TyConApp intTcNm [] ) = splitFunForallTy resTy
4197
+ Just intTc = lookupUniqMap intTcNm tcm
4198
+ [intDc] = tyConDataCons intTc
4199
+
4185
4200
mkFloatCLit :: TyConMap -> Word32 -> Type -> Term
4186
4201
mkFloatCLit tcm lit resTy =
4187
4202
App (Data floatDc) (Literal (FloatLiteral lit))
@@ -4468,22 +4483,24 @@ liftInteger2BitVector
4468
4483
-> [Value ]
4469
4484
-> (Proxy n -> Maybe Term )
4470
4485
liftInteger2BitVector f resTyInfo args _p
4471
- | [i] <- intLiterals ' args
4486
+ | [i] <- intCLiterals ' args
4472
4487
= let BV msk val = f i
4473
4488
in Just (mkBitVectorLit' resTyInfo (toInteger msk) (toInteger val))
4474
4489
4475
4490
| otherwise
4476
4491
= Nothing
4477
4492
4478
- liftBitVector2Int
4493
+ liftBitVector2CInt
4479
4494
:: KnownNat n
4480
- => (BitVector n -> Integer )
4495
+ => TyConMap
4496
+ -> Type
4497
+ -> (BitVector n -> Integer )
4481
4498
-> [Value ]
4482
4499
-> (Proxy n -> Maybe Term )
4483
- liftBitVector2Int f args _p
4500
+ liftBitVector2CInt tcm resTy f args _p
4484
4501
| [i] <- bitVectorLiterals' args
4485
4502
= let val = f (toBV i)
4486
- in Just $ integerToIntLiteral val
4503
+ in Just $ mkIntCLit tcm val resTy
4487
4504
| otherwise
4488
4505
= Nothing
4489
4506
0 commit comments