1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! Random draws (`TLC!RandomElement`): the run's streams, which the engine
//! supplies.
//!
//! The core defines the interface only. `dive-api` implements it with
//! `dive-stdlib`'s seeded streams and `dive-store`'s TLC state fingerprint,
//! so that the core's draws continue the streams start-up evaluation drew
//! from.
use dive_ir::StdOp;
use dive_value::{Ctx, Value};
use crate::Error;
use crate::handle::Handle;
use crate::heap::Heap;
/// A random stream in use: the startup stream, or one expanded state's.
pub trait DrawStream: Send + std::fmt::Debug {
/// Applies the random operator `op` to `args`, drawing from the stream.
///
/// # Errors
/// TLC's evaluation error of the operator, or a refusal.
fn draw(&mut self, op: StdOp, args: &[Value], ctx: Ctx) -> Result<Value, Error>;
}
/// The run's random streams.
pub trait Draws: Send + Sync {
/// The startup stream, where the constant definitions and `ASSUME`s
/// left it: `Init` draws from it.
fn startup(&self) -> Box<dyn DrawStream>;
/// The stream for expanding the state whose variables (in IR order)
/// are `vars`: TLC's `fingerprint(state) ^ seed`, or dive's replayable
/// stream keyed by the fingerprint.
///
/// # Errors
/// A state that cannot be converted or fingerprinted.
fn state(&self, heap: &mut Heap, vars: &[Handle]) -> Result<Box<dyn DrawStream>, Error>;
}
/// The run's `TLCSet`/`TLCGet` registers: the
/// dive-eval evaluator's, which constant definitions and `ASSUME`s wrote.
pub trait Registers: Send + Sync {
/// Applies `TLCSet(key, value)` or `TLCGet(key)` to evaluated
/// arguments. `TLCGet("level")` never reaches it.
///
/// # Errors
/// TLC's evaluation error, or a refusal.
fn call(&self, op: StdOp, args: &[Value]) -> Result<Value, Error>;
}