From 18c9a795bf2a49532e5b51692a1ec63007182653 Mon Sep 17 00:00:00 2001 From: John-John Tedro Date: Fri, 16 Feb 2024 23:21:20 +0100 Subject: [PATCH] Fix debugger and some tests --- crates/rune/src/cli/run.rs | 42 +++++++++++++++++++++------------ crates/rune/src/modules/core.rs | 2 ++ crates/rune/src/modules/iter.rs | 4 +++- crates/rune/src/runtime/vm.rs | 2 +- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/crates/rune/src/cli/run.rs b/crates/rune/src/cli/run.rs index 454ac3e13..6c487a2ce 100644 --- a/crates/rune/src/cli/run.rs +++ b/crates/rune/src/cli/run.rs @@ -273,9 +273,13 @@ pub(super) async fn run( writeln!(io.stdout, " *empty*")?; } - for (n, value) in stack.iter().enumerate() { - writeln!(io.stdout, "{}+{} = {:?}", frame.stack_bottom, n, value)?; - } + vm.with(|| { + for (n, value) in stack.iter().enumerate() { + writeln!(io.stdout, "{}+{} = {:?}", frame.stack_bottom, n, value)?; + } + + Ok::<_, crate::support::Error>(()) + })?; } // NB: print final frame @@ -292,15 +296,19 @@ pub(super) async fn run( writeln!(io.stdout, " *empty*")?; } - for (n, value) in values.iter().enumerate() { - writeln!( - io.stdout, - " {}+{} = {:?}", - stack.stack_bottom(), - n, - value - )?; - } + vm.with(|| { + for (n, value) in values.iter().enumerate() { + writeln!( + io.stdout, + " {}+{} = {:?}", + stack.stack_bottom(), + n, + value + )?; + } + + Ok::<_, crate::support::Error>(()) + })?; } if let Some(error) = errored { @@ -402,9 +410,13 @@ where writeln!(o, " *empty*")?; } - for (n, value) in values.iter().enumerate() { - writeln!(o, " {}+{} = {:?}", stack.stack_bottom(), n, value)?; - } + vm.with(|| { + for (n, value) in values.iter().enumerate() { + writeln!(o, " {}+{} = {:?}", stack.stack_bottom(), n, value)?; + } + + Ok::<_, TraceError>(()) + })?; } if let Some(result) = result { diff --git a/crates/rune/src/modules/core.rs b/crates/rune/src/modules/core.rs index ef25e2ebf..cf8dad06b 100644 --- a/crates/rune/src/modules/core.rs +++ b/crates/rune/src/modules/core.rs @@ -55,6 +55,7 @@ fn panic(message: &str) -> VmResult<()> { /// let value = Some(42); /// assert!(is_readable(value)); /// let value2 = value.map(|v| v + 1); +/// drop(value); /// assert!(!is_readable(value)); /// assert_eq!(value2, Some(43)); /// ``` @@ -74,6 +75,7 @@ fn is_readable(value: Value) -> bool { /// let value = Some(42); /// assert!(is_writable(value)); /// let value2 = value.map(|v| v + 1); +/// drop(value); /// assert!(!is_writable(value)); /// assert_eq!(value2, Some(43)); /// ``` diff --git a/crates/rune/src/modules/iter.rs b/crates/rune/src/modules/iter.rs index c903266f8..50de9cc9a 100644 --- a/crates/rune/src/modules/iter.rs +++ b/crates/rune/src/modules/iter.rs @@ -1,5 +1,7 @@ //! The `std::iter` module. +use core::convert::identity; + use crate as rune; use crate::alloc::String; use crate::modules::collections::VecDeque; @@ -43,7 +45,7 @@ pub fn module() -> Result { module.function_meta(take)?; module.function_meta(count)?; module.associated_function(Protocol::NEXT, Iterator::next)?; - module.associated_function(Protocol::INTO_ITER, >::from)?; + module.associated_function(Protocol::INTO_ITER, identity::)?; module.function_meta(range)?; module.function_meta(empty)?; diff --git a/crates/rune/src/runtime/vm.rs b/crates/rune/src/runtime/vm.rs index 26a1e0f77..64bf0b5b8 100644 --- a/crates/rune/src/runtime/vm.rs +++ b/crates/rune/src/runtime/vm.rs @@ -2957,7 +2957,7 @@ impl Vm { /// vm.with(|| output.string_display(&mut f)).into_result()?; /// # Ok::<_, rune::support::Error>(()) /// ``` - pub fn with(&mut self, f: F) -> T + pub fn with(&self, f: F) -> T where F: FnOnce() -> T, {