Skip to content
Closed
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
4 changes: 2 additions & 2 deletions ml-proto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ type expr =
| StoreGlobal of var * expr (* write global variable
| Load of loadop * expr (* read memory address
| Store of storeop * expr * expr (* write memory address
| Const of value (* constant
| Literal of value (* literal value
| Unary of unop * expr (* unary arithmetic operator
| Binary of binop * expr * expr (* binary arithmetic operator
| Compare of relop * expr * expr (* arithmetic comparison
Expand Down Expand Up @@ -182,7 +182,7 @@ expr:
( store_global <var> <expr> )
( <type>.load((8|16)_<sign>)?(/<align>)? <expr> )
( <type>.store(/<align>)? <expr> <expr> )
( <type>.const <value> )
( <type>.literal <value> )
( <type>.<unop> <expr> )
( <type>.<binop> <expr> <expr> )
( <type>.<relop> <expr> <expr> )
Expand Down
2 changes: 1 addition & 1 deletion ml-proto/src/host/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ rule token = parse
{ STORETRUNC (truncop t sz a) }

| (nxx as t)".switch" { SWITCH (value_type t) }
| (nxx as t)".const" { CONST (value_type t) }
| (nxx as t)".literal" { LITERAL (value_type t) }

| (ixx as t)".clz" { UNARY (intop t Int32Op.Clz Int64Op.Clz) }
| (ixx as t)".ctz" { UNARY (intop t Int32Op.Ctz Int64Op.Ctz) }
Expand Down
8 changes: 4 additions & 4 deletions ml-proto/src/host/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let literal at s t =
| Types.Int64Type -> Values.Int64 (I64.of_string s) @@ at
| Types.Float32Type -> Values.Float32 (F32.of_string s) @@ at
| Types.Float64Type -> Values.Float64 (F64.of_string s) @@ at
with _ -> Error.error at "constant out of range"
with _ -> Error.error at "literal value out of range"


(* Symbolic variables *)
Expand Down Expand Up @@ -96,7 +96,7 @@ let anon_label c = {c with labels = VarMap.map ((+) 1) c.labels}
%token NOP BLOCK IF LOOP LABEL BREAK SWITCH CASE FALLTHROUGH
%token CALL CALLIMPORT CALLINDIRECT RETURN
%token GETLOCAL SETLOCAL LOAD STORE
%token CONST UNARY BINARY COMPARE CONVERT
%token LITERAL UNARY BINARY COMPARE CONVERT
%token FUNC PARAM RESULT LOCAL MODULE MEMORY SEGMENT IMPORT EXPORT TABLE
%token PAGESIZE MEMORYSIZE RESIZEMEMORY
%token ASSERTINVALID ASSERTEQ ASSERTTRAP INVOKE
Expand All @@ -107,7 +107,7 @@ let anon_label c = {c with labels = VarMap.map ((+) 1) c.labels}
%token<string> TEXT
%token<string> VAR
%token<Types.value_type> TYPE
%token<Types.value_type> CONST
%token<Types.value_type> LITERAL
%token<Types.value_type> SWITCH
%token<Ast.unop> UNARY
%token<Ast.binop> BINARY
Expand Down Expand Up @@ -183,7 +183,7 @@ oper :
| STORE expr expr { fun c -> Store ($1, $2 c, $3 c) }
| LOADEXTEND expr { fun c -> LoadExtend ($1, $2 c) }
| STORETRUNC expr expr { fun c -> StoreTrunc ($1, $2 c, $3 c) }
| CONST literal { let at = at() in fun c -> Const (literal at $2 $1) }
| LITERAL literal { let at = at() in fun c -> Literal (literal at $2 $1) }
| UNARY expr { fun c -> Unary ($1, $2 c) }
| BINARY expr expr { fun c -> Binary ($1, $2 c, $3 c) }
| COMPARE expr expr { fun c -> Compare ($1, $2 c, $3 c) }
Expand Down
2 changes: 1 addition & 1 deletion ml-proto/src/spec/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ and expr' =
| Store of memop * expr * expr
| LoadExtend of extendop * expr
| StoreTrunc of truncop * expr * expr
| Const of literal
| Literal of literal
| Unary of unop * expr
| Binary of binop * expr * expr
| Compare of relop * expr * expr
Expand Down
2 changes: 1 addition & 1 deletion ml-proto/src/spec/check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ let rec check_expr c et e =
check_mem_type truncop.memop.ty truncop.sz e.at;
check_store c et truncop.memop e1 e2 e.at

| Const v ->
| Literal v ->
check_literal c et v

| Unary (unop, e1) ->
Expand Down
2 changes: 1 addition & 1 deletion ml-proto/src/spec/eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ let rec eval_expr (c : config) (e : expr) =
with exn -> memory_error e.at exn);
None

| Const v ->
| Literal v ->
Some v.it

| Unary (unop, e1) ->
Expand Down
550 changes: 275 additions & 275 deletions ml-proto/test/conversions.wasm

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions ml-proto/test/exports.wasm
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
(module (func (i32.const 1)) (export "a" 0))
(module (func (i32.const 1)) (export "a" 0) (export "b" 0))
(module (func (i32.const 1)) (func (i32.const 2)) (export "a" 0) (export "b" 1))
(module (func (i32.literal 1)) (export "a" 0))
(module (func (i32.literal 1)) (export "a" 0) (export "b" 0))
(module (func (i32.literal 1)) (func (i32.literal 2)) (export "a" 0) (export "b" 1))
(assert_invalid
(module (func (i32.const 1)) (export "a" 1))
(module (func (i32.literal 1)) (export "a" 1))
"unknown function 1")
(assert_invalid
(module (func (i32.const 1)) (func (i32.const 2)) (export "a" 0) (export "a" 1))
(module (func (i32.literal 1)) (func (i32.literal 2)) (export "a" 0) (export "a" 1))
"duplicate export name")
(assert_invalid
(module (func (i32.const 1)) (export "a" 0) (export "a" 0))
(module (func (i32.literal 1)) (export "a" 0) (export "a" 0))
"duplicate export name")

(module
(func $f (param $n i32) (result i32)
(return (i32.add (get_local $n) (i32.const 1)))
(return (i32.add (get_local $n) (i32.literal 1)))
)

(export "e" $f)
)

(assert_eq (invoke "e" (i32.const 42)) (i32.const 43))
(assert_eq (invoke "e" (i32.literal 42)) (i32.literal 43))
32 changes: 16 additions & 16 deletions ml-proto/test/fac.wasm
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
(module
;; Recursive factorial
(func (param i64) (result i64)
(if (i64.eq (get_local 0) (i64.const 0))
(i64.const 1)
(i64.mul (get_local 0) (call 0 (i64.sub (get_local 0) (i64.const 1))))
(if (i64.eq (get_local 0) (i64.literal 0))
(i64.literal 1)
(i64.mul (get_local 0) (call 0 (i64.sub (get_local 0) (i64.literal 1))))
)
)

;; Recursive factorial named
(func $fac-rec (param $n i64) (result i64)
(if (i64.eq (get_local $n) (i64.const 0))
(i64.const 1)
(if (i64.eq (get_local $n) (i64.literal 0))
(i64.literal 1)
(i64.mul
(get_local $n)
(call $fac-rec (i64.sub (get_local $n) (i64.const 1)))
(call $fac-rec (i64.sub (get_local $n) (i64.literal 1)))
)
)
)
Expand All @@ -24,15 +24,15 @@
(func (param i64) (result i64)
(local i64 i64)
(set_local 1 (get_local 0))
(set_local 2 (i64.const 1))
(set_local 2 (i64.literal 1))
(label
(loop
(if
(i64.eq (get_local 1) (i64.const 0))
(i64.eq (get_local 1) (i64.literal 0))
(break 0)
(block
(set_local 2 (i64.mul (get_local 1) (get_local 2)))
(set_local 1 (i64.sub (get_local 1) (i64.const 1)))
(set_local 1 (i64.sub (get_local 1) (i64.literal 1)))
)
)
)
Expand All @@ -45,15 +45,15 @@
(local $i i64)
(local $res i64)
(set_local $i (get_local $n))
(set_local $res (i64.const 1))
(set_local $res (i64.literal 1))
(label $done
(loop
(if
(i64.eq (get_local $i) (i64.const 0))
(i64.eq (get_local $i) (i64.literal 0))
(break $done)
(block
(set_local $res (i64.mul (get_local $i) (get_local $res)))
(set_local $i (i64.sub (get_local $i) (i64.const 1)))
(set_local $i (i64.sub (get_local $i) (i64.literal 1)))
)
)
)
Expand All @@ -67,7 +67,7 @@
(export "fac-iter-named" $fac-iter)
)

(assert_eq (invoke "fac-rec" (i64.const 25)) (i64.const 7034535277573963776))
(assert_eq (invoke "fac-iter" (i64.const 25)) (i64.const 7034535277573963776))
(assert_eq (invoke "fac-rec-named" (i64.const 25)) (i64.const 7034535277573963776))
(assert_eq (invoke "fac-iter-named" (i64.const 25)) (i64.const 7034535277573963776))
(assert_eq (invoke "fac-rec" (i64.literal 25)) (i64.literal 7034535277573963776))
(assert_eq (invoke "fac-iter" (i64.literal 25)) (i64.literal 7034535277573963776))
(assert_eq (invoke "fac-rec-named" (i64.literal 25)) (i64.literal 7034535277573963776))
(assert_eq (invoke "fac-iter-named" (i64.literal 25)) (i64.literal 7034535277573963776))
32 changes: 16 additions & 16 deletions ml-proto/test/float32.wasm
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,42 @@

(assert_eq
(invoke "eq_float32"
(f32.add (f32.const 1.1234567890) (f32.const 1.2345e-10))
(f32.const 1.123456789)
(f32.add (f32.literal 1.1234567890) (f32.literal 1.2345e-10))
(f32.literal 1.123456789)
)
(i32.const 1)
(i32.literal 1)
)

(assert_eq
(invoke "eq_float64"
(f64.add (f64.const 1.1234567890) (f64.const 1.2345e-10))
(f64.const 1.123456789)
(f64.add (f64.literal 1.1234567890) (f64.literal 1.2345e-10))
(f64.literal 1.123456789)
)
(i32.const 0)
(i32.literal 0)
)

(assert_eq
(invoke "eq_float32"
(f32.mul (f32.const 1e20) (f32.const 1e20))
(f32.mul (f32.const 1e25) (f32.const 1e25))
(f32.mul (f32.literal 1e20) (f32.literal 1e20))
(f32.mul (f32.literal 1e25) (f32.literal 1e25))
)
(i32.const 1)
(i32.literal 1)
)

(assert_eq
(invoke "eq_float64"
(f64.mul (f64.const 1e20) (f64.const 1e20))
(f64.mul (f64.const 1e25) (f64.const 1e25))
(f64.mul (f64.literal 1e20) (f64.literal 1e20))
(f64.mul (f64.literal 1e25) (f64.literal 1e25))
)
(i32.const 0)
(i32.literal 0)
)

(assert_eq
(invoke "div_float32" (f32.const 1.123456789) (f32.const 100))
(f32.const 0.011234568432)
(invoke "div_float32" (f32.literal 1.123456789) (f32.literal 100))
(f32.literal 0.011234568432)
)

(assert_eq
(invoke "div_float64" (f64.const 1.123456789) (f64.const 100))
(f64.const 0.01123456789)
(invoke "div_float64" (f64.literal 1.123456789) (f64.literal 100))
(f64.literal 0.01123456789)
)
20 changes: 10 additions & 10 deletions ml-proto/test/forward.wasm
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
(export "odd" $odd)

(func $even (param $n i32) (result i32)
(if (i32.eq (get_local $n) (i32.const 0))
(i32.const 1)
(call $odd (i32.sub (get_local $n) (i32.const 1)))
(if (i32.eq (get_local $n) (i32.literal 0))
(i32.literal 1)
(call $odd (i32.sub (get_local $n) (i32.literal 1)))
)
)

(func $odd (param $n i32) (result i32)
(if (i32.eq (get_local $n) (i32.const 0))
(i32.const 0)
(call $even (i32.sub (get_local $n) (i32.const 1)))
(if (i32.eq (get_local $n) (i32.literal 0))
(i32.literal 0)
(call $even (i32.sub (get_local $n) (i32.literal 1)))
)
)
)

(assert_eq (invoke "even" (i32.const 13)) (i32.const 0))
(assert_eq (invoke "even" (i32.const 20)) (i32.const 1))
(assert_eq (invoke "odd" (i32.const 13)) (i32.const 1))
(assert_eq (invoke "odd" (i32.const 20)) (i32.const 0))
(assert_eq (invoke "even" (i32.literal 13)) (i32.literal 0))
(assert_eq (invoke "even" (i32.literal 20)) (i32.literal 1))
(assert_eq (invoke "odd" (i32.literal 13)) (i32.literal 1))
(assert_eq (invoke "odd" (i32.literal 20)) (i32.literal 0))
24 changes: 12 additions & 12 deletions ml-proto/test/hexnum.wasm
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
(module
(func $test32 (result i32)
(return (i32.const 0x0bAdD00D))
(return (i32.literal 0x0bAdD00D))
)

(func $max32 (result i32)
(return (i32.const 0xffffffff))
(return (i32.literal 0xffffffff))
)

(func $neg32 (result i32)
(return (i32.const -0x7fffffff))
(return (i32.literal -0x7fffffff))
)

(func $test64 (result i64)
(return (i64.const 0x0CABBA6E0ba66a6e))
(return (i64.literal 0x0CABBA6E0ba66a6e))
)

(func $max64 (result i64)
(return (i64.const 0xffffffffffffffff))
(return (i64.literal 0xffffffffffffffff))
)

(func $neg64 (result i64)
(return (i64.const -0x7fffffffffffffff))
(return (i64.literal -0x7fffffffffffffff))
)

(export "test32" $test32)
Expand All @@ -31,9 +31,9 @@
(export "neg64" $neg64)
)

(assert_eq (invoke "test32") (i32.const 195940365))
(assert_eq (invoke "max32") (i32.const -1))
(assert_eq (invoke "neg32") (i32.const -2147483647))
(assert_eq (invoke "test64") (i64.const 913028331277281902))
(assert_eq (invoke "max64") (i64.const -1))
(assert_eq (invoke "neg64") (i64.const -9223372036854775807))
(assert_eq (invoke "test32") (i32.literal 195940365))
(assert_eq (invoke "max32") (i32.literal -1))
(assert_eq (invoke "neg32") (i32.literal -2147483647))
(assert_eq (invoke "test64") (i64.literal 913028331277281902))
(assert_eq (invoke "max64") (i64.literal -1))
(assert_eq (invoke "neg64") (i64.literal -9223372036854775807))
Loading