This commit is contained in:
Remko Tronçon 2022-05-31 20:45:22 +02:00
parent 2dbe2e00dd
commit b13d7fe4d7
3 changed files with 424 additions and 389 deletions

File diff suppressed because it is too large Load diff

View file

@ -334,65 +334,65 @@ T{ BASE @ HEX BASE @ DECIMAL BASE @ - SWAP BASE ! -> 6 }T
\ T{ MA0 -> }T \ T{ MA0 -> }T
\ T{ MA? MA0 MA? MA1 MA? MA2 -> FALSE FALSE FALSE }T \ T{ MA? MA0 MA? MA1 MA? MA2 -> FALSE FALSE FALSE }T
\ \ ----------------------------------------------------------------------------- \ -----------------------------------------------------------------------------
\ TESTING ?DO TESTING ?DO
\ : QD ?DO I LOOP ; : QD ?DO I LOOP ;
\ T{ 789 789 QD -> }T T{ 789 789 QD -> }T
\ T{ -9876 -9876 QD -> }T T{ -9876 -9876 QD -> }T
\ T{ 5 0 QD -> 0 1 2 3 4 }T T{ 5 0 QD -> 0 1 2 3 4 }T
\ : QD1 ?DO I 10 +LOOP ; : QD1 ?DO I 10 +LOOP ;
\ T{ 50 1 QD1 -> 1 11 21 31 41 }T T{ 50 1 QD1 -> 1 11 21 31 41 }T
\ T{ 50 0 QD1 -> 0 10 20 30 40 }T T{ 50 0 QD1 -> 0 10 20 30 40 }T
\ : QD2 ?DO I 3 > IF LEAVE ELSE I THEN LOOP ; : QD2 ?DO I 3 > IF LEAVE ELSE I THEN LOOP ;
\ T{ 5 -1 QD2 -> -1 0 1 2 3 }T T{ 5 -1 QD2 -> -1 0 1 2 3 }T
\ : QD3 ?DO I 1 +LOOP ; : QD3 ?DO I 1 +LOOP ;
\ T{ 4 4 QD3 -> }T T{ 4 4 QD3 -> }T
\ T{ 4 1 QD3 -> 1 2 3 }T T{ 4 1 QD3 -> 1 2 3 }T
\ T{ 2 -1 QD3 -> -1 0 1 }T T{ 2 -1 QD3 -> -1 0 1 }T
\ : QD4 ?DO I -1 +LOOP ; : QD4 ?DO I -1 +LOOP ;
\ T{ 4 4 QD4 -> }T T{ 4 4 QD4 -> }T
\ T{ 1 4 QD4 -> 4 3 2 1 }T T{ 1 4 QD4 -> 4 3 2 1 }T
\ T{ -1 2 QD4 -> 2 1 0 -1 }T T{ -1 2 QD4 -> 2 1 0 -1 }T
\ : QD5 ?DO I -10 +LOOP ; : QD5 ?DO I -10 +LOOP ;
\ T{ 1 50 QD5 -> 50 40 30 20 10 }T T{ 1 50 QD5 -> 50 40 30 20 10 }T
\ T{ 0 50 QD5 -> 50 40 30 20 10 0 }T T{ 0 50 QD5 -> 50 40 30 20 10 0 }T
\ T{ -25 10 QD5 -> 10 0 -10 -20 }T T{ -25 10 QD5 -> 10 0 -10 -20 }T
\ VARIABLE ITERS VARIABLE ITERS
\ VARIABLE INCRMNT VARIABLE INCRMNT
\ : QD6 ( limit start increment -- ) : QD6 ( limit start increment -- )
\ INCRMNT ! INCRMNT !
\ 0 ITERS ! 0 ITERS !
\ ?DO ?DO
\ 1 ITERS +! 1 ITERS +!
\ I I
\ ITERS @ 6 = IF LEAVE THEN ITERS @ 6 = IF LEAVE THEN
\ INCRMNT @ INCRMNT @
\ +LOOP ITERS @ +LOOP ITERS @
\ ; ;
\ T{ 4 4 -1 QD6 -> 0 }T T{ 4 4 -1 QD6 -> 0 }T
\ T{ 1 4 -1 QD6 -> 4 3 2 1 4 }T T{ 1 4 -1 QD6 -> 4 3 2 1 4 }T
\ T{ 4 1 -1 QD6 -> 1 0 -1 -2 -3 -4 6 }T T{ 4 1 -1 QD6 -> 1 0 -1 -2 -3 -4 6 }T
\ T{ 4 1 0 QD6 -> 1 1 1 1 1 1 6 }T T{ 4 1 0 QD6 -> 1 1 1 1 1 1 6 }T
\ T{ 0 0 0 QD6 -> 0 }T T{ 0 0 0 QD6 -> 0 }T
\ T{ 1 4 0 QD6 -> 4 4 4 4 4 4 6 }T T{ 1 4 0 QD6 -> 4 4 4 4 4 4 6 }T
\ T{ 1 4 1 QD6 -> 4 5 6 7 8 9 6 }T T{ 1 4 1 QD6 -> 4 5 6 7 8 9 6 }T
\ T{ 4 1 1 QD6 -> 1 2 3 3 }T T{ 4 1 1 QD6 -> 1 2 3 3 }T
\ T{ 4 4 1 QD6 -> 0 }T T{ 4 4 1 QD6 -> 0 }T
\ T{ 2 -1 -1 QD6 -> -1 -2 -3 -4 -5 -6 6 }T T{ 2 -1 -1 QD6 -> -1 -2 -3 -4 -5 -6 6 }T
\ T{ -1 2 -1 QD6 -> 2 1 0 -1 4 }T T{ -1 2 -1 QD6 -> 2 1 0 -1 4 }T
\ T{ 2 -1 0 QD6 -> -1 -1 -1 -1 -1 -1 6 }T T{ 2 -1 0 QD6 -> -1 -1 -1 -1 -1 -1 6 }T
\ T{ -1 2 0 QD6 -> 2 2 2 2 2 2 6 }T T{ -1 2 0 QD6 -> 2 2 2 2 2 2 6 }T
\ T{ -1 2 1 QD6 -> 2 3 4 5 6 7 6 }T T{ -1 2 1 QD6 -> 2 3 4 5 6 7 6 }T
\ T{ 2 -1 1 QD6 -> -1 0 1 3 }T T{ 2 -1 1 QD6 -> -1 0 1 3 }T
\ \ ----------------------------------------------------------------------------- \ \ -----------------------------------------------------------------------------
\ TESTING BUFFER: \ TESTING BUFFER:

View file

@ -731,6 +731,20 @@ function loadTests() {
}); });
}); });
describe("?DO/LOOP", () => {
it("should run a loop", () => {
run(`: FOO 4 0 ?DO 3 LOOP ;`);
run("FOO");
expect(stackValues()).to.eql([3, 3, 3, 3]);
});
it("should not run a loop with equal conditions", () => {
run(`: FOO 4 4 ?DO 3 LOOP ;`);
run("FOO");
expect(stackValues()).to.eql([]);
});
});
describe("UNLOOP", () => { describe("UNLOOP", () => {
it("should work with nested loops", () => { it("should work with nested loops", () => {
run( run(