9b1cc0cace
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.
92 lines
2.1 KiB
Rust
92 lines
2.1 KiB
Rust
//! Error types for the WAFER compiler and runtime.
|
|
|
|
use thiserror::Error;
|
|
|
|
/// Errors that can occur during WAFER compilation and execution.
|
|
#[derive(Debug, Error)]
|
|
pub enum WaferError {
|
|
#[error("stack underflow")]
|
|
StackUnderflow,
|
|
|
|
#[error("stack overflow")]
|
|
StackOverflow,
|
|
|
|
#[error("return stack underflow")]
|
|
ReturnStackUnderflow,
|
|
|
|
#[error("return stack overflow")]
|
|
ReturnStackOverflow,
|
|
|
|
#[error("float stack underflow")]
|
|
FloatStackUnderflow,
|
|
|
|
#[error("float stack overflow")]
|
|
FloatStackOverflow,
|
|
|
|
#[error("unknown word: {0}")]
|
|
UnknownWord(String),
|
|
|
|
#[error("division by zero")]
|
|
DivisionByZero,
|
|
|
|
#[error("invalid memory address: {0:#x}")]
|
|
InvalidAddress(u32),
|
|
|
|
#[error("dictionary overflow")]
|
|
DictionaryOverflow,
|
|
|
|
#[error("compilation error: {0}")]
|
|
CompileError(String),
|
|
|
|
#[error("invalid number: {0}")]
|
|
InvalidNumber(String),
|
|
|
|
#[error("word name too long: {0}")]
|
|
NameTooLong(String),
|
|
|
|
#[error("control structure mismatch: {0}")]
|
|
ControlMismatch(String),
|
|
|
|
#[error("WASM codegen error: {0}")]
|
|
CodegenError(String),
|
|
|
|
#[error("WASM validation error: {0}")]
|
|
ValidationError(String),
|
|
|
|
#[error("I/O error: {0}")]
|
|
IoError(String),
|
|
|
|
#[error("THROW code {0}")]
|
|
Throw(i32),
|
|
|
|
#[error("{0}")]
|
|
Abort(String),
|
|
|
|
/// An uncaught Forth THROW as reported to the user. `message` is the
|
|
/// full display text (standard message or ABORT" payload); `code`
|
|
/// carries the THROW code for typed consumers (CLI exit paths, web
|
|
/// REPL styling) via `Error::downcast_ref`.
|
|
#[error("{message}")]
|
|
UncaughtThrow { code: i32, message: String },
|
|
}
|
|
|
|
/// Result type alias for WAFER operations.
|
|
pub type WaferResult<T> = Result<T, WaferError>;
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn error_display() {
|
|
let err = WaferError::UnknownWord("FOO".to_string());
|
|
assert_eq!(err.to_string(), "unknown word: FOO");
|
|
}
|
|
|
|
#[test]
|
|
fn error_throw_code() {
|
|
let err = WaferError::Throw(-1);
|
|
assert_eq!(err.to_string(), "THROW code -1");
|
|
}
|
|
}
|