Skip to content

Commit

Permalink
Implement +PLACE
Browse files Browse the repository at this point in the history
  • Loading branch information
tkers committed Mar 20, 2022
1 parent 80d4dee commit 711501e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/core.fs
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,12 @@ include ../shared/core.fs
: place ( c-addr1 u1 c-addr2 -- )
over >r rot over char+ r> move c! ;

: +place ( c-addr1 u1 c-addr2 -- )
over over >r >r
count chars +
swap chars move
r> r@ c@ + r> c! ;

: bounds ( addr u – addr+u addr )
over + swap ;

Expand Down
7 changes: 7 additions & 0 deletions test/core/test-plus-place.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
create note 256 chars allot

: main
s" Forth " note place
s" for " note +place
s" GB" note +place
note ;
13 changes: 13 additions & 0 deletions test/core/test-plus-place.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const gb = require("../gbtest")(__filename);

const readCountedString = (addr) => {
const len = gb.memory[addr]
const chars = gb.memory.slice(addr + 1, addr + 1 + len)
return String.fromCharCode(...chars)
}

test("plus-place", () => {
gb.run();
expect(gb.stack.length).toBe(1);
expect(readCountedString(gb.stack[0])).toBe("Forth for GB")
});

0 comments on commit 711501e

Please sign in to comment.