Allow initialization of EvalState tag and separate debugger state into separate variable.

This commit is contained in:
Stephen Chung
2022-05-21 21:44:12 +08:00
parent 5435fdb8c8
commit 1abec0a8a8
10 changed files with 86 additions and 25 deletions

View File

@@ -201,7 +201,7 @@ impl Engine {
scope: &Scope,
scripts: impl AsRef<[S]>,
) -> ParseResult<AST> {
self.compile_with_scope_and_optimization_level(scope, scripts, self.optimization_level)
self.compile_with_scope_and_optimization_level(scope, scripts, self.optimization_level())
}
/// Join a list of strings and compile into an [`AST`] using own scope at a specific optimization level.
///
@@ -292,6 +292,6 @@ impl Engine {
let mut peekable = stream.peekable();
let mut state = ParseState::new(self, scope, tokenizer_control);
self.parse_global_expr(&mut peekable, &mut state, self.optimization_level)
self.parse_global_expr(&mut peekable, &mut state, self.optimization_level())
}
}

View File

@@ -67,7 +67,7 @@ impl Engine {
let ast = self.compile_with_scope_and_optimization_level(
scope,
&[script],
self.optimization_level,
self.optimization_level(),
)?;
self.eval_ast_with_scope(scope, &ast)
}

View File

@@ -30,7 +30,7 @@ pub mod deprecated;
use crate::engine::Precedence;
use crate::tokenizer::Token;
use crate::{Engine, Identifier};
use crate::{Dynamic, Engine, Identifier};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
@@ -195,4 +195,23 @@ impl Engine {
Ok(self)
}
/// Get the default value of the custom state for each evaluation run.
#[inline(always)]
#[must_use]
pub fn default_tag(&self) -> &Dynamic {
&self.def_tag
}
/// Get a mutable reference to the default value of the custom state for each evaluation run.
#[inline(always)]
#[must_use]
pub fn default_tag_mut(&mut self) -> &mut Dynamic {
&mut self.def_tag
}
/// Set the default value of the custom state for each evaluation run.
#[inline(always)]
pub fn set_default_tag(&mut self, value: impl Into<Dynamic>) -> &mut Self {
self.def_tag = value.into();
self
}
}

View File

@@ -26,7 +26,11 @@ impl Engine {
self.lex_raw(&scripts, self.token_mapper.as_ref().map(Box::as_ref));
let mut state = ParseState::new(self, scope, tokenizer_control);
let ast = self.parse(&mut stream.peekable(), &mut state, self.optimization_level)?;
let ast = self.parse(
&mut stream.peekable(),
&mut state,
self.optimization_level(),
)?;
self.run_ast_with_scope(scope, &ast)
}