Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isStaticValue to the Prelude #747

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/Libraries/Base1/Prelude.bs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ package Prelude(
sameFamily, isAncestor,
chkClockDomain,

isStaticValue,
impCondOf,

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

isStaticBool :: Bool -> Bool
isStaticBool = compose areStaticBits pack

--@ \begin{libverbatim}
--@ function Bool not(Bool x);
--@ \end{libverbatim}
Expand Down Expand Up @@ -2850,6 +2848,9 @@ primitive primAreStaticBits :: Bit n -> Bit 1
areStaticBits :: Bit n -> Bool
areStaticBits = compose primChr primAreStaticBits

isStaticValue :: (Bits a n) => a -> Bool
isStaticValue = areStaticBits ∘ pack

-- these are elaboration-time-only conversions
-- primAreStaticBits should be called first
primitive primUIntBitsToInteger :: Bit n -> Integer
Expand Down Expand Up @@ -3482,7 +3483,7 @@ listStaticSelect pos xs n =
listPrimSelect' Nil _ n0 =
let b = n0 < 0 || listNullOrUndef (listDrop n0 xs)
-- don't raise an error unless we can prove we are out-of-bounds
in if (isStaticBool b) && b then
in if (isStaticValue b) && b then
primError pos $ listMessage n0 "list selection"
else primBuildUndefined pos iuDontCare -- should add runtime error here
listPrimSelect' (Cons x _) 0 _ = x
Expand Down Expand Up @@ -3518,7 +3519,7 @@ listPrimUpdate pos l k x =
primGenerateError 78 pos "Attempt to update an undetermined list"
else if (isRawUndefined k) then
primGenerateError 79 pos "Attempt to update a list at an undetermined position"
else if ((isStaticIndex k) && (k' < 0 || (isStaticBool b && b)))
else if ((isStaticIndex k) && (k' < 0 || (isStaticValue b && b)))
then primError pos $ listMessage k' "list updating"
else listPrimMap (\ p -> if (rangeTest p.snd) && (k == fromInteger p.snd) then x else p.fst)
(listPrimNum l)
Expand Down Expand Up @@ -3597,7 +3598,7 @@ instance PrimSelectable (Array a) a
if (isStaticIndex x) then
letseq i = toStaticIndex x
b = i >= primArrayLength v
in if (isStaticBool b && b) || (i < 0) then
in if (isStaticValue b && b) || (i < 0) then
primError pos (listMessage i "array selection" )
else primArraySelect v i
else primArrayDynSelect v (toDynamicIndex x)
Expand All @@ -3618,7 +3619,7 @@ instance PrimUpdateable (Array a) a
else if (isStaticIndex x) then
letseq i = toStaticIndex x
b = i >= primArrayLength v
in if (isStaticBool b && b) || (i < 0) then
in if (isStaticValue b && b) || (i < 0) then
primError pos (listMessage i "array update")
else primArrayUpdate v i n
else primArrayDynUpdate v (toDynamicIndex x) n
Expand Down
Loading