Provide Position to debug.

This commit is contained in:
Stephen Chung
2020-12-12 11:47:18 +08:00
parent 5443368359
commit 40b6a014ae
7 changed files with 59 additions and 25 deletions

View File

@@ -4,7 +4,8 @@ use crate::ast::{Expr, FnCallExpr, Ident, IdentX, ReturnType, Stmt};
use crate::dynamic::{map_std_type_name, AccessMode, Union, Variant};
use crate::fn_call::run_builtin_op_assignment;
use crate::fn_native::{
CallableFunction, IteratorFn, OnPrintCallback, OnProgressCallback, OnVarCallback,
CallableFunction, IteratorFn, OnDebugCallback, OnPrintCallback, OnProgressCallback,
OnVarCallback,
};
use crate::module::NamespaceRef;
use crate::optimize::OptimizationLevel;
@@ -626,7 +627,7 @@ pub struct Engine {
/// Callback closure for implementing the `print` command.
pub(crate) print: OnPrintCallback,
/// Callback closure for implementing the `debug` command.
pub(crate) debug: OnPrintCallback,
pub(crate) debug: OnDebugCallback,
/// Callback closure for progress reporting.
pub(crate) progress: Option<OnProgressCallback>,
@@ -677,7 +678,7 @@ pub fn is_anonymous_fn(fn_name: &str) -> bool {
fn_name.starts_with(FN_ANONYMOUS)
}
/// Print/debug to stdout
/// Print to stdout
#[inline(always)]
fn default_print(_s: &str) {
#[cfg(not(feature = "no_std"))]
@@ -685,6 +686,14 @@ fn default_print(_s: &str) {
println!("{}", _s);
}
/// Debug to stdout
#[inline(always)]
fn default_debug(_s: &str, _pos: Position) {
#[cfg(not(feature = "no_std"))]
#[cfg(not(target_arch = "wasm32"))]
println!("{:?} | {}", _pos, _s);
}
/// Search for a module within an imports stack.
/// [`Position`] in [`EvalAltResult`] is [`None`][Position::None] and must be set afterwards.
pub fn search_imports(
@@ -741,7 +750,7 @@ impl Engine {
// default print/debug implementations
print: Box::new(default_print),
debug: Box::new(default_print),
debug: Box::new(default_debug),
// progress callback
progress: None,
@@ -797,7 +806,7 @@ impl Engine {
resolve_var: None,
print: Box::new(|_| {}),
debug: Box::new(|_| {}),
debug: Box::new(|_, _| {}),
progress: None,
optimization_level: if cfg!(feature = "no_optimize") {