Skip to content

Commit

Permalink
Merge pull request #51 from AndrewScheidecker/Fix_i32.wrap
Browse files Browse the repository at this point in the history
Fixed i32.wrap/i64 being parsed as i64.wrap/i64
  • Loading branch information
sunfishcode committed Sep 17, 2015
2 parents aa25fba + 45c1196 commit cc6b0a2
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ml-proto/src/host/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ rule token = parse

| "i64.extend_s/i32" { CONVERT (Values.Int64 Int64Op.ExtendSInt32) }
| "i64.extend_u/i32" { CONVERT (Values.Int64 Int64Op.ExtendUInt32) }
| "i64.wrap/i64" { CONVERT (Values.Int32 Int32Op.WrapInt64) }
| "i32.wrap/i64" { CONVERT (Values.Int32 Int32Op.WrapInt64) }
| (ixx as t)".trunc_s/f32"
{ CONVERT (intop t Int32Op.TruncSFloat32 Int64Op.TruncSFloat32) }
| (ixx as t)".trunc_u/f32"
Expand Down
102 changes: 102 additions & 0 deletions ml-proto/test/conversions.wasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
(module

;; i64.extend_s/i32
(func $i64_extend_s_i32 (param $x i32) (result i64) (i64.extend_s/i32 (get_local $x)))
(export "$i64_extend_s_i32" $i64_extend_s_i32)

;; i64.extend_u/i32
(func $i64_extend_u_i32 (param $x i32) (result i64) (i64.extend_u/i32 (get_local $x)))
(export "$i64_extend_u_i32" $i64_extend_u_i32)

;; i32.wrap/i64
(func $i32_wrap_i64 (param $x i64) (result i32) (i32.wrap/i64 (get_local $x)))
(export "$i32_wrap_i64" $i32_wrap_i64)

;; i32.trunc_s/f32
(func $i32_trunc_s_f32 (param $x f32) (result i32) (i32.trunc_s/f32 (get_local $x)))
(export "$i32_trunc_s_f32" $i32_trunc_s_f32)

;; i32.trunc_u/f32
(func $i32_trunc_u_f32 (param $x f32) (result i32) (i32.trunc_u/f32 (get_local $x)))
(export "$i32_trunc_u_f32" $i32_trunc_u_f32)

;; i64.trunc_s/f32
(func $i64_trunc_s_f32 (param $x f32) (result i64) (i64.trunc_s/f32 (get_local $x)))
(export "$i64_trunc_s_f32" $i64_trunc_s_f32)

;; i64.trunc_u/f32
(func $i64_trunc_u_f32 (param $x f32) (result i64) (i64.trunc_u/f32 (get_local $x)))
(export "$i64_trunc_u_f32" $i64_trunc_u_f32)
)

;; i64.extend_s/i32
(assert_eq (invoke "$i64_extend_s_i32" (i32.const 0)) (i64.const 0))
(assert_eq (invoke "$i64_extend_s_i32" (i32.const 10000)) (i64.const 10000))
(assert_eq (invoke "$i64_extend_s_i32" (i32.const -10000)) (i64.const -10000))

;; i64.extend_u/i32
(assert_eq (invoke "$i64_extend_u_i32" (i32.const 0)) (i64.const 0))
(assert_eq (invoke "$i64_extend_u_i32" (i32.const 10000)) (i64.const 10000))
(assert_eq (invoke "$i64_extend_u_i32" (i32.const -10000)) (i64.const 4294957296)) ;; ffff ffff ffff d8f0

;; i32.wrap/i64
(assert_eq (invoke "$i32_wrap_i64" (i64.const -1)) (i32.const -1))
(assert_eq (invoke "$i32_wrap_i64" (i64.const -100000)) (i32.const -100000))
(assert_eq (invoke "$i32_wrap_i64" (i64.const -2147483648)) (i32.const -2147483648)) ;; ffff ffff 8000 0000
(assert_eq (invoke "$i32_wrap_i64" (i64.const -2147483649)) (i32.const 2147483647)) ;; ffff ffff 7fff ffff
(assert_eq (invoke "$i32_wrap_i64" (i64.const -4294967296)) (i32.const 0)) ;; ffff ffff 0000 0000
(assert_eq (invoke "$i32_wrap_i64" (i64.const -4294967297)) (i32.const -1)) ;; ffff fffe ffff ffff
(assert_eq (invoke "$i32_wrap_i64" (i64.const -4294967295)) (i32.const 1)) ;; ffff ffff 0000 0001
(assert_eq (invoke "$i32_wrap_i64" (i64.const 0)) (i32.const 0))
(assert_eq (invoke "$i32_wrap_i64" (i64.const 1311768467463790320)) (i32.const -1698898192)) ;; 1234 5678 9abc def0
(assert_eq (invoke "$i32_wrap_i64" (i64.const 4294967295)) (i32.const -1)) ;; 0000 0000 ffff ffff
(assert_eq (invoke "$i32_wrap_i64" (i64.const 4294967296)) (i32.const 0)) ;; 0000 0001 0000 0000
(assert_eq (invoke "$i32_wrap_i64" (i64.const 4294967297)) (i32.const 1)) ;; 0000 0001 0000 0001

