feat(repl): usability batch - errors, WORDS, .S, BYE, DUMP, history
Core:
- Uncaught THROW prints its standard message ("Stack underflow
(throw -4)"; unknown codes as "Catch = <n>") instead of the
"forth-throw" sentinel. ABORT" text is carried as a structured
payload and shown only when the -2 throw goes uncaught -- CATCH
stays silent and the payload cannot go stale. ABORT throws -1
through the same path.
- WORDS: optional same-line substring filter (WORDS FDEPTH), skips
internal words (new INTERNAL header flag, set at create for
underscore-prefixed names), wraps at 78 columns, prints a count.
ORDER names wids (FORTH / wid#N) instead of Rust debug output.
- .S honors BASE. New: F.S (float stack), DUMP (hex+ASCII,
bounds-checked, 4K cap), ? (fetch-and-print, boot.fth). BYE is a
real word now: sets a VM flag the driver honors (exits REPL,
stops rest of line/file).
CLI:
- Persistent history (~/.local/state/wafer/history, 0600 perms,
$WAFER_HISTORY override), Tab completion over the live dictionary
(snapshot refreshed after each line), Up/Down do prefix history
search, Ctrl-C clears the line instead of exiting.
Web:
- History survives reloads (localStorage, cap 200, dedup, init-code
runs excluded), User Words palette populated via new words()
export, stack bar annotates non-decimal BASE, base() reads the
real BASE sysvar instead of returning a hardcoded 10.
This commit is contained in:
@@ -6,8 +6,9 @@ use send_wrapper::SendWrapper;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
use wafer_core::config::WaferConfig;
|
||||
use wafer_core::memory::{CELL_SIZE, PAD_BASE, PAD_SIZE};
|
||||
use wafer_core::memory::{CELL_SIZE, PAD_BASE, PAD_SIZE, SYSVAR_BASE_VAR};
|
||||
use wafer_core::outer::ForthVM;
|
||||
use wafer_core::runtime::Runtime;
|
||||
use wafer_core::runtime::{HostAccess, HostFn};
|
||||
|
||||
use crate::runtime_web::WebRuntime;
|
||||
@@ -53,9 +54,12 @@ impl WaferRepl {
|
||||
|
||||
/// Get the current number base (10 = decimal, 16 = hex).
|
||||
pub fn base(&mut self) -> u32 {
|
||||
// BASE is stored at SYSVAR_BASE_VAR in WASM memory
|
||||
self.vm.take_output(); // no-op side effect; just return base
|
||||
10 // TODO: read from memory once we have a getter
|
||||
self.vm.runtime_mut().mem_read_i32(SYSVAR_BASE_VAR) as u32
|
||||
}
|
||||
|
||||
/// Names of all user-facing words (visible, non-internal), newest first.
|
||||
pub fn words(&self) -> Vec<String> {
|
||||
self.vm.word_names()
|
||||
}
|
||||
|
||||
/// Reset the VM to initial state.
|
||||
|
||||
Reference in New Issue
Block a user