Skip to content

Commit 6cd1d21

Browse files
author
Mieszko
committed
Add isStaticValue to the Prelude
1 parent f365d35 commit 6cd1d21

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/Libraries/Base1/Prelude.bs

+8-7
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ package Prelude(
4343
sameFamily, isAncestor,
4444
chkClockDomain,
4545

46+
isStaticValue,
4647
impCondOf,
4748

4849
primZeroExt, primSignExt, primTrunc,
@@ -1259,9 +1260,6 @@ replaceBit pos w i b =
12591260
data Bool = False | True
12601261
deriving (Eq, Bits, Bounded, FShow, DefaultValue)
12611262

1262-
isStaticBool :: Bool -> Bool
1263-
isStaticBool = compose areStaticBits pack
1264-
12651263
--@ \begin{libverbatim}
12661264
--@ function Bool not(Bool x);
12671265
--@ \end{libverbatim}
@@ -2850,6 +2848,9 @@ primitive primAreStaticBits :: Bit n -> Bit 1
28502848
areStaticBits :: Bit n -> Bool
28512849
areStaticBits = compose primChr primAreStaticBits
28522850

2851+
isStaticValue :: (Bits a n) => a -> Bool
2852+
isStaticValue = areStaticBits ∘ pack
2853+
28532854
-- these are elaboration-time-only conversions
28542855
-- primAreStaticBits should be called first
28552856
primitive primUIntBitsToInteger :: Bit n -> Integer
@@ -3482,7 +3483,7 @@ listStaticSelect pos xs n =
34823483
listPrimSelect' Nil _ n0 =
34833484
let b = n0 < 0 || listNullOrUndef (listDrop n0 xs)
34843485
-- don't raise an error unless we can prove we are out-of-bounds
3485-
in if (isStaticBool b) && b then
3486+
in if (isStaticValue b) && b then
34863487
primError pos $ listMessage n0 "list selection"
34873488
else primBuildUndefined pos iuDontCare -- should add runtime error here
34883489
listPrimSelect' (Cons x _) 0 _ = x
@@ -3518,7 +3519,7 @@ listPrimUpdate pos l k x =
35183519
primGenerateError 78 pos "Attempt to update an undetermined list"
35193520
else if (isRawUndefined k) then
35203521
primGenerateError 79 pos "Attempt to update a list at an undetermined position"
3521-
else if ((isStaticIndex k) && (k' < 0 || (isStaticBool b && b)))
3522+
else if ((isStaticIndex k) && (k' < 0 || (isStaticValue b && b)))
35223523
then primError pos $ listMessage k' "list updating"
35233524
else listPrimMap (\ p -> if (rangeTest p.snd) && (k == fromInteger p.snd) then x else p.fst)
35243525
(listPrimNum l)
@@ -3597,7 +3598,7 @@ instance PrimSelectable (Array a) a
35973598
if (isStaticIndex x) then
35983599
letseq i = toStaticIndex x
35993600
b = i >= primArrayLength v
3600-
in if (isStaticBool b && b) || (i < 0) then
3601+
in if (isStaticValue b && b) || (i < 0) then
36013602
primError pos (listMessage i "array selection" )
36023603
else primArraySelect v i
36033604
else primArrayDynSelect v (toDynamicIndex x)
@@ -3618,7 +3619,7 @@ instance PrimUpdateable (Array a) a
36183619
else if (isStaticIndex x) then
36193620
letseq i = toStaticIndex x
36203621
b = i >= primArrayLength v
3621-
in if (isStaticBool b && b) || (i < 0) then
3622+
in if (isStaticValue b && b) || (i < 0) then
36223623
primError pos (listMessage i "array update")
36233624
else primArrayUpdate v i n
36243625
else primArrayDynUpdate v (toDynamicIndex x) n

0 commit comments

Comments
 (0)