Move level into GlobalRuntimeState.

This commit is contained in:
Stephen Chung
2022-11-08 21:28:20 +08:00
parent 5bae4d8a19
commit e93923b3b6
21 changed files with 409 additions and 493 deletions

View File

@@ -414,14 +414,13 @@ impl Engine {
global: &mut GlobalRuntimeState,
caches: &mut Caches,
lib: &[SharedModule],
level: usize,
scope: &mut Scope,
this_ptr: &mut Dynamic,
node: impl Into<ASTNode<'a>>,
) -> RhaiResultOf<()> {
if self.debugger.is_some() {
if let Some(cmd) =
self.run_debugger_with_reset_raw(global, caches, lib, level, scope, this_ptr, node)?
self.run_debugger_with_reset_raw(global, caches, lib, scope, this_ptr, node)?
{
global.debugger.status = cmd;
}
@@ -441,13 +440,12 @@ impl Engine {
global: &mut GlobalRuntimeState,
caches: &mut Caches,
lib: &[SharedModule],
level: usize,
scope: &mut Scope,
this_ptr: &mut Dynamic,
node: impl Into<ASTNode<'a>>,
) -> RhaiResultOf<Option<DebuggerStatus>> {
if self.debugger.is_some() {
self.run_debugger_with_reset_raw(global, caches, lib, level, scope, this_ptr, node)
self.run_debugger_with_reset_raw(global, caches, lib, scope, this_ptr, node)
} else {
Ok(None)
}
@@ -464,7 +462,6 @@ impl Engine {
global: &mut GlobalRuntimeState,
caches: &mut Caches,
lib: &[SharedModule],
level: usize,
scope: &mut Scope,
this_ptr: &mut Dynamic,
node: impl Into<ASTNode<'a>>,
@@ -497,7 +494,7 @@ impl Engine {
},
};
self.run_debugger_raw(global, caches, lib, level, scope, this_ptr, node, event)
self.run_debugger_raw(global, caches, lib, scope, this_ptr, node, event)
}
/// Run the debugger callback unconditionally.
///
@@ -511,7 +508,6 @@ impl Engine {
global: &mut GlobalRuntimeState,
caches: &mut Caches,
lib: &[SharedModule],
level: usize,
scope: &mut Scope,
this_ptr: &mut Dynamic,
node: ASTNode<'a>,
@@ -519,7 +515,7 @@ impl Engine {
) -> Result<Option<DebuggerStatus>, Box<crate::EvalAltResult>> {
let src = global.source_raw().cloned();
let src = src.as_ref().map(|s| s.as_str());
let context = crate::EvalContext::new(self, global, caches, lib, level, scope, this_ptr);
let context = crate::EvalContext::new(self, global, caches, lib, scope, this_ptr);
if let Some((.., ref on_debugger)) = self.debugger {
let command = on_debugger(context, event, node, src, node.position())?;
@@ -545,12 +541,12 @@ impl Engine {
// Bump a level if it is a function call
let level = match node {
ASTNode::Expr(Expr::FnCall(..)) | ASTNode::Stmt(Stmt::FnCall(..)) => {
level + 1
global.level + 1
}
ASTNode::Stmt(Stmt::Expr(e)) if matches!(**e, Expr::FnCall(..)) => {
level + 1
global.level + 1
}
_ => level,
_ => global.level,
};
global.debugger.status = DebuggerStatus::FunctionExit(level);
Ok(None)