Implement */

This commit is contained in:
Remko Tronçon 2018-06-01 22:49:16 +02:00
parent b6fecdebb1
commit 8140811ead
2 changed files with 29 additions and 3 deletions

View file

@ -181,6 +181,19 @@
(set_global $tos (get_local $btos)))
(!def_word "*" "$star")
;; 6.1.0100
(func $*/ (param i32)
(local $bbtos i32)
(local $bbbtos i32)
(i32.store (tee_local $bbbtos (i32.sub (get_global $tos) (i32.const 12)))
(i32.wrap/i64
(i64.div_s
(i64.mul (i64.extend_s/i32 (i32.load (get_local $bbbtos)))
(i64.extend_s/i32 (i32.load (tee_local $bbtos (i32.sub (get_global $tos) (i32.const 8))))))
(i64.extend_s/i32 (i32.load (i32.sub (get_global $tos) (i32.const 4)))))))
(set_global $tos (get_local $bbtos)))
(!def_word "*/" "$*/")
;; 6.1.0120
(func $plus (param i32)
(local $btos i32)

View file

@ -293,6 +293,19 @@ describe("WAForth", () => {
});
});
describe("*/", () => {
it("should work with small numbers", () => {
run("10 3 5 */ 5");
expect(stack[0]).to.eql(6);
expect(stack[1]).to.eql(5);
});
it("should work with large numbers", () => {
run("268435455 1000 5000 */");
expect(stack[0]).to.eql(53687091);
});
});
describe("1+", () => {
it("should work with positive numbers", () => {
run("3");
@ -783,7 +796,7 @@ describe("WAForth", () => {
forth.read("DUP");
core.WORD();
core.FIND();
expect(stack[0]).to.eql(131728);
expect(stack[0]).to.eql(131740);
expect(stack[1]).to.eql(-1);
});
@ -799,7 +812,7 @@ describe("WAForth", () => {
forth.read("+LOOP");
core.WORD();
core.FIND();
expect(stack[0]).to.eql(131132);
expect(stack[0]).to.eql(131144);
expect(stack[1]).to.eql(1);
});
@ -961,7 +974,7 @@ describe("WAForth", () => {
});
});
describe.only("MOVE", () => {
describe("MOVE", () => {
it("should work with non-overlapping regions", () => {
const ptr = here();
memory8[ptr] = 1;