diff --git a/lib/core.fs b/lib/core.fs index 475b49e..c4b8dfc 100644 --- a/lib/core.fs +++ b/lib/core.fs @@ -648,3 +648,10 @@ include ../shared/core.fs loop drop drop true then ; + +: roll ( x_u x_u-1 ... x_0 u -- x_u-1 ... x_0 x_u ) + dup 0= if + drop exit + then + swap >R + 1- recurse R> swap ; diff --git a/test/core/test-roll.fs b/test/core/test-roll.fs new file mode 100644 index 0000000..0cdc821 --- /dev/null +++ b/test/core/test-roll.fs @@ -0,0 +1 @@ +: main #1 #2 #3 #2 roll #1 roll #0 roll ; diff --git a/test/core/test-roll.js b/test/core/test-roll.js new file mode 100644 index 0000000..e07fb8e --- /dev/null +++ b/test/core/test-roll.js @@ -0,0 +1,6 @@ +const gb = require("../gbtest")(__filename); + +test("roll", () => { + gb.run(); + expect(gb.stack).toEqual([0x02, 0x01, 0x03]); +});