Skip to content

Commit

Permalink
debug: use flog! macro instead of eprintln! sometimes
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-levan committed Mar 15, 2024
1 parent 439657f commit ef90c78
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
12 changes: 8 additions & 4 deletions rust/ares/src/interpreter.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
//
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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?
Expand Down
6 changes: 3 additions & 3 deletions rust/ares/src/jets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -96,7 +97,7 @@ impl From<JetErr> for Error {
}
}

pub fn get_jet(jet_name: Noun) -> Option<Jet> {
pub fn get_jet(context: &mut Context, jet_name: Noun) -> Option<Jet> {
match jet_name.as_direct().ok()?.data() {
tas!(b"add") => Some(jet_add),
tas!(b"dec") => Some(jet_dec),
Expand Down Expand Up @@ -166,8 +167,7 @@ pub fn get_jet(jet_name: Noun) -> Option<Jet> {
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
}
}
Expand Down
8 changes: 5 additions & 3 deletions rust/ares/src/serf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand All @@ -436,7 +438,7 @@ fn soft(context: &mut Context, ovo: Noun, trace_name: Option<String>) -> 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,
);
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 10 additions & 5 deletions rust/ares/src/trace.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<TraceInfo>, 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;
}
}

Expand Down

0 comments on commit ef90c78

Please sign in to comment.