diff --git a/Cargo.lock b/Cargo.lock index 13fb838..462a9d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -158,9 +158,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.2.58" +version = "1.2.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1e928d4b69e3077709075a938a05ffbedfa53a84c8f766efbf8220bb1ff60e1" +checksum = "43c5703da9466b66a946814e1adf53ea2c90f10063b86290cc9eb67ce3478a20" dependencies = [ "find-msvc-tools", "jobserver", @@ -562,9 +562,9 @@ checksum = "dea2df4cf52843e0452895c455a1a2cfbb842a1e7329671acf418fdc53ed4c59" [[package]] name = "fastrand" -version = "2.3.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" [[package]] name = "find-msvc-tools" @@ -752,6 +752,12 @@ dependencies = [ "serde_core", ] +[[package]] +name = "hashbrown" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51" + [[package]] name = "heck" version = "0.5.0" @@ -789,21 +795,21 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.13.0" +version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" dependencies = [ "equivalent", - "hashbrown 0.16.1", + "hashbrown 0.17.0", "serde", "serde_core", ] [[package]] name = "insta" -version = "1.47.1" +version = "1.47.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99322078b2c076829a1db959d49da554fabc4342257fc0ba5a070a1eb3a01cd8" +checksum = "7b4a6248eb93a4401ed2f37dfe8ea592d3cf05b7cf4f8efa867b6895af7e094e" dependencies = [ "console", "once_cell", @@ -882,9 +888,9 @@ checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" [[package]] name = "libc" -version = "0.2.183" +version = "0.2.184" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" +checksum = "48f5d2a454e16a5ea0f4ced81bd44e4cfc7bd3a507b61887c99fd3538b28e4af" [[package]] name = "libm" @@ -894,9 +900,9 @@ checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" [[package]] name = "libredox" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ddbf48fd451246b1f8c2610bd3b4ac0cc6e149d89832867093ab69a17194f08" +checksum = "e02f3bb43d335493c96bf3fd3a321600bf6bd07ed34bc64118e9293bdffea46c" dependencies = [ "libc", ] @@ -1035,9 +1041,9 @@ checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" [[package]] name = "pkg-config" -version = "0.3.32" +version = "0.3.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" +checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e" [[package]] name = "postcard" @@ -1160,9 +1166,9 @@ dependencies = [ [[package]] name = "rand" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" +checksum = "7ec095654a25171c2124e9e3393a930bddbffdc939556c914957a4c3e0a87166" dependencies = [ "rand_chacha", "rand_core 0.9.5", @@ -1343,9 +1349,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.27" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" dependencies = [ "serde", "serde_core", @@ -2201,22 +2207,22 @@ dependencies = [ [[package]] name = "wast" -version = "245.0.1" +version = "246.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28cf1149285569120b8ce39db8b465e8a2b55c34cbb586bd977e43e2bc7300bf" +checksum = "fe3fe8e3bf88ad96d031b4181ddbd64634b17cb0d06dfc3de589ef43591a9a62" dependencies = [ "bumpalo", "leb128fmt", "memchr", "unicode-width", - "wasm-encoder 0.245.1", + "wasm-encoder 0.246.2", ] [[package]] name = "wat" -version = "1.245.1" +version = "1.246.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd48d1679b6858988cb96b154dda0ec5bbb09275b71db46057be37332d5477be" +checksum = "4bd7fda1199b94fff395c2d19a153f05dbe7807630316fa9673367666fd2ad8c" dependencies = [ "wast", ] diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index dc5e606..ba17205 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -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: diff --git a/crates/core/src/outer.rs b/crates/core/src/outer.rs index cea6934..ffe7735 100644 --- a/crates/core/src/outer.rs +++ b/crates/core/src/outer.rs @@ -2364,6 +2364,7 @@ impl ForthVM { // -- 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)])?; diff --git a/crates/web/www/app.js b/crates/web/www/app.js index a711f39..9d6a4ec 100644 --- a/crates/web/www/app.js +++ b/crates/web/www/app.js @@ -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 diff --git a/crates/web/www/index.html b/crates/web/www/index.html index 80bfddb..c72d732 100644 --- a/crates/web/www/index.html +++ b/crates/web/www/index.html @@ -47,7 +47,9 @@