diff --git a/src/bin/rhai-dbg.rs b/src/bin/rhai-dbg.rs index 18ab359c..e44cc073 100644 --- a/src/bin/rhai-dbg.rs +++ b/src/bin/rhai-dbg.rs @@ -221,6 +221,7 @@ fn main() { [""] | ["step", ..] => break DebuggerCommand::StepInto, ["next", ..] => break DebuggerCommand::StepOver, ["scope", ..] => print_scope(context.scope()), + #[cfg(not(feature = "no_function"))] ["backtrace", ..] => { context .global_runtime_state() diff --git a/src/eval/debugger.rs b/src/eval/debugger.rs index 1f95aefd..7a4f52b9 100644 --- a/src/eval/debugger.rs +++ b/src/eval/debugger.rs @@ -3,7 +3,7 @@ use super::{EvalContext, EvalState, GlobalRuntimeState}; use crate::ast::{ASTNode, Expr, Stmt}; -use crate::{Dynamic, Engine, Identifier, Module, Position, Scope, StaticVec}; +use crate::{Dynamic, Engine, Identifier, Module, Position, Scope}; use std::fmt; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -75,14 +75,16 @@ impl fmt::Display for BreakPoint { } /// A function call. +#[cfg(not(feature = "no_function"))] #[derive(Debug, Clone, Hash)] pub struct CallStackFrame { pub fn_name: Identifier, - pub args: StaticVec, + pub args: crate::StaticVec, pub source: Identifier, pub pos: Position, } +#[cfg(not(feature = "no_function"))] impl fmt::Display for CallStackFrame { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut fp = f.debug_tuple(&self.fn_name); @@ -110,6 +112,7 @@ impl fmt::Display for CallStackFrame { pub struct Debugger { status: DebuggerCommand, break_points: Vec, + #[cfg(not(feature = "no_function"))] call_stack: Vec, } @@ -119,30 +122,35 @@ impl Debugger { Self { status: DebuggerCommand::Continue, break_points: Vec::new(), + #[cfg(not(feature = "no_function"))] call_stack: Vec::new(), } } /// Get the function call stack depth. + #[cfg(not(feature = "no_function"))] #[inline(always)] pub fn call_stack_len(&self) -> usize { self.call_stack.len() } /// Get the current call stack. + #[cfg(not(feature = "no_function"))] #[inline(always)] pub fn call_stack(&self) -> &[CallStackFrame] { &self.call_stack } /// Rewind the function call stack to a particular depth. + #[cfg(not(feature = "no_function"))] #[inline(always)] pub(crate) fn rewind_call_stack(&mut self, len: usize) { self.call_stack.truncate(len); } /// Add a new frame to the function call stack. + #[cfg(not(feature = "no_function"))] #[inline(always)] pub(crate) fn push_call_stack_frame( &mut self, fn_name: impl Into, - args: StaticVec, + args: crate::StaticVec, source: impl Into, pos: Position, ) { diff --git a/src/eval/mod.rs b/src/eval/mod.rs index 99cf5938..dcbfcc9d 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -11,7 +11,10 @@ mod target; #[cfg(any(not(feature = "no_index"), not(feature = "no_object")))] pub use chaining::{ChainArgument, ChainType}; #[cfg(feature = "debugging")] -pub use debugger::{BreakPoint, CallStackFrame, Debugger, DebuggerCommand, OnDebuggerCallback}; +#[cfg(not(feature = "no_function"))] +pub use debugger::CallStackFrame; +#[cfg(feature = "debugging")] +pub use debugger::{BreakPoint, Debugger, DebuggerCommand, OnDebuggerCallback}; pub use eval_context::EvalContext; pub use eval_state::EvalState; pub use global_state::GlobalRuntimeState; diff --git a/src/eval/stmt.rs b/src/eval/stmt.rs index 62bb62c2..6542c58e 100644 --- a/src/eval/stmt.rs +++ b/src/eval/stmt.rs @@ -712,17 +712,15 @@ impl Engine { err_map.insert("source".into(), global.source.clone().into()); } - if err_pos.is_none() { - // No position info - } else { - let line = err_pos.line().unwrap() as INT; - let position = if err_pos.is_beginning_of_line() { - 0 - } else { - err_pos.position().unwrap() - } as INT; - err_map.insert("line".into(), line.into()); - err_map.insert("position".into(), position.into()); + if !err_pos.is_none() { + err_map.insert( + "line".into(), + (err_pos.line().unwrap() as INT).into(), + ); + err_map.insert( + "position".into(), + (err_pos.position().unwrap_or(0) as INT).into(), + ); } err.dump_fields(&mut err_map); diff --git a/src/func/script.rs b/src/func/script.rs index 48ca4cf7..11875836 100644 --- a/src/func/script.rs +++ b/src/func/script.rs @@ -71,7 +71,9 @@ impl Engine { let orig_scope_len = scope.len(); let orig_imports_len = global.num_imports(); + #[cfg(feature = "debugging")] + #[cfg(not(feature = "no_function"))] let orig_call_stack_len = global.debugger.call_stack_len(); // Put arguments into scope as variables @@ -82,6 +84,7 @@ impl Engine { // Push a new call stack frame #[cfg(feature = "debugging")] + #[cfg(not(feature = "no_function"))] global.debugger.push_call_stack_frame( fn_def.name.clone(), scope @@ -166,6 +169,7 @@ impl Engine { // Pop the call stack #[cfg(feature = "debugging")] + #[cfg(not(feature = "no_function"))] global.debugger.rewind_call_stack(orig_call_stack_len); result diff --git a/src/lib.rs b/src/lib.rs index 3e5c8acc..f28252a9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -160,7 +160,9 @@ pub use types::{ /// Exported under the `debugging` feature only. #[cfg(feature = "debugging")] pub mod debugger { - pub use super::eval::{BreakPoint, CallStackFrame, Debugger, DebuggerCommand}; + #[cfg(not(feature = "no_function"))] + pub use super::eval::CallStackFrame; + pub use super::eval::{BreakPoint, Debugger, DebuggerCommand}; } /// An identifier in Rhai. [`SmartString`](https://crates.io/crates/smartstring) is used because most