diff --git a/rust/ares/src/interpreter.rs b/rust/ares/src/interpreter.rs index 250aa96..c250d88 100644 --- a/rust/ares/src/interpreter.rs +++ b/rust/ares/src/interpreter.rs @@ -1,6 +1,7 @@ use crate::assert_acyclic; use crate::assert_no_forwarding_pointers; use crate::assert_no_junior_pointers; +use crate::flog; use crate::guard::call_with_guard; use crate::hamt::Hamt; use crate::jets::cold; @@ -390,7 +391,7 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res *(context.stack.push()) = NockWork::Done; }; - // DO NOT REMOVE THIS ASSERTION + // DO NOT REMOVE THIS COMMENT // // If you need to allocate for debugging, wrap the debugging code in // @@ -1339,8 +1340,11 @@ unsafe fn write_trace(context: &mut Context) { // Abort writing to trace file if we encountered an error. This should // result in a well-formed partial trace file. if let Err(_e) = write_nock_trace(&mut context.stack, info, trace_stack) { - // XX: need NockStack allocated string interpolation - // eprintln!("\rserf: error writing nock trace to file: {:?}", e); + flog!( + context, + "\rserf: error writing nock trace to file: {:?}", + _e + ); context.trace_info = None; } } @@ -1387,7 +1391,7 @@ mod hint { // XX: what is the head here? let jet_name = jet_formula.tail(); - if let Some(jet) = jets::get_jet(jet_name) { + if let Some(jet) = jets::get_jet(context, jet_name) { match jet(context, subject) { Ok(mut jet_res) => { // XX: simplify this by moving jet test mode into the 11 code in interpret, or into its own function? diff --git a/rust/ares/src/jets.rs b/rust/ares/src/jets.rs index 9d1a97d..f9ebe3c 100644 --- a/rust/ares/src/jets.rs +++ b/rust/ares/src/jets.rs @@ -15,6 +15,7 @@ pub mod serial; pub mod sort; pub mod tree; +use crate::flog; use crate::interpreter::{Context, Error, Mote}; use crate::jets::bits::*; use crate::jets::cold::Cold; @@ -96,7 +97,7 @@ impl From for Error { } } -pub fn get_jet(jet_name: Noun) -> Option { +pub fn get_jet(context: &mut Context, jet_name: Noun) -> Option { match jet_name.as_direct().ok()?.data() { tas!(b"add") => Some(jet_add), tas!(b"dec") => Some(jet_dec), @@ -166,8 +167,7 @@ pub fn get_jet(jet_name: Noun) -> Option { tas!(b"sivc_de") => Some(jet_sivc_de), // _ => { - // XX: need NockStack allocated string interpolation - // eprintln!("Unknown jet: {:?}", jet_name); + flog!(context, "unknown jet: {:?}", jet_name); None } } diff --git a/rust/ares/src/serf.rs b/rust/ares/src/serf.rs index 1f4aecc..9a94596 100644 --- a/rust/ares/src/serf.rs +++ b/rust/ares/src/serf.rs @@ -332,6 +332,8 @@ pub fn serf(constant_hot_state: &[HotEntry]) -> io::Result<()> { if let Some(ref mut info) = trace_info.as_mut() { if let Err(_e) = write_metadata(info) { // XX: need NockStack allocated string interpolation + // XX: chicken/egg problem with flog bc it requires context + // before we've initialized it, and context needs trace_info // eprintln!("\rError initializing trace file: {:?}", e); trace_info = None; } @@ -411,7 +413,7 @@ fn peek(context: &mut Context, ovo: Noun) -> Noun { let trace_name = "peek"; let start = Instant::now(); let slam_res = slam(context, PEEK_AXIS, ovo); - write_serf_trace_safe(&mut context.nock_context.trace_info, trace_name, start); + write_serf_trace_safe(&mut context.nock_context, trace_name, start); slam_res.expect("peek error handling unimplemented") } else { @@ -436,7 +438,7 @@ fn soft(context: &mut Context, ovo: Noun, trace_name: Option) -> Result< let start = Instant::now(); let slam_res = slam(context, POKE_AXIS, ovo); write_serf_trace_safe( - &mut context.nock_context.trace_info, + &mut context.nock_context, trace_name.as_ref().unwrap(), start, ); @@ -467,7 +469,7 @@ fn play_life(context: &mut Context, eve: Noun) { let trace_name = "boot"; let start = Instant::now(); let boot_res = interpret(&mut context.nock_context, eve, lyf); - write_serf_trace_safe(&mut context.nock_context.trace_info, trace_name, start); + write_serf_trace_safe(&mut context.nock_context, trace_name, start); boot_res } else { diff --git a/rust/ares/src/trace.rs b/rust/ares/src/trace.rs index 3a4fe04..50bc013 100644 --- a/rust/ares/src/trace.rs +++ b/rust/ares/src/trace.rs @@ -1,3 +1,5 @@ +use crate::flog; +use crate::interpreter::Context; use crate::jets::bits::util::rap; use crate::jets::form::util::scow; use crate::mem::NockStack; @@ -97,11 +99,14 @@ pub fn write_metadata(info: &mut TraceInfo) -> Result<(), Error> { /// Abort writing to trace file if an error is encountered. /// /// This should result in a well-formed partial trace file. -pub fn write_serf_trace_safe(info: &mut Option, name: &str, start: Instant) { - if let Err(_e) = write_serf_trace(info.as_mut().unwrap(), name, start) { - // XX: need NockStack allocated string interpolation - // eprintln!("\rserf: error writing event trace to file: {:?}", e); - *info = None; +pub fn write_serf_trace_safe(context: &mut Context, name: &str, start: Instant) { + if let Err(e) = write_serf_trace(context.trace_info.as_mut().unwrap(), name, start) { + flog!( + context, + "\rserf: error writing event trace to file: {:?}", + e + ); + *(&mut context.trace_info) = None; } }