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

@@ -253,17 +253,20 @@ pub struct Debugger {
break_points: Vec<BreakPoint>,
/// The current function call stack.
call_stack: Vec<CallStackFrame>,
/// The current state.
state: Dynamic,
}
impl Debugger {
/// Create a new [`Debugger`].
#[inline(always)]
#[must_use]
pub fn new(status: DebuggerStatus) -> Self {
pub fn new(status: DebuggerStatus, state: Dynamic) -> Self {
Self {
status,
break_points: Vec::new(),
call_stack: Vec::new(),
state,
}
}
/// Get the current call stack.
@@ -374,6 +377,23 @@ impl Debugger {
pub fn break_points_mut(&mut self) -> &mut Vec<BreakPoint> {
&mut self.break_points
}
/// Get the custom state.
#[inline(always)]
#[must_use]
pub fn state(&self) -> &Dynamic {
&self.state
}
/// Get a mutable reference to the custom state.
#[inline(always)]
#[must_use]
pub fn state_mut(&mut self) -> &mut Dynamic {
&mut self.state
}
/// Set the custom state.
#[inline(always)]
pub fn set_state(&mut self, state: impl Into<Dynamic>) {
self.state = state.into();
}
}
impl Engine {

View File

@@ -78,8 +78,6 @@ impl GlobalRuntimeState<'_> {
#[inline(always)]
#[must_use]
pub fn new(engine: &Engine) -> Self {
let _engine = engine;
Self {
#[cfg(not(feature = "no_module"))]
keys: crate::StaticVec::new_const(),
@@ -98,21 +96,21 @@ impl GlobalRuntimeState<'_> {
#[cfg(not(feature = "no_function"))]
constants: None,
#[cfg(not(feature = "debugging"))]
tag: Dynamic::UNIT,
#[cfg(feature = "debugging")]
tag: if let Some((ref init, ..)) = engine.debugger {
init()
} else {
Dynamic::UNIT
},
tag: engine.default_tag().clone(),
#[cfg(feature = "debugging")]
debugger: crate::eval::Debugger::new(if engine.debugger.is_some() {
crate::eval::DebuggerStatus::Init
} else {
crate::eval::DebuggerStatus::CONTINUE
}),
debugger: crate::eval::Debugger::new(
if engine.debugger.is_some() {
crate::eval::DebuggerStatus::Init
} else {
crate::eval::DebuggerStatus::CONTINUE
},
if let Some((ref init, ..)) = engine.debugger {
init()
} else {
Dynamic::UNIT
},
),
dummy: PhantomData::default(),
}