Support call stack and FunctionExit for native functions.

This commit is contained in:
Stephen Chung
2022-02-02 14:47:35 +08:00
parent 7163a7331a
commit 4a80483749
13 changed files with 190 additions and 77 deletions

View File

@@ -220,6 +220,7 @@ impl Engine {
Ok(ref mut obj_ptr) => {
self.eval_op_assignment(
global, state, lib, op_info, op_pos, obj_ptr, root, new_val,
level,
)
.map_err(|err| err.fill_position(new_pos))?;
#[cfg(not(feature = "unchecked"))]
@@ -314,6 +315,7 @@ impl Engine {
)?;
self.eval_op_assignment(
global, state, lib, op_info, op_pos, val_target, root, new_val,
level,
)
.map_err(|err| err.fill_position(new_pos))?;
}
@@ -380,6 +382,7 @@ impl Engine {
&mut (&mut orig_val).into(),
root,
new_val,
level,
)
.map_err(|err| err.fill_position(new_pos))?;

View File

@@ -346,13 +346,15 @@ impl Debugger {
node.position() == *pos && _src == source
}
BreakPoint::AtFunctionName { name, .. } => match node {
ASTNode::Expr(Expr::FnCall(x, _)) | ASTNode::Stmt(Stmt::FnCall(x, _)) => {
x.name == *name
}
ASTNode::Expr(Expr::FnCall(x, _))
| ASTNode::Stmt(Stmt::FnCall(x, _))
| ASTNode::Stmt(Stmt::Expr(Expr::FnCall(x, _))) => x.name == *name,
_ => false,
},
BreakPoint::AtFunctionCall { name, args, .. } => match node {
ASTNode::Expr(Expr::FnCall(x, _)) | ASTNode::Stmt(Stmt::FnCall(x, _)) => {
ASTNode::Expr(Expr::FnCall(x, _))
| ASTNode::Stmt(Stmt::FnCall(x, _))
| ASTNode::Stmt(Stmt::Expr(Expr::FnCall(x, _))) => {
x.args.len() == *args && x.name == *name
}
_ => false,
@@ -503,7 +505,14 @@ impl Engine {
Ok(None)
}
DebuggerCommand::FunctionExit => {
global.debugger.status = DebuggerStatus::FunctionExit(context.call_level());
// Bump a level if it is a function call
let level = match node {
ASTNode::Expr(Expr::FnCall(_, _))
| ASTNode::Stmt(Stmt::FnCall(_, _))
| ASTNode::Stmt(Stmt::Expr(Expr::FnCall(_, _))) => context.call_level() + 1,
_ => context.call_level(),
};
global.debugger.status = DebuggerStatus::FunctionExit(level);
Ok(None)
}
}

View File

@@ -353,6 +353,7 @@ impl Engine {
&mut (&mut concat).into(),
("", Position::NONE),
item,
level,
) {
result = Err(err.fill_position(expr.position()));
break;

View File

@@ -120,6 +120,7 @@ impl Engine {
target: &mut Target,
root: (&str, Position),
new_val: Dynamic,
level: usize,
) -> RhaiResultOf<()> {
if target.is_read_only() {
// Assignment to constant variable
@@ -154,7 +155,7 @@ impl Engine {
let args = &mut [lhs_ptr_inner, &mut new_val];
match self.call_native_fn(
global, state, lib, op_assign, hash, args, true, true, op_pos,
global, state, lib, op_assign, hash, args, true, true, op_pos, level,
) {
Ok(_) => {
#[cfg(not(feature = "unchecked"))]
@@ -164,7 +165,7 @@ impl Engine {
{
// Expand to `var = var op rhs`
let (value, _) = self.call_native_fn(
global, state, lib, op, hash_op, args, true, false, op_pos,
global, state, lib, op, hash_op, args, true, false, op_pos, level,
)?;
#[cfg(not(feature = "unchecked"))]
@@ -266,6 +267,7 @@ impl Engine {
&mut lhs_ptr,
(var_name, pos),
rhs_val,
level,
)
.map_err(|err| err.fill_position(rhs.position()))
.map(|_| Dynamic::UNIT)