Skip to content

Commit

Permalink
Merge pull request #44 from WebAssembly/integer-unary
Browse files Browse the repository at this point in the history
Sync the integer unary operators with AstSemantics.md.
  • Loading branch information
sunfishcode committed Sep 3, 2015
2 parents d168abf + 85846ca commit ce645d2
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ml-proto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ memtype: <type> | i8 | i16
value: <int> | <float>
var: <int> | $<name>
unop: neg | abs | not | ...
unop: ctz | clz | popcnt | ...
binop: add | sub | mul | ...
relop: eq | neq | lt | ...
sign: s|u
Expand Down
4 changes: 1 addition & 3 deletions ml-proto/src/arithmetic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,9 @@ struct

let unop op =
let f = match op with
| Neg -> Int.neg
| Abs -> Int.abs
| Not -> Int.lognot
| Clz -> fun i -> i (* TODO *)
| Ctz -> fun i -> i (* TODO *)
| Popcnt -> fun i -> i (* TODO *)
in fun v -> Int.to_value (f (Int.of_value 1 v))

let binop op =
Expand Down
2 changes: 1 addition & 1 deletion ml-proto/src/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type value_type = Types.value_type Source.phrase

module IntOp () =
struct
type unop = Neg | Abs | Not | Clz | Ctz
type unop = Clz | Ctz | Popcnt
type binop = Add | Sub | Mul | DivS | DivU | RemS | RemU
| And | Or | Xor | Shl | Shr | Sar
type relop = Eq | Neq | LtS | LtU | LeS | LeU | GtS | GtU | GeS | GeU
Expand Down
4 changes: 1 addition & 3 deletions ml-proto/src/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,9 @@ rule token = parse
| (nxx as t)".switch" { SWITCH (value_type t) }
| (nxx as t)".const" { CONST (value_type t) }

| (ixx as t)".neg" { UNARY (intop t Int32Op.Neg Int64Op.Neg) }
| (ixx as t)".abs" { UNARY (intop t Int32Op.Abs Int64Op.Abs) }
| (ixx as t)".not" { UNARY (intop t Int32Op.Not Int64Op.Not) }
| (ixx as t)".clz" { UNARY (intop t Int32Op.Clz Int64Op.Clz) }
| (ixx as t)".ctz" { UNARY (intop t Int32Op.Ctz Int64Op.Ctz) }
| (ixx as t)".popcnt" { UNARY (intop t Int32Op.Popcnt Int64Op.Popcnt) }
| (fxx as t)".neg" { UNARY (floatop t Float32Op.Neg Float64Op.Neg) }
| (fxx as t)".abs" { UNARY (floatop t Float32Op.Abs Float64Op.Abs) }
| (fxx as t)".sqrt" { UNARY (floatop t Float32Op.Sqrt Float64Op.Sqrt) }
Expand Down
4 changes: 2 additions & 2 deletions ml-proto/test/switch.wasm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
(case 0 (return (get_local $i)))
(case 1 (nop) fallthrough)
(case 2) ;; implicit fallthrough
(case 3 (set_local $j (i32.neg (get_local $i))) (break))
(case 3 (set_local $j (i32.sub (i32.const 0) (get_local $i))) (break))
(case 4 (break))
(case 5 (set_local $j (i32.const 101)))
(case 6 (set_local $j (i32.const 101)) fallthrough)
Expand All @@ -30,7 +30,7 @@
(case 0 (return (get_local $i)))
(case 1 (nop) fallthrough)
(case 2) ;; implicit fallthrough
(case 3 (break $l (i64.neg (get_local $i))))
(case 3 (break $l (i64.sub (i64.const 0) (get_local $i))))
(case 6 (set_local $j (i64.const 101)) fallthrough)
(;default;) (get_local $j)
)
Expand Down

0 comments on commit ce645d2

Please sign in to comment.