mirror of
https://github.com/remko/waforth
synced 2025-01-29 08:34:33 +01:00
Implement REFILL + make >IN handling compliant
This commit is contained in:
parent
c4817ebcb9
commit
e41247b2a7
2 changed files with 36 additions and 24 deletions
|
@ -1344,6 +1344,28 @@
|
|||
(i32.const 2))))))
|
||||
(!def_word "PICK" "$PICK")
|
||||
|
||||
;; 6.2.2125
|
||||
(func $refill
|
||||
(local $char i32)
|
||||
(set_global $inputBufferSize (i32.const 0))
|
||||
(if (i32.eq (get_global $sourceID) (i32.const -1))
|
||||
(then
|
||||
(call $push (i32.const -1))
|
||||
(return)))
|
||||
(block $endLoop
|
||||
(loop $loop
|
||||
(br_if $endLoop (i32.eq (tee_local $char (call $shell_getc)) (i32.const -1)))
|
||||
(i32.store8 (i32.add (i32.const !inputBufferBase) (get_global $inputBufferSize))
|
||||
(get_local $char))
|
||||
(set_global $inputBufferSize (i32.add (get_global $inputBufferSize) (i32.const 1)))
|
||||
(br $loop)))
|
||||
(if (i32.eqz (get_global $inputBufferSize))
|
||||
(then (call $push (i32.const 0)))
|
||||
(else
|
||||
(i32.store (i32.const !inBase) (i32.const 0))
|
||||
(call $push (i32.const -1)))))
|
||||
(!def_word "REFILL" "$refill")
|
||||
|
||||
;; 6.1.2395
|
||||
(func $UNUSED
|
||||
(call $push (i32.shr_s (i32.sub (i32.const !memorySize) (get_global $here)) (i32.const 2))))
|
||||
|
@ -1535,7 +1557,6 @@ EOF
|
|||
(local $error i32)
|
||||
(set_local $error (i32.const 0))
|
||||
(set_global $tors (i32.const !returnStackBase))
|
||||
(i32.store (i32.const !inBase) (i32.const 0))
|
||||
(block $endLoop
|
||||
(loop $loop
|
||||
(call $word)
|
||||
|
@ -1911,17 +1932,6 @@ EOF
|
|||
(return (get_local $n)))))
|
||||
(unreachable))
|
||||
|
||||
(func $readInput
|
||||
(local $char i32)
|
||||
(set_global $inputBufferSize (i32.const 0))
|
||||
(block $endLoop
|
||||
(loop $loop
|
||||
(br_if $endLoop (i32.eq (tee_local $char (call $shell_getc)) (i32.const -1)))
|
||||
(i32.store8 (i32.add (i32.const !inputBufferBase) (get_global $inputBufferSize))
|
||||
(get_local $char))
|
||||
(set_global $inputBufferSize (i32.add (get_global $inputBufferSize) (i32.const 1)))
|
||||
(br $loop))))
|
||||
|
||||
(func $loadPrelude (export "loadPrelude")
|
||||
(set_global $sourceID (i32.const -1))
|
||||
(call $push (i32.const !preludeDataBase))
|
||||
|
@ -2022,7 +2032,8 @@ EOF
|
|||
|
||||
(func (export "interpret") (result i32)
|
||||
(local $result i32)
|
||||
(call $readInput)
|
||||
(call $refill)
|
||||
(drop (call $pop))
|
||||
(if (i32.ge_s (tee_local $result (call $interpret)) (i32.const 0))
|
||||
(then
|
||||
;; Write ok
|
||||
|
|
|
@ -78,16 +78,17 @@ function loadTests(wasmModule, arrayToBase64) {
|
|||
console.log("Entry:", p, previous, length, name, code, data, end);
|
||||
}
|
||||
|
||||
function run(s, expectErrors = false) {
|
||||
const r = forth.run(s);
|
||||
if (expectErrors) {
|
||||
expect(r).to.be.undefined;
|
||||
output = output.substr(0, output.length);
|
||||
} else {
|
||||
expect(r).to.not.be.below(0);
|
||||
output = output.substr(0, output.length - 3); // Strip 'ok\n' from output
|
||||
}
|
||||
return r;
|
||||
function run(ss, expectErrors = false) {
|
||||
ss.split("\n").forEach(s => {
|
||||
const r = forth.run(s);
|
||||
if (expectErrors) {
|
||||
expect(r).to.be.undefined;
|
||||
output = output.substr(0, output.length);
|
||||
} else {
|
||||
expect(r).to.not.be.below(0);
|
||||
output = output.substr(0, output.length - 3); // Strip 'ok\n' from output
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function here() {
|
||||
|
@ -1370,7 +1371,7 @@ function loadTests(wasmModule, arrayToBase64) {
|
|||
|
||||
it("should run core word tests", () => {
|
||||
run(standardCoreWordsTestSuite);
|
||||
// console.log("Output: ", output);
|
||||
console.log("Output: ", output);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue