Use tag for debugger state.

This commit is contained in:
Stephen Chung
2022-05-03 21:55:01 +08:00
parent 4f74d2f96a
commit 516f5a82a0
4 changed files with 21 additions and 41 deletions

View File

@@ -249,8 +249,6 @@ impl fmt::Display for CallStackFrame {
pub struct Debugger {
/// The current status command.
pub(crate) status: DebuggerStatus,
/// The current state.
state: Dynamic,
/// The current set of break-points.
break_points: Vec<BreakPoint>,
/// The current function call stack.
@@ -258,37 +256,16 @@ pub struct Debugger {
}
impl Debugger {
/// Create a new [`Debugger`] based on an [`Engine`].
/// Create a new [`Debugger`].
#[inline(always)]
#[must_use]
pub fn new(engine: &Engine) -> Self {
pub fn new(status: DebuggerStatus) -> Self {
Self {
status: if engine.debugger.is_some() {
DebuggerStatus::Init
} else {
DebuggerStatus::CONTINUE
},
state: if let Some((ref init, ..)) = engine.debugger {
init()
} else {
Dynamic::UNIT
},
status,
break_points: Vec::new(),
call_stack: Vec::new(),
}
}
/// Get a reference to the current state.
#[inline(always)]
#[must_use]
pub fn state(&self) -> &Dynamic {
&self.state
}
/// Get a mutable reference to the current state.
#[inline(always)]
#[must_use]
pub fn state_mut(&mut self) -> &mut Dynamic {
&mut self.state
}
/// Get the current call stack.
#[inline(always)]
#[must_use]

View File

@@ -97,9 +97,23 @@ impl GlobalRuntimeState<'_> {
#[cfg(not(feature = "no_module"))]
#[cfg(not(feature = "no_function"))]
constants: None,
#[cfg(not(feature = "debugging"))]
tag: Dynamic::UNIT,
#[cfg(feature = "debugging")]
debugger: crate::eval::Debugger::new(_engine),
tag: if let Some((ref init, ..)) = engine.debugger {
init()
} else {
Dynamic::UNIT
},
#[cfg(feature = "debugging")]
debugger: crate::eval::Debugger::new(if engine.debugger.is_some() {
crate::eval::DebuggerStatus::Init
} else {
crate::eval::DebuggerStatus::CONTINUE
}),
dummy: PhantomData::default(),
}
}