Skip to content

Commit

Permalink
update simple test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwight Guth authored and dwightguth committed Aug 13, 2024
1 parent b350c96 commit c654db4
Show file tree
Hide file tree
Showing 14 changed files with 236 additions and 226 deletions.
10 changes: 10 additions & 0 deletions pykwasm/src/pykwasm/kdist/wasm-semantics/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,16 @@ The sort `OptionalInt` provides this potentially "undefined" `Int`.
```

### Integer conversion

```k
syntax MInt{32} ::= i2i32(Int) [function]
syntax MInt{64} ::= i2i64(Int) [function]
// -----------------------------------------
rule i2i32(I) => Int2MInt(I)
rule i2i64(I) => Int2MInt(I)
```

```k
endmodule
```
Expand Down
72 changes: 36 additions & 36 deletions tests/simple/arithmetic.wast
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
(i32.const 5)
(i32.const 7)
(i32.add)
#assertTopStack < i32 > 12 "add"
#assertTopStack < i32 > i2i32(12) "add"

(i32.const 5)
(i32.const 7)
(i32.sub)
#assertTopStack < i32 > -2 "sub"
#assertTopStack < i32 > i2i32(-2) "sub"

(i32.const 15)
(i32.const 3)
(i32.mul)
#assertTopStack < i32 > 45 "mul"
#assertTopStack < i32 > i2i32(45) "mul"

(i32.const 15)
(i32.const 3)
(i32.div_u)
#assertTopStack < i32 > 5 "div_u1"
#assertTopStack < i32 > i2i32(5) "div_u1"

(i32.const 15)
(i32.const 2)
(i32.div_u)
#assertTopStack < i32 > 7 "div_u2"
#assertTopStack < i32 > i2i32(7) "div_u2"

(i32.const 15)
(i32.const 0)
Expand All @@ -31,12 +31,12 @@
(i32.const 15)
(i32.const 3)
(i32.rem_u)
#assertTopStack < i32 > 0 "rem_u1"
#assertTopStack < i32 > i2i32(0) "rem_u1"

(i32.const 15)
(i32.const 2)
(i32.rem_u)
#assertTopStack < i32 > 1 "rem_u2"
#assertTopStack < i32 > i2i32(1) "rem_u2"

(i32.const 15)
(i32.const 0)
Expand All @@ -46,137 +46,137 @@
(i32.const 10)
(i32.const 3)
(i32.div_s)
#assertTopStack < i32 > 3 "i32.div_s 1"
#assertTopStack < i32 > i2i32(3) "i32.div_s 1"

(i32.const 10)
(i32.const 4)
(i32.div_s)
#assertTopStack < i32 > 2 "i32.div_s 2"
#assertTopStack < i32 > i2i32(2) "i32.div_s 2"

(i32.const 10)
(i32.const 0)
(i32.div_s)
#assertTrap "i32.div_s 3"

(i32.const #pow1(i32))
(i32.sub (i32.const #pow(i32)) (i32.const 1))
(i32.const 2147483648)
(i32.sub (i32.const 4294967296) (i32.const 1))
(i32.div_s)
#assertTrap "i32.div_s 4"

(i32.const 10)
(i32.const 5)
(i32.div_s)
#assertTopStack < i32 > 2 "div_s"
#assertTopStack < i32 > i2i32(2) "div_s"

(i32.const 91)
(i32.const 13)
(i32.rem_s)
#assertTopStack <i32 > 0 "rem_s"
#assertTopStack <i32 > i2i32(0) "rem_s"

(i32.const -91)
(i32.const -13)
(i32.rem_s)
#assertTopStack <i32 > 0 "rem_s"
#assertTopStack <i32 > i2i32(0) "rem_s"

(i32.const -1)
(i32.const -3)
(i32.rem_s)
#assertTopStack <i32 > -1 "rem_s"
#assertTopStack <i32 > i2i32(-1) "rem_s"

(i32.const 10)
(i32.const 0)
(i32.rem_s)
#assertTrap "rem_s"

(i32.const #pow1(i32))
(i32.sub (i32.const #pow(i32)) (i32.const 1))
(i32.const 2147483648)
(i32.sub (i32.const 4294967296) (i32.const 1))
(i32.rem_s)
#assertTopStack <i32 > 0 "rem_s edge case"
#assertTopStack <i32 > i2i32(0) "rem_s edge case"

;; The following tests were generated using the reference OCaml WASM interpreter.

(i32.const 10)
(i32.const 3)
(i32.rem_s)
#assertTopStack < i32 > 1 "i32.rem_s 1"
#assertTopStack < i32 > i2i32(1) "i32.rem_s 1"

(i32.const 10)
(i32.const 4)
(i32.rem_s)
#assertTopStack < i32 > 2 "i32.rem_s 2"
#assertTopStack < i32 > i2i32(2) "i32.rem_s 2"

(i32.const 10)
(i32.const 5)
(i32.rem_s)
#assertTopStack < i32 > 0 "i32.rem_s 3"
#assertTopStack < i32 > i2i32(0) "i32.rem_s 3"

(i32.const -10)
(i32.const 3)
(i32.div_s)
#assertTopStack < i32 > -3 "i32.div_s 3"
#assertTopStack < i32 > i2i32(-3) "i32.div_s 3"

(i32.const -10)
(i32.const 4)
(i32.div_s)
#assertTopStack < i32 > -2 "i32.div_s 4"
#assertTopStack < i32 > i2i32(-2) "i32.div_s 4"

(i32.const -10)
(i32.const 5)
(i32.div_s)
#assertTopStack < i32 > -2 "i32.div_s 5"
#assertTopStack < i32 > i2i32(-2) "i32.div_s 5"

(i32.const -10)
(i32.const 3)
(i32.rem_s)
#assertTopStack < i32 > -1 "i32.rem_s 4"
#assertTopStack < i32 > i2i32(-1) "i32.rem_s 4"

(i32.const -10)
(i32.const 4)
(i32.rem_s)
#assertTopStack < i32 > -2 "i32.rem_s 5"
#assertTopStack < i32 > i2i32(-2) "i32.rem_s 5"

(i32.const -10)
(i32.const 5)
(i32.rem_s)
#assertTopStack < i32 > 0 "i32.rem_s 6"
#assertTopStack < i32 > i2i32(0) "i32.rem_s 6"

(i32.const -10)
(i32.const -3)
(i32.div_s)
#assertTopStack < i32 > 3 "i32.div_s 6"
#assertTopStack < i32 > i2i32(3) "i32.div_s 6"

(i32.const -10)
(i32.const -4)
(i32.div_s)
#assertTopStack < i32 > 2 "i32.div_s 7"
#assertTopStack < i32 > i2i32(2) "i32.div_s 7"

(i32.const -10)
(i32.const -5)
(i32.div_s)
#assertTopStack < i32 > 2 "i32.div_s 8"
#assertTopStack < i32 > i2i32(2) "i32.div_s 8"

(i32.const -10)
(i32.const -3)
(i32.rem_s)
#assertTopStack < i32 > -1 "i32.rem_s 7"
#assertTopStack < i32 > i2i32(-1) "i32.rem_s 7"

(i32.const -10)
(i32.const -4)
(i32.rem_s)
#assertTopStack < i32 > -2 "i32.rem_s 8"
#assertTopStack < i32 > i2i32(-2) "i32.rem_s 8"

(i32.const -10)
(i32.const -5)
(i32.rem_s)
#assertTopStack < i32 > 0 "i32.rem_s 9"
#assertTopStack < i32 > i2i32(0) "i32.rem_s 9"

(i32.add (i32.const 3) (i32.const 4))
#assertTopStack < i32 > 7 "simple add folded"
#assertTopStack < i32 > i2i32(7) "simple add folded"

(i32.sub (i32.const 3) (i32.const 4))
#assertTopStack < i32 > -1 "simple sub, order dependent folded"
#assertTopStack < i32 > i2i32(-1) "simple sub, order dependent folded"

(i32.sub (i32.mul (i32.const 5) (i32.const 7)) (i32.const 4))
#assertTopStack < i32 > 31 "mul nested in sub folded"
#assertTopStack < i32 > i2i32(31) "mul nested in sub folded"

#clearConfig
Loading

0 comments on commit c654db4

Please sign in to comment.