debug: use flog! macro instead of eprintln! sometimes

This commit is contained in:
Matthew LeVan 2024-03-15 08:51:36 -04:00
parent 439657f35f
commit ef90c78438
4 changed files with 26 additions and 15 deletions

View File

@ -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?

View File

@ -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<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),
@ -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
}
}

View File

@ -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<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,
);
@ -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 {

View File

@ -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<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;
}
}