Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions ml-proto/TestingTodo.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Misc semantics:
- test that too-big `grow_memory` fails appropriately
- test that too-big linear memory initial allocation fails
- test that function addresses are monotonic indices, and not actual addresses.
- test that non-pagesize `grow_memory` fails
- ~~test that non-pagesize `grow_memory` fails~~
- test that non-pagesize initial linear memory allocation fails
- test that one can clobber the entire contents of the linear memory without corrupting: call stack, global variables, local variables, program execution.
- test that one can clobber the entire contents of the linear memory without corrupting: call stack, local variables, program execution.

Operator semantics:
- test that promote/demote, sext/trunc, zext/trunc is bit-preserving if not NaN
Expand All @@ -24,7 +24,10 @@ Operator semantics:
- ~~test that `page_size` returns a power of 2~~
- ~~test that arithmetic operands are evaluated left-to-right~~
- ~~test that call and store operands are evaluated left-to-right too~~
- test that call and argument operands of call_indirect are evaluated left-to-right, too
- ~~test that call and argument operands of call_indirect are evaluated left-to-right, too~~
- ~~test that select arguments are evaluated left-to-right, too~~
- test that br_if arguments are evaluated left-to-right, too
- test that tableswitch arguments are evaluated left-to-right, too
- ~~test that add/sub/mul/wrap/wrapping-store silently wrap on overflow~~
- ~~test that sdiv/udiv/srem/urem trap on divide-by-zero~~
- ~~test that sdiv traps on overflow~~
Expand All @@ -33,7 +36,7 @@ Operator semantics:
- ~~test that unsigned operations are properly unsigned~~
- ~~test that signed integer div rounds toward zero~~
- ~~test that signed integer mod has the sign of the dividend~~
- test that select preserves all NaN bits
- ~~test that select preserves all NaN bits~~

Floating point semantics:
- ~~test for round-to-nearest rounding~~
Expand Down
57 changes: 35 additions & 22 deletions ml-proto/test/fac.wast
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,18 @@
(local i64 i64)
(set_local 1 (get_local 0))
(set_local 2 (i64.const 1))
(block
(loop
(if_else
(i64.eq (get_local 1) (i64.const 0))
(br 1)
(block
(set_local 2 (i64.mul (get_local 1) (get_local 2)))
(set_local 1 (i64.sub (get_local 1) (i64.const 1)))
)
(loop
(if_else
(i64.eq (get_local 1) (i64.const 0))
(br 1)
(block
(set_local 2 (i64.mul (get_local 1) (get_local 2)))
(set_local 1 (i64.sub (get_local 1) (i64.const 1)))
)
(br 0)
)
(br 0)
)
(return (get_local 2))
(get_local 2)
)

;; Iterative factorial named
Expand All @@ -45,30 +43,45 @@
(local $res i64)
(set_local $i (get_local $n))
(set_local $res (i64.const 1))
(block $done
(loop $loop
(if_else
(i64.eq (get_local $i) (i64.const 0))
(br $done)
(block
(set_local $res (i64.mul (get_local $i) (get_local $res)))
(set_local $i (i64.sub (get_local $i) (i64.const 1)))
)
(loop $done $loop
(if_else
(i64.eq (get_local $i) (i64.const 0))
(br $done)
(block
(set_local $res (i64.mul (get_local $i) (get_local $res)))
(set_local $i (i64.sub (get_local $i) (i64.const 1)))
)
(br $loop)
)
(br $loop)
)
(get_local $res)
)

;; More-realistically optimized factorial.
(func $fac-opt (param i64) (result i64)
(local i64)
(set_local 1 (i64.const 1))
(block
(br_if (i64.lt_s (get_local 0) (i64.const 2)) 0)
(loop
(set_local 1 (i64.mul (get_local 1) (get_local 0)))
(set_local 0 (i64.add (get_local 0) (i64.const -1)))
(br_if (i64.gt_s (get_local 0) (i64.const 1)) 0)
)
)
(return (get_local $res))
(get_local 1)
)

(export "fac-rec" 0)
(export "fac-iter" 2)
(export "fac-rec-named" $fac-rec)
(export "fac-iter-named" $fac-iter)
(export "fac-opt" $fac-opt)
)

(assert_return (invoke "fac-rec" (i64.const 25)) (i64.const 7034535277573963776))
(assert_return (invoke "fac-iter" (i64.const 25)) (i64.const 7034535277573963776))
(assert_return (invoke "fac-rec-named" (i64.const 25)) (i64.const 7034535277573963776))
(assert_return (invoke "fac-iter-named" (i64.const 25)) (i64.const 7034535277573963776))
(assert_return (invoke "fac-opt" (i64.const 25)) (i64.const 7034535277573963776))
(assert_trap (invoke "fac-rec" (i64.const 1073741824)) "call stack exhausted")
6 changes: 6 additions & 0 deletions ml-proto/test/int_literals.wast
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
(func $i32.alt_smin (result i32) (return (i32.const 0x80000000)))
(func $i32.inc_smin (result i32) (return (i32.add (i32.const -0x80000000) (i32.const 1))))
(func $i32.neg_zero (result i32) (return (i32.const -0x0)))
(func $i32.not_octal (result i32) (return (i32.const 010)))

(func $i64.test (result i64) (return (i64.const 0x0CABBA6E0ba66a6e)))
(func $i64.umax (result i64) (return (i64.const 0xffffffffffffffff)))
Expand All @@ -16,6 +17,7 @@
(func $i64.alt_smin (result i64) (return (i64.const 0x8000000000000000)))
(func $i64.inc_smin (result i64) (return (i64.add (i64.const -0x8000000000000000) (i64.const 1))))
(func $i64.neg_zero (result i64) (return (i64.const -0x0)))
(func $i64.not_octal (result i64) (return (i64.const 010)))

(export "i32.test" $i32.test)
(export "i32.umax" $i32.umax)
Expand All @@ -25,6 +27,7 @@
(export "i32.alt_smin" $i32.alt_smin)
(export "i32.inc_smin" $i32.inc_smin)
(export "i32.neg_zero" $i32.neg_zero)
(export "i32.not_octal" $i32.not_octal)

(export "i64.test" $i64.test)
(export "i64.umax" $i64.umax)
Expand All @@ -34,6 +37,7 @@
(export "i64.alt_smin" $i64.alt_smin)
(export "i64.inc_smin" $i64.inc_smin)
(export "i64.neg_zero" $i64.neg_zero)
(export "i64.not_octal" $i64.not_octal)
)

(assert_return (invoke "i32.test") (i32.const 195940365))
Expand All @@ -44,6 +48,7 @@
(assert_return (invoke "i32.alt_smin") (i32.const -2147483648))
(assert_return (invoke "i32.inc_smin") (i32.const -2147483647))
(assert_return (invoke "i32.neg_zero") (i32.const 0))
(assert_return (invoke "i32.not_octal") (i32.const 10))

(assert_return (invoke "i64.test") (i64.const 913028331277281902))
(assert_return (invoke "i64.umax") (i64.const -1))
Expand All @@ -53,3 +58,4 @@
(assert_return (invoke "i64.alt_smin") (i64.const -9223372036854775808))
(assert_return (invoke "i64.inc_smin") (i64.const -9223372036854775807))
(assert_return (invoke "i64.neg_zero") (i64.const 0))
(assert_return (invoke "i64.not_octal") (i64.const 10))
Loading