Implement CONSTANT & VALUE in terms of CREATE DOES>

This commit is contained in:
Remko Tronçon 2019-03-10 16:53:18 +01:00
parent 2a7322cfa5
commit b23bf78a45
2 changed files with 17 additions and 22 deletions

View file

@ -104,9 +104,8 @@
(define !popIndex 2) (define !popIndex 2)
(define !typeIndex 3) (define !typeIndex 3)
(define !pushDataAddressIndex 4) (define !pushDataAddressIndex 4)
(define !pushDataValueIndex 5) (define !setLatestBodyIndex 5)
(define !setLatestBodyIndex 6) (define !tableStartIndex 6)
(define !tableStartIndex 7)
(define !dictionaryLatest 0) (define !dictionaryLatest 0)
(define !dictionaryTop !dictionaryBase) (define !dictionaryTop !dictionaryBase)
@ -661,15 +660,6 @@
(i32.load8_u (i32.const (!+ !wordBase 4))))) (i32.load8_u (i32.const (!+ !wordBase 4)))))
(!def_word "CHAR" "$CHAR") (!def_word "CHAR" "$CHAR")
;; 6.1.0950
(func $CONSTANT
(call $create)
(i32.store (call $body (get_global $latest)) (i32.const !pushDataValueIndex))
(i32.store (get_global $here) (call $pop))
(call $setFlag (i32.const !fData))
(set_global $here (i32.add (get_global $here) (i32.const 4))))
(!def_word "CONSTANT" "$CONSTANT")
;; 6.1.0980 ;; 6.1.0980
(func $COUNT (func $COUNT
(local $btos i32) (local $btos i32)
@ -1121,9 +1111,6 @@
(call $compileUntil)) (call $compileUntil))
(!def_word "UNTIL" "$UNTIL" !fImmediate) (!def_word "UNTIL" "$UNTIL" !fImmediate)
;; 6.2.2405
(!def_word "VALUE" "$CONSTANT")
;; 6.1.2410 ;; 6.1.2410
(func $VARIABLE (func $VARIABLE
(call $create) (call $create)
@ -1280,6 +1267,9 @@
; IMMEDIATE ; IMMEDIATE
\ 6.1.0950
: CONSTANT CREATE , DOES> @ ;
\ 6.1.1170 \ 6.1.1170
: DECIMAL 10 BASE ! ; : DECIMAL 10 BASE ! ;
@ -1358,6 +1348,9 @@
\ 6.1.0180 \ 6.1.0180
: . 0 .R SPACE ; : . 0 .R SPACE ;
\ 6.2.2405
: VALUE CONSTANT ;
EOF EOF
) )
@ -1682,10 +1675,6 @@ EOF
(call $push (get_local $d))) (call $push (get_local $d)))
(elem (i32.const !pushDataAddressIndex) $pushDataAddress) (elem (i32.const !pushDataAddressIndex) $pushDataAddress)
(func $pushDataValue (param $d i32)
(call $push (i32.load (get_local $d))))
(elem (i32.const !pushDataValueIndex) $pushDataValue)
(func $setLatestBody (param $v i32) (func $setLatestBody (param $v i32)
(i32.store (call $body (get_global $latest)) (get_local $v))) (i32.store (call $body (get_global $latest)) (get_local $v)))
(elem (i32.const !setLatestBodyIndex) $setLatestBody) (elem (i32.const !setLatestBodyIndex) $setLatestBody)
@ -1924,8 +1913,6 @@ EOF
;; - name (n bytes): Name characters. End is 4-byte aligned. ;; - name (n bytes): Name characters. End is 4-byte aligned.
;; - code pointer (4 bytes): Index into the function ;; - code pointer (4 bytes): Index into the function
;; table of code to execute ;; table of code to execute
;; - code argument (4 bytes) (optional): In case the function is
;; pushDataValue (used by CONST), contains data used by the function.
;; - data (m bytes) ;; - data (m bytes)
;; ;;
;; Execution tokens are addresses of dictionary entries ;; Execution tokens are addresses of dictionary entries

View file

@ -827,7 +827,7 @@ function loadTests(wasmModule, arrayToBase64) {
it("should find a word", () => { it("should find a word", () => {
loadString("DUP"); loadString("DUP");
run("FIND"); run("FIND");
expect(stack[0]).to.eql(131784); expect(stack[0]).to.eql(131764);
expect(stack[1]).to.eql(-1); expect(stack[1]).to.eql(-1);
}); });
@ -1186,6 +1186,10 @@ function loadTests(wasmModule, arrayToBase64) {
}); });
describe("CONSTANT", () => { describe("CONSTANT", () => {
beforeEach(() => {
core.loadPrelude();
});
it("should work", () => { it("should work", () => {
run("12 CONSTANT FOO"); run("12 CONSTANT FOO");
run("FOO 5"); run("FOO 5");
@ -1195,6 +1199,10 @@ function loadTests(wasmModule, arrayToBase64) {
}); });
describe("VALUE", () => { describe("VALUE", () => {
beforeEach(() => {
core.loadPrelude();
});
it("should store a value", () => { it("should store a value", () => {
run("12 VALUE FOO"); run("12 VALUE FOO");
run("FOO 5"); run("FOO 5");