feat(core): INCLUDE, error overhaul, sf64 lane, WORDS ALL, .RS
WS-012 -- INCLUDE/INCLUDED:
- Injected source loader (core stays IO-free: CLI installs a
filesystem reader, web leaves it unset -> defined error). Recursive
include_file feeds files line-by-line through evaluate, so compile
state and SEE capture span lines for free. Cycle detection, depth
cap 16, paths relative to the including file, SOURCE-ID per nesting
level, parent input restored on success/error/BYE.
- CLI file mode now runs through the include machinery: `wafer x.fth`
gets file:line error context and a base dir for nested INCLUDEs.
- Unlocks the REMEMBER+INCLUDE reload loop.
WS-008 -- error reporting remainder:
- Errors inside included files carry `file.fth:12:` context
(anyhow context chain; CLI prints {e:#}).
- describe_uncaught now returns typed WaferError::UncaughtThrow
{ code, message } -- display text unchanged, THROW code reachable
via downcast for CLI/web consumers.
- compile_word emits a WASM name section; wasmtime trap backtraces
name the faulting word and runtime_native prefixes "in <WORD>:".
Batch/consolidated modules stay unnamed (no name plumbing there;
boot primitives rarely trap).
WS-003 -- SwiftForth correctness lane:
- compare_all_programs_sf64 runs the program corpus with sf64 as
oracle; whitespace-token comparison (sf64 prints numbers
space-prefixed and echoes piped lines). 34/35 parity; dot-quote
skipped (interpret-mode ." is a SwiftForth no-op). #[ignore]d like
the gforth lane; `just compare-correctness` runs both.
WS-011 leftovers:
- WORDS ALL: grouped full view -- one section per wordlist (search
order first), then internal words, each with counts. Backed by
Dictionary::visible_entries (name, wid, internal); visible_words
now derives from it.
- .RS / RDEPTH: return-stack introspection in boot.fth over a new
RP@ primitive (IrOp::RpFetch); BEGIN/WHILE walk so the walk never
touches the stack it prints. SPACES clamped per 6.1.2230.
549 unit + 11 compliance + 9(+2) comparison + 5 crypto + 1 bench
green; fmt/clippy clean; --no-default-features and wasm32 web checks
pass.
This commit is contained in:
@@ -899,6 +899,15 @@ fn emit_op(f: &mut Function, op: &IrOp, ctx: &mut EmitCtx) {
|
||||
.instruction(&Instruction::I32Store(MEM4));
|
||||
}
|
||||
|
||||
IrOp::RpFetch => {
|
||||
// Push the current return-stack pointer onto the data stack.
|
||||
// `$rsp` lives in a global (not cached), so no writeback needed.
|
||||
dsp_dec(f);
|
||||
f.instruction(&Instruction::LocalGet(CACHED_DSP_LOCAL))
|
||||
.instruction(&Instruction::GlobalGet(RSP))
|
||||
.instruction(&Instruction::I32Store(MEM4));
|
||||
}
|
||||
|
||||
// -- Compound operations -----------------------------------------------
|
||||
IrOp::TwoDup => {
|
||||
// ( a b -- a b a b )
|
||||
@@ -1242,7 +1251,9 @@ fn is_promotable(ops: &[IrOp]) -> bool {
|
||||
fn is_promotable_body(ops: &[IrOp]) -> bool {
|
||||
for op in ops {
|
||||
match op {
|
||||
IrOp::Call(_) | IrOp::TailCall(_) | IrOp::Execute | IrOp::SpFetch => return false,
|
||||
IrOp::Call(_) | IrOp::TailCall(_) | IrOp::Execute | IrOp::SpFetch | IrOp::RpFetch => {
|
||||
return false;
|
||||
}
|
||||
IrOp::ToR | IrOp::FromR | IrOp::Exit => return false,
|
||||
IrOp::ForthLocalGet(_) | IrOp::ForthLocalSet(_) => return false,
|
||||
IrOp::ForthFLocalGet(_) | IrOp::ForthFLocalSet(_) => return false,
|
||||
@@ -2306,6 +2317,9 @@ fn body_needs_return_stack(ops: &[IrOp]) -> bool {
|
||||
match op {
|
||||
IrOp::Call(_) | IrOp::TailCall(_) | IrOp::Execute => return true,
|
||||
IrOp::ToR | IrOp::FromR => return true,
|
||||
// RP@ observes the return stack, so loop params must be there
|
||||
// (otherwise inlined RDEPTH/.RS would report an empty stack).
|
||||
IrOp::RpFetch => return true,
|
||||
// RFetch (I) is handled by loop locals in the fast path — not a problem.
|
||||
// LoopJ is also handled by loop locals.
|
||||
// Only explicit >R / R> / calls force the slow path.
|
||||
@@ -2518,7 +2532,7 @@ fn count_forth_f_locals(ops: &[IrOp]) -> u32 {
|
||||
/// This is the JIT path: each word gets its own module that imports
|
||||
/// shared memory, globals, and function table from the host.
|
||||
pub fn compile_word(
|
||||
_name: &str,
|
||||
name: &str,
|
||||
body: &[IrOp],
|
||||
config: &CodegenConfig,
|
||||
) -> WaferResult<CompiledModule> {
|
||||
@@ -2685,6 +2699,16 @@ pub fn compile_word(
|
||||
code.function(&func);
|
||||
module.section(&code);
|
||||
|
||||
// -- Name section: carries the Forth word name into wasmtime trap
|
||||
// backtraces (best-effort symbolication, WS-008).
|
||||
let mut names = wasm_encoder::NameSection::new();
|
||||
names.module(name);
|
||||
let mut fn_names = wasm_encoder::NameMap::new();
|
||||
fn_names.append(0, "emit");
|
||||
fn_names.append(WORD_FUNC, name);
|
||||
names.functions(&fn_names);
|
||||
module.section(&names);
|
||||
|
||||
let bytes = module.finish();
|
||||
|
||||
// Validate
|
||||
|
||||
Reference in New Issue
Block a user