Skip to content

Commit

Permalink
fix track caller on macros
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Sep 29, 2024
1 parent 2de7d3b commit dba17e9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion site/primitives.json
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@
"outputs": 0,
"modifier_args": 1,
"class": "Debug",
"description": "Debug print all the values currently on stack without popping them"
"description": "Preprocess and print all stack values without popping them"
},
"duplicate": {
"glyph": ".",
Expand Down
10 changes: 6 additions & 4 deletions src/compile/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl Compiler {
_ => None,
})
});
let flags = prelude.flags;

// Handle macro
let ident_margs = ident_modifier_args(&name);
Expand All @@ -66,7 +67,8 @@ impl Compiler {
),
);
}
let new_func = self.compile_words(binding.words, true)?;
let mut new_func = self.compile_words(binding.words, true)?;
new_func.flags |= flags;
let sig = match instrs_signature(&new_func.instrs) {
Ok(s) => {
if let Some(declared) = binding.signature {
Expand Down Expand Up @@ -127,7 +129,7 @@ impl Compiler {
self.code_macros.insert(local.index, mac);
return Ok(());
}
// Positional macro
// Index macro
match (ident_margs > 0, placeholder_count > 0) {
(true, true) | (false, false) => {}
(true, false) => {
Expand Down Expand Up @@ -216,7 +218,7 @@ impl Compiler {
self.add_error(
span.clone(),
"Recursive positional macro must have a \
signature declared after the ←",
signature declared after the ←",
);
}
}
Expand All @@ -226,13 +228,13 @@ impl Compiler {
hygenic: true,
sig: binding.signature.map(|s| s.value),
recursive,
flags,
};
self.index_macros.insert(local.index, mac);
return Ok(());
}

// A non-macro binding
let flags = prelude.flags;
let mut make_fn: Box<dyn FnOnce(_, _, &mut Compiler) -> _> = {
let name = name.clone();
Box::new(
Expand Down
1 change: 1 addition & 0 deletions src/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ struct IndexMacro {
sig: Option<Signature>,
hygenic: bool,
recursive: bool,
flags: FunctionFlags,
}

/// A code macro
Expand Down
6 changes: 5 additions & 1 deletion src/compile/modifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,12 @@ impl Compiler {
}
});
// Compile
let new_func = self.suppress_diagnostics(|comp| {
let mut new_func = self.suppress_diagnostics(|comp| {
comp.temp_scope(mac.names, macro_local, |comp| {
comp.compile_words(mac.words, true)
})
})?;
new_func.flags |= mac.flags;
// Add
let sig = self.sig_of(&new_func.instrs, &modified.modifier.span)?;
let mut func =
Expand Down Expand Up @@ -416,8 +417,10 @@ impl Compiler {
return Err(self.fatal_error(modified.modifier.span.clone(), message));
}

let span = self.add_span(modified.modifier.span.clone());
let env = &mut self.macro_env;
env.asm = self.asm.clone();
env.rt.call_stack.last_mut().unwrap().call_span = span;

// Run the macro function
if let Some(sigs) = op_sigs {
Expand Down Expand Up @@ -1795,6 +1798,7 @@ impl Compiler {
sig: None,
hygenic: false,
recursive: false,
flags: FunctionFlags::default(),
},
);
let local = LocalName {
Expand Down
4 changes: 2 additions & 2 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub(crate) struct Runtime {
/// The stack height at the start of each array currently being built
pub(crate) array_stack: Vec<usize>,
/// The call stack
call_stack: Vec<StackFrame>,
pub(crate) call_stack: Vec<StackFrame>,
/// The stack for tracking recursion points
recur_stack: Vec<usize>,
/// The fill stack
Expand Down Expand Up @@ -104,7 +104,7 @@ pub(crate) struct StackFrame {
pub(crate) sig: Signature,
track_caller: bool,
/// The span at which the function was called
call_span: usize,
pub(crate) call_span: usize,
/// The program counter for the function
pub(crate) pc: usize,
/// Additional spans for error reporting
Expand Down

0 comments on commit dba17e9

Please sign in to comment.