Implement ABORT + QUIT

This commit is contained in:
Remko Tronçon 2019-03-12 14:26:38 +01:00
parent 2e344baf31
commit 7920432071
3 changed files with 24 additions and 2 deletions

View file

@ -112,7 +112,12 @@ class WAForth {
run(s) { run(s) {
this.read(s); this.read(s);
try {
return this.core.exports.interpret(); return this.core.exports.interpret();
} catch (e) {
// Exceptions thrown from the core means QUIT or ABORT is called, or an error
// has occurred. Assume what has been done has been done, and ignore here.
}
} }
} }

View file

@ -28,7 +28,11 @@ function prompt() {
$el.html($el.html().replace(/\n$/, "")); $el.html($el.html().replace(/\n$/, ""));
forth.run(input); forth.run(input);
jqconsole.Write(outputBuffer.join(""), "jqconsole-output"); let output = outputBuffer.join("");
if (output.length === 0) {
output = "\n";
}
jqconsole.Write(output, "jqconsole-output");
outputBuffer = []; outputBuffer = [];
prompt(); prompt();
}); });

View file

@ -585,6 +585,12 @@
(i32.load (i32.load (get_local $btos))))) (i32.load (i32.load (get_local $btos)))))
(!def_word "@" "$@") (!def_word "@" "$@")
;; 6.1.0670 ABORT
(func $ABORT
(set_global $tos (i32.const !stackBase))
(call $QUIT))
(!def_word "ABORT" "$ABORT")
;; 6.1.0690 ;; 6.1.0690
(func $ABS (func $ABS
(local $btos i32) (local $btos i32)
@ -1012,6 +1018,13 @@
(call $compileCall (get_local $findToken))) (call $compileCall (get_local $findToken)))
(!def_word "POSTPONE" "$POSTPONE" !fImmediate) (!def_word "POSTPONE" "$POSTPONE" !fImmediate)
;; 6.1.2050
(func $QUIT
(set_global $tors (i32.const !returnStackBase))
(set_global $sourceID (i32.const 0))
(unreachable))
(!def_word "QUIT" "$QUIT")
;; 6.1.2060 ;; 6.1.2060
(func $R> (func $R>
(set_global $tors (i32.sub (get_global $tors) (i32.const 4))) (set_global $tors (i32.sub (get_global $tors) (i32.const 4)))