;; i32.trunc_s/f32
(assert_eq (invoke "$i32_trunc_s_f32" (f32.const 1.0)) (i32.const 1))
(assert_eq (invoke "$i32_trunc_s_f32" (f32.const 1.1)) (i32.const 1))
(assert_eq (invoke "$i32_trunc_s_f32" (f32.const 1.5)) (i32.const 1))
(assert_eq (invoke "$i32_trunc_s_f32" (f32.const -1.0)) (i32.const -1))
(assert_eq (invoke "$i32_trunc_s_f32" (f32.const -1.1)) (i32.const -1))
(assert_eq (invoke "$i32_trunc_s_f32" (f32.const -1.5)) (i32.const -1))
(assert_eq (invoke "$i32_trunc_s_f32" (f32.const -1.9)) (i32.const -1))
(assert_eq (invoke "$i32_trunc_s_f32" (f32.const -2.0)) (i32.const -2))

;; i32.trunc_u/f32
(assert_eq (invoke "$i32_trunc_u_f32" (f32.const 1.0)) (i32.const 1))
(assert_eq (invoke "$i32_trunc_u_f32" (f32.const 1.1)) (i32.const 1))
(assert_eq (invoke "$i32_trunc_u_f32" (f32.const 1.5)) (i32.const 1))
(assert_eq (invoke "$i32_trunc_u_f32" (f32.const 1.9)) (i32.const 1))
(assert_eq (invoke "$i32_trunc_u_f32" (f32.const 2.0)) (i32.const 2))
(assert_eq (invoke "$i32_trunc_u_f32" (f32.const 2147483648)) (i32.const -2147483648)) ;; 0x1.00000p+31 -> 8000 0000

;; i64.trunc_s/f32
(assert_eq (invoke "$i64_trunc_s_f32" (f32.const 1.0)) (i64.const 1))
(assert_eq (invoke "$i64_trunc_s_f32" (f32.const 1.1)) (i64.const 1))
(assert_eq (invoke "$i64_trunc_s_f32" (f32.const 1.5)) (i64.const 1))
(assert_eq (invoke "$i64_trunc_s_f32" (f32.const -1.0)) (i64.const -1))
(assert_eq (invoke "$i64_trunc_s_f32" (f32.const -1.1)) (i64.const -1))
(assert_eq (invoke "$i64_trunc_s_f32" (f32.const -1.5)) (i64.const -1))
(assert_eq (invoke "$i64_trunc_s_f32" (f32.const -1.9)) (i64.const -1))
(assert_eq (invoke "$i64_trunc_s_f32" (f32.const -2.0)) (i64.const -2))
(assert_eq (invoke "$i64_trunc_s_f32" (f32.const 4294967296)) (i64.const 4294967296)) ;; 0x1.00000p+32 -> 1 0000 0000
(assert_eq (invoke "$i64_trunc_s_f32" (f32.const -4294967296)) (i64.const -4294967296)) ;; -0x1.00000p+32 -> ffff ffff 0000 0000

;; i64.trunc_u/f32
(assert_eq (invoke "$i64_trunc_u_f32" (f32.const 1.0)) (i64.const 1))
(assert_eq (invoke "$i64_trunc_u_f32" (f32.const 1.1)) (i64.const 1))
(assert_eq (invoke "$i64_trunc_u_f32" (f32.const 1.5)) (i64.const 1))
(assert_eq (invoke "$i64_trunc_u_f32" (f32.const 4294967296)) (i64.const 4294967296))

(;
todo:
fxx.convert_s/ixx
fxx.convert_u/ixx
f64.promote/f32
f32.demote/f64
f32.reinterpret/i32
f64.reinterpret/i64
i32.reinterpret/f32
i64.reinterpret/f64
;)

0 comments on commit cc6b0a2

Please sign in to comment.