Skip to content

Commit

Permalink
Fix debugger and some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Feb 16, 2024
1 parent 5ee7e13 commit 18c9a79
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
42 changes: 27 additions & 15 deletions crates/rune/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions crates/rune/src/modules/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
/// ```
Expand All @@ -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));
/// ```
Expand Down
4 changes: 3 additions & 1 deletion crates/rune/src/modules/iter.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -43,7 +45,7 @@ pub fn module() -> Result<Module, ContextError> {
module.function_meta(take)?;
module.function_meta(count)?;
module.associated_function(Protocol::NEXT, Iterator::next)?;
module.associated_function(Protocol::INTO_ITER, <Iterator as From<Iterator>>::from)?;
module.associated_function(Protocol::INTO_ITER, identity::<Iterator>)?;

module.function_meta(range)?;
module.function_meta(empty)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/rune/src/runtime/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2957,7 +2957,7 @@ impl Vm {
/// vm.with(|| output.string_display(&mut f)).into_result()?;
/// # Ok::<_, rune::support::Error>(())
/// ```
pub fn with<F, T>(&mut self, f: F) -> T
pub fn with<F, T>(&self, f: F) -> T
where
F: FnOnce() -> T,
{
Expand Down

0 comments on commit 18c9a79

Please sign in to comment.