Add PAGE word, fix web REPL init code, update deps

Implement PAGE (Facility word set) as IR primitive emitting form feed.
Web REPL clears output div on form feed, CLI REPL sends ANSI clear.
Fix init code panel: use default textarea content instead of placeholder
so init code actually executes on first visit. Update wasm-pack 0.10→0.14
and refresh Cargo.lock to latest compatible versions.
This commit is contained in:
2026-04-13 11:21:11 +02:00
parent 3b65b48640
commit 24e808935f
5 changed files with 51 additions and 28 deletions
+5
View File
@@ -312,6 +312,11 @@ fn cmd_eval_or_repl(file: Option<&str>) -> anyhow::Result<()> {
match vm.evaluate(&line) {
Ok(()) => {
let output = vm.take_output();
// PAGE (form feed) clears the terminal
if output.contains('\x0C') {
print!("\x1b[2J\x1b[H");
}
let output = output.replace('\x0C', "");
if !vm.is_compiling() {
// Move cursor back up to end of input line so
// output appears inline, like traditional Forth:
+1
View File
@@ -2364,6 +2364,7 @@ impl<R: Runtime> ForthVM<R> {
// -- I/O --
self.register_primitive("EMIT", false, vec![IrOp::Emit])?;
self.register_primitive("CR", false, vec![IrOp::Cr])?;
self.register_primitive("PAGE", false, vec![IrOp::PushI32(0x0C), IrOp::Emit])?;
// -- Constants --
self.register_primitive("TRUE", false, vec![IrOp::PushI32(-1)])?;
+12 -3
View File
@@ -66,7 +66,12 @@ function evaluate(line) {
historyIdx = history.length;
try {
const result = repl.evaluate(trimmed);
let result = repl.evaluate(trimmed);
// PAGE (form feed) clears the screen
if (result.includes('\x0C')) {
output.innerHTML = '';
result = result.replaceAll('\x0C', '');
}
// Show input + output on one line (traditional Forth style)
const combined = result.length > 0 ? `${trimmed} ${result} ok` : `${trimmed} ok`;
appendLine(combined, 'line-ok');
@@ -230,11 +235,15 @@ async function boot() {
// Restore and run init code
const saved = localStorage.getItem('wafer-init-code');
if (saved) {
if (saved !== null) {
document.getElementById('init-code').value = saved;
for (const line of saved.split('\n')) {
}
const initCode = document.getElementById('init-code').value;
if (initCode.trim()) {
for (const line of initCode.split('\n')) {
if (line.trim()) evaluate(line);
}
localStorage.setItem('wafer-init-code', initCode);
}
// Load from URL hash if present
+3 -1
View File
@@ -47,7 +47,9 @@
</div>
</div>
<div class="init-body collapsed">
<textarea id="init-code" placeholder="\ Forth code to run on startup&#10;: greet cr .&quot; Hello WAFER!&quot; ;&#10;greet" spellcheck="false"></textarea>
<textarea id="init-code" spellcheck="false">\ Forth code to run on startup
: greet cr ." Hello WAFER!" ;
greet</textarea>
</div>
</div>
</div>