diff --git a/CHANGELOG.md b/CHANGELOG.md index 404692e0..58c9de46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ Rhai Release Notes Version 1.5.0 ============= +This version adds a debugging interface, which can be used to integrate a debugger. + Bug fixes --------- diff --git a/src/ast/expr.rs b/src/ast/expr.rs index 1ec236d1..72dea97c 100644 --- a/src/ast/expr.rs +++ b/src/ast/expr.rs @@ -376,7 +376,11 @@ pub enum Expr { Option, Position, #[cfg(not(feature = "no_module"))] - Box<(Option, Option<(crate::module::Namespace, u64)>, Identifier)>, + Box<( + Option, + Option<(crate::module::Namespace, u64)>, + Identifier, + )>, #[cfg(feature = "no_module")] Box<(Option, (), Identifier)>, ), /// Property access - ((getter, hash), (setter, hash), prop) diff --git a/src/bin/rhai-dbg.rs b/src/bin/rhai-dbg.rs index 8a37d15c..9c81c202 100644 --- a/src/bin/rhai-dbg.rs +++ b/src/bin/rhai-dbg.rs @@ -1,3 +1,5 @@ +#![cfg(not(feature = "no_std"))] + #[cfg(feature = "debugging")] use rhai::{Dynamic, Engine, EvalAltResult, ImmutableString, Position, Scope}; @@ -83,6 +85,7 @@ fn print_debug_help() { println!("scope => print the scope"); println!("print => print all variables de-duplicated"); println!("print => print the current value of a variable"); + #[cfg(not(feature = "no_module"))] println!("imports => print all imported modules"); println!("node => print the current AST node"); println!("backtrace => print the current call-stack"); @@ -162,8 +165,6 @@ fn main() { let mut script = String::new(); let main_ast; - #[cfg(not(feature = "no_module"))] - #[cfg(not(feature = "no_std"))] { // Load init scripts if let Some(filename) = env::args().skip(1).next() { @@ -303,6 +304,7 @@ fn main() { } } ["print", ..] => print_scope(context.scope(), true), + #[cfg(not(feature = "no_module"))] ["imports", ..] => { for (i, (name, module)) in context .global_runtime_state() diff --git a/src/eval/eval_context.rs b/src/eval/eval_context.rs index fd2a9c78..2191bb44 100644 --- a/src/eval/eval_context.rs +++ b/src/eval/eval_context.rs @@ -62,7 +62,6 @@ impl<'x, 'px, 'm, 'pm, 'pt> EvalContext<'_, 'x, 'px, 'm, 'pm, '_, '_, '_, '_, 'p /// _(internals)_ The current [`GlobalRuntimeState`]. /// Exported under the `internals` feature only. #[cfg(feature = "internals")] - #[cfg(not(feature = "no_module"))] #[inline(always)] #[must_use] pub const fn global_runtime_state(&self) -> &GlobalRuntimeState { @@ -71,7 +70,6 @@ impl<'x, 'px, 'm, 'pm, 'pt> EvalContext<'_, 'x, 'px, 'm, 'pm, '_, '_, '_, '_, 'p /// _(internals)_ Get a mutable reference to the current [`GlobalRuntimeState`]. /// Exported under the `internals` feature only. #[cfg(feature = "internals")] - #[cfg(not(feature = "no_module"))] #[inline(always)] #[must_use] pub fn global_runtime_state_mut(&mut self) -> &mut &'m mut GlobalRuntimeState<'pm> { diff --git a/src/eval/stmt.rs b/src/eval/stmt.rs index 0ccfbd6f..a5dd2da4 100644 --- a/src/eval/stmt.rs +++ b/src/eval/stmt.rs @@ -580,22 +580,14 @@ impl Engine { let func = self .global_modules .iter() - .find_map(|m| m.get_iter(iter_type)) - .or_else(|| { - #[cfg(not(feature = "no_module"))] - return global.get_iter(iter_type); - #[cfg(feature = "no_module")] - return None; - }) - .or_else(|| { - #[cfg(not(feature = "no_module"))] - return self - .global_sub_modules - .values() - .find_map(|m| m.get_qualified_iter(iter_type)); - #[cfg(feature = "no_module")] - return None; - }); + .find_map(|m| m.get_iter(iter_type)); + + #[cfg(not(feature = "no_module"))] + let func = func.or_else(|| global.get_iter(iter_type)).or_else(|| { + self.global_sub_modules + .values() + .find_map(|m| m.get_qualified_iter(iter_type)) + }); if let Some(func) = func { // Add the loop variables diff --git a/src/func/call.rs b/src/func/call.rs index 5b57e0bb..f7c45e27 100644 --- a/src/func/call.rs +++ b/src/func/call.rs @@ -241,31 +241,28 @@ impl Engine { source: m.id_raw().clone(), }) }) - }) + }); + + #[cfg(not(feature = "no_module"))] + let func = func .or_else(|| { - #[cfg(not(feature = "no_module"))] - return _global.get_qualified_fn(hash).map(|(func, source)| { + _global.get_qualified_fn(hash).map(|(func, source)| { FnResolutionCacheEntry { func: func.clone(), source: source .map_or_else(|| Identifier::new_const(), Into::into), } - }); - #[cfg(feature = "no_module")] - return None; + }) }) .or_else(|| { - #[cfg(not(feature = "no_module"))] - return self.global_sub_modules.values().find_map(|m| { + self.global_sub_modules.values().find_map(|m| { m.get_qualified_fn(hash).cloned().map(|func| { FnResolutionCacheEntry { func, source: m.id_raw().clone(), } }) - }); - #[cfg(feature = "no_module")] - return None; + }) }); match func {