Backup commit
My backspace key started ghosting. Nothing works atm.
This commit is contained in:
@@ -1,32 +1,38 @@
|
||||
use hashbrown::HashMap;
|
||||
|
||||
use crate::interner::Interner;
|
||||
use crate::representations::interpreted::ExprInst;
|
||||
use crate::Sym;
|
||||
use super::nort::Expr;
|
||||
use crate::name::Sym;
|
||||
|
||||
/// All the data associated with an interpreter run
|
||||
#[derive(Clone)]
|
||||
pub struct Context<'a> {
|
||||
pub struct RunContext<'a> {
|
||||
/// Table used to resolve constants
|
||||
pub symbols: &'a HashMap<Sym, ExprInst>,
|
||||
/// The interner used for strings internally, so external functions can
|
||||
/// deduce referenced constant names on the fly
|
||||
pub interner: &'a Interner,
|
||||
pub symbols: &'a HashMap<Sym, Expr>,
|
||||
/// The number of reduction steps the interpreter can take before returning
|
||||
pub gas: Option<usize>,
|
||||
}
|
||||
impl<'a> RunContext<'a> {
|
||||
/// Consume some gas if it is being counted
|
||||
pub fn use_gas(&mut self, amount: usize) {
|
||||
if let Some(g) = self.gas.as_mut() {
|
||||
*g = g.saturating_sub(amount)
|
||||
}
|
||||
}
|
||||
/// Gas is being counted and there is none left
|
||||
pub fn no_gas(&self) -> bool { self.gas == Some(0) }
|
||||
}
|
||||
|
||||
/// All the data produced by an interpreter run
|
||||
#[derive(Clone)]
|
||||
pub struct Return {
|
||||
pub struct Halt {
|
||||
/// The new expression tree
|
||||
pub state: ExprInst,
|
||||
pub state: Expr,
|
||||
/// Leftover [Context::gas] if counted
|
||||
pub gas: Option<usize>,
|
||||
/// If true, the next run would not modify the expression
|
||||
pub inert: bool,
|
||||
}
|
||||
impl Return {
|
||||
impl Halt {
|
||||
/// Check if gas has run out. Returns false if gas is not being used
|
||||
pub fn preempted(&self) -> bool { self.gas.map_or(false, |g| g == 0) }
|
||||
/// Returns a general report of the return
|
||||
|
||||
Reference in New Issue
Block a user