@@ -167,6 +167,9 @@ module SAWCentral.Value (
167167 runProofScript ,
168168 -- used by SAWCentral.Builtins, SAWScript.Interpreter
169169 scriptTopLevel ,
170+ llvmTopLevel ,
171+ jvmTopLevel ,
172+ mirTopLevel ,
170173 -- used in SAWScript.Interpreter
171174 -- XXX: probably belongs in SAWSupport
172175 underStateT ,
@@ -295,10 +298,18 @@ data Value
295298 | VBuiltin (Value -> TopLevel Value )
296299 | VTerm TypedTerm
297300 | VType Cryptol. Schema
298- | VReturn Value -- Returned value in unspecified monad
299- | VBind SS. Pos Value Value
300- -- ^ Monadic bind in unspecified monad. Requires a source position because
301- -- operations in these monads can fail at runtime.
301+ -- | Returned value in unspecified monad
302+ | VReturn Value
303+ -- | Not-yet-executed do-block in unspecified monad
304+ --
305+ -- The string is a hack hook for the current implementation of
306+ -- stack traces. See the commit message that added it for further
307+ -- information. XXX: to be removed along with the stack trace code
308+ | VDo SS. Pos (Maybe String ) LocalEnv [SS. Stmt ]
309+ -- | Single monadic bind in unspecified monad.
310+ -- This exists only to support the "for" builtin; see notes there
311+ -- for why this is so. XXX: remove it once that's no longer needed
312+ | VBindOnce Value Value
302313 | VTopLevel (TopLevel Value )
303314 | VProofScript (ProofScript Value )
304315 | VSimpset SAWSimpset
@@ -443,6 +454,7 @@ showRefnset opts ss =
443454 ppFunAssumpRHS ctx (RewriteFunAssump rhs) =
444455 SAWCorePP. ppTermInCtx opts (map fst $ mrVarCtxInnerToOuter ctx) rhs
445456
457+ -- XXX the precedence in here needs to be cleaned up
446458showsPrecValue :: PPS. Opts -> DisplayNameEnv -> Int -> Value -> ShowS
447459showsPrecValue opts nenv p v =
448460 case v of
@@ -467,8 +479,15 @@ showsPrecValue opts nenv p v =
467479 VBuiltin {} -> showString " <<builtin>>"
468480 VTerm t -> showString (SAWCorePP. showTermWithNames opts nenv (ttTerm t))
469481 VType sig -> showString (pretty sig)
470- VReturn {} -> showString " <<monadic>>"
471- VBind {} -> showString " <<monadic>>"
482+ VReturn v' -> showString " return " . showsPrecValue opts nenv (p + 1 ) v'
483+ VDo pos _name _env stmts ->
484+ let e = SS. Block pos stmts in
485+ shows (PP. pretty e)
486+ VBindOnce v1 v2 ->
487+ let v1' = showsPrecValue opts nenv 0 v1
488+ v2' = showsPrecValue opts nenv 0 v2
489+ in
490+ v1' . showString " >>= " . v2'
472491 VTopLevel {} -> showString " <<TopLevel>>"
473492 VSimpset ss -> showString (showSimpset opts ss)
474493 VRefnset ss -> showString (showRefnset opts ss)
@@ -922,6 +941,11 @@ instance Monad LLVMCrucibleSetupM where
922941 LLVMCrucibleSetupM m >>= f =
923942 LLVMCrucibleSetupM (m >>= \ x -> runLLVMCrucibleSetupM (f x))
924943
944+ -- XXX this is required for the moment in the interpreter, and should
945+ -- be removed when we clean out error handling.
946+ instance MonadFail LLVMCrucibleSetupM where
947+ fail msg = LLVMCrucibleSetupM $ lift $ lift $ fail msg
948+
925949throwCrucibleSetup :: ProgramLoc -> String -> CrucibleSetup ext a
926950throwCrucibleSetup loc msg = X. throw $ SS. CrucibleSetupException loc msg
927951
@@ -946,13 +970,23 @@ type JVMSetup = CrucibleSetup CJ.JVM
946970newtype JVMSetupM a = JVMSetupM { runJVMSetupM :: JVMSetup a }
947971 deriving (Applicative , Functor , Monad )
948972
973+ -- XXX this is required for the moment in the interpreter, and should
974+ -- be removed when we clean out error handling.
975+ instance MonadFail JVMSetupM where
976+ fail msg = JVMSetupM $ lift $ lift $ fail msg
977+
949978--
950979
951980type MIRSetup = CrucibleSetup MIR
952981
953982newtype MIRSetupM a = MIRSetupM { runMIRSetupM :: MIRSetup a }
954983 deriving (Applicative , Functor , Monad )
955984
985+ -- XXX this is required for the moment in the interpreter, and should
986+ -- be removed when we clean out error handling.
987+ instance MonadFail MIRSetupM where
988+ fail msg = MIRSetupM $ lift $ lift $ fail msg
989+
956990--
957991newtype ProofScript a = ProofScript { unProofScript :: ExceptT (SolverStats , CEX ) (StateT ProofState TopLevel ) a }
958992 deriving (Functor , Applicative , Monad )
@@ -986,6 +1020,15 @@ runProofScript (ProofScript m) concl gl ploc rsn recordThm useSequentGoals =
9861020scriptTopLevel :: TopLevel a -> ProofScript a
9871021scriptTopLevel m = ProofScript (lift (lift m))
9881022
1023+ llvmTopLevel :: TopLevel a -> LLVMCrucibleSetupM a
1024+ llvmTopLevel m = LLVMCrucibleSetupM (lift (lift m))
1025+
1026+ jvmTopLevel :: TopLevel a -> JVMSetupM a
1027+ jvmTopLevel m = JVMSetupM (lift (lift m))
1028+
1029+ mirTopLevel :: TopLevel a -> MIRSetupM a
1030+ mirTopLevel m = MIRSetupM (lift (lift m))
1031+
9891032instance MonadIO ProofScript where
9901033 liftIO m = ProofScript (liftIO m)
9911034
0 commit comments