Reduce data sizes.

This commit is contained in:
Stephen Chung
2022-11-24 20:35:56 +08:00
parent 6c06481457
commit bda8c2b636
14 changed files with 264 additions and 191 deletions

View File

@@ -364,7 +364,10 @@ impl Engine {
// Push a new call stack frame
#[cfg(feature = "debugging")]
let orig_call_stack_len = global.debugger.call_stack().len();
let orig_call_stack_len = global
.debugger
.as_ref()
.map_or(0, |dbg| dbg.call_stack().len());
let backup = &mut ArgBackup::new();
@@ -381,10 +384,12 @@ impl Engine {
#[cfg(feature = "debugging")]
if self.debugger.is_some() {
global.debugger.push_call_stack_frame(
let source = source.clone().or_else(|| global.source.clone());
global.debugger_mut().push_call_stack_frame(
self.get_interned_string(name),
args.iter().map(|v| (*v).clone()).collect(),
source.clone().or_else(|| global.source.clone()),
source,
pos,
);
}
@@ -410,10 +415,10 @@ impl Engine {
};
#[cfg(feature = "debugging")]
{
if self.debugger.is_some() {
use crate::eval::{DebuggerEvent, DebuggerStatus};
let trigger = match global.debugger.status {
let trigger = match global.debugger().status {
DebuggerStatus::FunctionExit(n) => n >= global.level,
DebuggerStatus::Next(.., true) => true,
_ => false,
@@ -436,7 +441,7 @@ impl Engine {
}
// Pop the call stack
global.debugger.rewind_call_stack(orig_call_stack_len);
global.debugger_mut().rewind_call_stack(orig_call_stack_len);
}
let result = _result?;
@@ -714,11 +719,15 @@ impl Engine {
// Do not match function exit for arguments
#[cfg(feature = "debugging")]
let reset = global.debugger.clear_status_if(|status| {
matches!(status, crate::eval::DebuggerStatus::FunctionExit(..))
let reset = global.debugger.as_mut().and_then(|dbg| {
dbg.clear_status_if(|status| {
matches!(status, crate::eval::DebuggerStatus::FunctionExit(..))
})
});
#[cfg(feature = "debugging")]
let global = &mut *RestoreOnDrop::lock(global, move |g| g.debugger.reset_status(reset));
let global = &mut *RestoreOnDrop::lock_if(reset.is_some(), global, move |g| {
g.debugger_mut().reset_status(reset)
});
self.eval_expr(global, caches, scope, this_ptr, arg_expr)
.map(|r| (r, arg_expr.start_position()))

View File

@@ -83,7 +83,10 @@ impl Engine {
let orig_imports_len = global.num_imports();
#[cfg(feature = "debugging")]
let orig_call_stack_len = global.debugger.call_stack().len();
let orig_call_stack_len = global
.debugger
.as_ref()
.map_or(0, |dbg| dbg.call_stack().len());
// Put arguments into scope as variables
scope.extend(fn_def.params.iter().cloned().zip(args.iter_mut().map(|v| {
@@ -94,10 +97,12 @@ impl Engine {
// Push a new call stack frame
#[cfg(feature = "debugging")]
if self.debugger.is_some() {
global.debugger.push_call_stack_frame(
let source = global.source.clone();
global.debugger_mut().push_call_stack_frame(
fn_def.name.clone(),
scope.iter().skip(orig_scope_len).map(|(.., v)| v).collect(),
global.source.clone(),
source,
pos,
);
}
@@ -126,7 +131,7 @@ impl Engine {
};
#[cfg(feature = "debugging")]
{
if self.debugger.is_some() {
let node = crate::ast::Stmt::Noop(fn_def.body.position());
self.run_debugger(global, caches, scope, this_ptr, &node)?;
}
@@ -156,12 +161,13 @@ impl Engine {
});
#[cfg(feature = "debugging")]
{
let trigger = match global.debugger.status {
if self.debugger.is_some() {
let trigger = match global.debugger_mut().status {
crate::eval::DebuggerStatus::FunctionExit(n) => n >= global.level,
crate::eval::DebuggerStatus::Next(.., true) => true,
_ => false,
};
if trigger {
let node = crate::ast::Stmt::Noop(fn_def.body.end_position().or_else(pos));
let node = (&node).into();
@@ -176,7 +182,11 @@ impl Engine {
}
// Pop the call stack
global.debugger.rewind_call_stack(orig_call_stack_len);
global
.debugger
.as_mut()
.unwrap()
.rewind_call_stack(orig_call_stack_len);
}
// Remove all local variables and imported modules