From 186ab96276fa5a5095cea186fdde8a87f9ae9e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Wed, 13 Mar 2019 20:01:17 +0100 Subject: [PATCH] Implement S>D --- src/waforth.wat | 8 ++++++++ tests/standard-testsuite/core.f.js | 11 +++++++++++ tests/tests.js | 14 ++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/waforth.wat b/src/waforth.wat index cbc1d27..aed517c 100644 --- a/src/waforth.wat +++ b/src/waforth.wat @@ -1145,6 +1145,14 @@ (call $ALIGN)) (!def_word "S\"" "$Sq" !fImmediate) + ;; 6.1.2170 + (func $s-to-d + (local $btos i32) + (i64.store (tee_local $btos (i32.sub (get_global $tos) (i32.const 4))) + (i64.extend_s/i32 (i32.load (get_local $btos)))) + (set_global $tos (i32.add (get_global $tos) (i32.const 4)))) + (!def_word "S>D" "$s-to-d") + ;; 6.1.2216 (func $SOURCE (call $push (i32.const !inputBufferBase)) diff --git a/tests/standard-testsuite/core.f.js b/tests/standard-testsuite/core.f.js index 84e3406..aa32530 100644 --- a/tests/standard-testsuite/core.f.js +++ b/tests/standard-testsuite/core.f.js @@ -270,5 +270,16 @@ T{ 1 ABS -> 1 }T T{ -1 ABS -> 1 }T T{ MIN-INT ABS -> MID-UINT+1 }T +\\ ------------------------------------------------------------------------ +TESTING MULTIPLY: S>D * M* UM* + +T{ 0 S>D -> 0 0 }T +T{ 1 S>D -> 1 0 }T +T{ 2 S>D -> 2 0 }T +T{ -1 S>D -> -1 -1 }T +T{ -2 S>D -> -2 -1 }T +T{ MIN-INT S>D -> MIN-INT -1 }T +T{ MAX-INT S>D -> MAX-INT 0 }T + `; diff --git a/tests/tests.js b/tests/tests.js index 03d7793..45e656f 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -1350,6 +1350,20 @@ function loadTests(wasmModule, arrayToBase64) { }); }); + describe("S>D", () => { + it("should work with positive number", () => { + run("2 S>D"); + expect(stack[0]).to.eql(2); + expect(stack[1]).to.eql(0); + }); + + it("should work with negative number", () => { + run("-2 S>D"); + expect(stack[0]).to.eql(-2); + expect(stack[1]).to.eql(-1); + }); + }); + describe("system", () => { beforeEach(() => { core.loadPrelude();