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

Bool values aren't injected into Cryptol expressions #1404

Closed
RyanGlScott opened this issue Aug 4, 2021 · 2 comments · Fixed by #1405
Closed

Bool values aren't injected into Cryptol expressions #1404

RyanGlScott opened this issue Aug 4, 2021 · 2 comments · Fixed by #1405
Labels
type: bug Issues reporting bugs or unexpected/unwanted behavior

Comments

@RyanGlScott
Copy link
Contributor

The SAW manual claims:

  • Any variable in scope that has SAWScript type Bool is visible in Cryptol expressions as a value of type Bit.

This doesn't appear to be true in practice, however:

$ ~/Software/saw-0.8/bin/saw 
 ┏━━━┓━━━┓━┓━┓━┓
 ┃ ━━┓ ╻ ┃ ┃ ┃ ┃
 ┣━━ ┃ ╻ ┃┓ ╻ ┏┛
 ┗━━━┛━┛━┛┗━┛━┛ version 0.8



sawscript> let b = true;
sawscript> {{ b }}

Cryptol error:
[error] at <stdin>:1:4--1:5 Value not in scope: b
@RyanGlScott RyanGlScott added the type: bug Issues reporting bugs or unexpected/unwanted behavior label Aug 4, 2021
@brianhuffman
Copy link
Contributor

To implement this feature, we'll just need to add a new case for constructor VBool to function extendEnv in module SAWScript.Value:

extendEnv ::
SharedContext ->
SS.LName -> Maybe SS.Schema -> Maybe String -> Value -> TopLevelRW -> IO TopLevelRW
extendEnv sc x mt md v rw =
do ce' <-
case v of
VTerm t ->
pure $ CEnv.bindTypedTerm (ident, t) ce
VType s ->
pure $ CEnv.bindType (ident, s) ce
VInteger n ->
pure $ CEnv.bindInteger (ident, n) ce
VCryptolModule m ->
pure $ CEnv.bindCryptolModule (modname, m) ce
VString s ->
do tt <- typedTermOfString sc (unpack s)
pure $ CEnv.bindTypedTerm (ident, tt) ce
_ ->
pure ce
pure $
rw { rwValues = M.insert name v (rwValues rw)
, rwTypes = maybeInsert name mt (rwTypes rw)
, rwDocs = maybeInsert (SS.getVal name) md (rwDocs rw)
, rwCryptol = ce'
}

@brianhuffman
Copy link
Contributor

Adding this case should do it:

         VBool b ->
           do t <- scBool sc b
              let schema = Cryptol.tMono Cryptol.tBit
              let tt = TypedTerm (TypedTermSchema schema) t
              pure $ CEnv.bindTypedTerm (ident, tt) ce

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Issues reporting bugs or unexpected/unwanted behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants