Implement [CHAR]

This commit is contained in:
Remko Tronçon 2019-03-11 14:01:34 +01:00
parent f17dac3e09
commit 779945c306
2 changed files with 26 additions and 0 deletions

View file

@ -1201,6 +1201,12 @@
(call $compilePushConst (call $pop)))
(!def_word "[']" "$bracket-tick" !fImmediate)
;; 6.1.2520
(func $bracket-char
(call $CHAR)
(call $compilePushConst (call $pop)))
(!def_word "[CHAR]" "$bracket-char" !fImmediate)
;; 6.1.2540
(func $right-bracket
(i32.store (i32.const !stateBase) (i32.const 1)))

View file

@ -778,6 +778,26 @@ function loadTests(wasmModule, arrayToBase64) {
});
});
describe("[CHAR]", () => {
it("should work with a single character", () => {
run(": FOO [CHAR] A 5 ;");
run("4 FOO 6");
expect(stack[0]).to.eql(4);
expect(stack[1]).to.eql(65);
expect(stack[2]).to.eql(5);
expect(stack[3]).to.eql(6);
});
it("should work with multiple characters", () => {
run(": FOO [CHAR] ABC 5 ;");
run("4 FOO 6");
expect(stack[0]).to.eql(4);
expect(stack[1]).to.eql(65);
expect(stack[2]).to.eql(5);
expect(stack[3]).to.eql(6);
});
});
// describe("word", () => {
// it("should read a word", () => {
// forth.read(" FOO BAR BAZ ");