Implement DEFER, DEFER!, DEFER@, IS, ACTION-OF

This commit is contained in:
Remko Tronçon 2022-06-04 11:16:03 +02:00
parent f1a0f8ddb9
commit 1f5ffd1b9c
3 changed files with 395 additions and 276 deletions

File diff suppressed because it is too large Load diff

View file

@ -657,39 +657,39 @@ T{ PARSE-NAME-TEST abcde abcde
T{ PARSE-NAME-TEST abcde abcde
-> TRUE }T \ Leading and trailing spaces
\ \ -----------------------------------------------------------------------------
\ TESTING DEFER DEFER@ DEFER! IS ACTION-OF (Forth 2012)
\ \ Adapted from the Forth 200X RfD tests
\ -----------------------------------------------------------------------------
TESTING DEFER DEFER@ DEFER! IS ACTION-OF (Forth 2012)
\ Adapted from the Forth 200X RfD tests
\ T{ DEFER DEFER1 -> }T
\ T{ : MY-DEFER DEFER ; -> }T
\ T{ : IS-DEFER1 IS DEFER1 ; -> }T
\ T{ : ACTION-DEFER1 ACTION-OF DEFER1 ; -> }T
\ T{ : DEF! DEFER! ; -> }T
\ T{ : DEF@ DEFER@ ; -> }T
T{ DEFER DEFER1 -> }T
T{ : MY-DEFER DEFER ; -> }T
T{ : IS-DEFER1 IS DEFER1 ; -> }T
T{ : ACTION-DEFER1 ACTION-OF DEFER1 ; -> }T
T{ : DEF! DEFER! ; -> }T
T{ : DEF@ DEFER@ ; -> }T
\ T{ ' * ' DEFER1 DEFER! -> }T
\ T{ 2 3 DEFER1 -> 6 }T
\ T{ ' DEFER1 DEFER@ -> ' * }T
\ T{ ' DEFER1 DEF@ -> ' * }T
\ T{ ACTION-OF DEFER1 -> ' * }T
\ T{ ACTION-DEFER1 -> ' * }T
\ T{ ' + IS DEFER1 -> }T
\ T{ 1 2 DEFER1 -> 3 }T
\ T{ ' DEFER1 DEFER@ -> ' + }T
\ T{ ' DEFER1 DEF@ -> ' + }T
\ T{ ACTION-OF DEFER1 -> ' + }T
\ T{ ACTION-DEFER1 -> ' + }T
\ T{ ' - IS-DEFER1 -> }T
\ T{ 1 2 DEFER1 -> -1 }T
\ T{ ' DEFER1 DEFER@ -> ' - }T
\ T{ ' DEFER1 DEF@ -> ' - }T
\ T{ ACTION-OF DEFER1 -> ' - }T
\ T{ ACTION-DEFER1 -> ' - }T
T{ ' * ' DEFER1 DEFER! -> }T
T{ 2 3 DEFER1 -> 6 }T
T{ ' DEFER1 DEFER@ -> ' * }T
T{ ' DEFER1 DEF@ -> ' * }T
T{ ACTION-OF DEFER1 -> ' * }T
T{ ACTION-DEFER1 -> ' * }T
T{ ' + IS DEFER1 -> }T
T{ 1 2 DEFER1 -> 3 }T
T{ ' DEFER1 DEFER@ -> ' + }T
T{ ' DEFER1 DEF@ -> ' + }T
T{ ACTION-OF DEFER1 -> ' + }T
T{ ACTION-DEFER1 -> ' + }T
T{ ' - IS-DEFER1 -> }T
T{ 1 2 DEFER1 -> -1 }T
T{ ' DEFER1 DEFER@ -> ' - }T
T{ ' DEFER1 DEF@ -> ' - }T
T{ ACTION-OF DEFER1 -> ' - }T
T{ ACTION-DEFER1 -> ' - }T
\ T{ MY-DEFER DEFER2 -> }T
\ T{ ' DUP IS DEFER2 -> }T
\ T{ 1 DEFER2 -> 1 1 }T
T{ MY-DEFER DEFER2 -> }T
T{ ' DUP IS DEFER2 -> }T
T{ 1 DEFER2 -> 1 1 }T
\ -----------------------------------------------------------------------------
TESTING HOLDS (Forth 2012)

View file

@ -1578,6 +1578,25 @@ function loadTests() {
});
});
describe("DEFER", () => {
it("should work", () => {
run("DEFER DEFER1");
run("' * ' DEFER1 DEFER!");
run("2 3 DEFER1");
expect(stackValues()).to.eql([6]);
});
});
describe("IS", () => {
it("should work compiled", () => {
run("DEFER DEFER1");
run(": IS-DEFER1 IS DEFER1 ;");
run("' - IS-DEFER1");
run("1 2 DEFER1");
expect(stackValues()).to.eql([-1]);
});
});
describe("system", () => {
it("should run sieve", () => {
run(sieve);