Add debug mode and VM tracing

Introduce a `debug_mode` flag to the `Environment` and a new `run_debug`
method. This method uses a `TracingObserver` to log the VM's execution
flow, including node evaluation and scope state changes. This allows for
detailed inspection of script execution.

The `BoundKind` enum now also includes a `display_name` method for
better log readability.
This commit is contained in:
Michael Schimmel
2026-02-18 00:56:29 +01:00
parent 25e3bc1d01
commit faada16723
5 changed files with 212 additions and 30 deletions
+27
View File
@@ -120,4 +120,31 @@ mod tests {
}
}
}
#[test]
fn test_debug_mode_logging() {
let env = Environment::new();
let source = "(+ 10 20)";
let result = env.run_debug(source).expect("Failed to run debug");
let (val, logs) = result;
// 1. Check value
match val {
Ok(Value::Int(30)) => (),
_ => panic!("Expected Int(30), got {:?}", val),
}
// 2. Check logs (should have entries for + and constants)
assert!(!logs.is_empty(), "Logs should not be empty");
// Look for typical trace patterns
let has_call = logs.iter().any(|l| l.contains("CALL"));
let has_const = logs.iter().any(|l| l.contains("CONST(10)"));
let has_result = logs.iter().any(|l| l.contains("} -> 30"));
assert!(has_call, "Logs should contain CALL");
assert!(has_const, "Logs should contain CONST(10)");
assert!(has_result, "Logs should contain result 30");
}
}