Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewagner committed Aug 25, 2015
1 parent 28b7283 commit c8af2a5
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 23 deletions.
1 change: 1 addition & 0 deletions ml-proto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ cmd:
<module> ;; define, validate, and initialize module
( invoke <name> <expr>* ) ;; invoke export and print result
( asserteq (invoke <name> <expr>* ) <expr>* ) ;; assert expected results of invocation
( assertinvalid <module> <failure> ) ;; assert invalid module with given failure string
```

Invocation is only possible after a module has been defined.
Expand Down
2 changes: 1 addition & 1 deletion ml-proto/src/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ rule token = parse
| "export" { EXPORT }
| "table" { TABLE }

| "invalid" { INVALID }
| "assertinvalid" { ASSERTINVALID }
| "invoke" { INVOKE }
| "asserteq" { ASSERTEQ }

Expand Down
6 changes: 3 additions & 3 deletions ml-proto/src/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ let anon_label c = {c with labels = VarMap.map ((+) 1) c.labels}
%token GETLOCAL SETLOCAL GETGLOBAL SETGLOBAL GETMEMORY SETMEMORY
%token CONST UNARY BINARY COMPARE CONVERT
%token FUNC PARAM RESULT LOCAL MODULE MEMORY SEGMENT GLOBAL IMPORT EXPORT TABLE
%token INVALID INVOKE ASSERTEQ
%token ASSERTINVALID INVOKE ASSERTEQ
%token EOF

%token<string> INT
Expand Down Expand Up @@ -308,11 +308,11 @@ modul :
cmd :
| modul { Define $1 @@ at() }
| LPAR INVALID modul TEXT RPAR { Invalid ($3, $4) @@ at() }
| LPAR ASSERTINVALID modul TEXT RPAR { AssertInvalid ($3, $4) @@ at() }
| LPAR INVOKE TEXT expr_list RPAR
{ Invoke ($3, $4 (c0 ())) @@ at() }
| LPAR ASSERTEQ LPAR INVOKE TEXT expr_list RPAR expr_list RPAR
{ AssertEqInvoke ($5, $6 (c0 ()), $8 (c0 ())) @@ at() }
{ AssertEq ($5, $6 (c0 ()), $8 (c0 ())) @@ at() }
;
cmd_list :
| /* empty */ { [] }
Expand Down
17 changes: 9 additions & 8 deletions ml-proto/src/script.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ open Source
type command = command' phrase
and command' =
| Define of Ast.modul
| Invalid of Ast.modul * string
| AssertInvalid of Ast.modul * string
| Invoke of string * Ast.expr list
| AssertEqInvoke of string * Ast.expr list * Ast.expr list
| AssertEq of string * Ast.expr list * Ast.expr list

type script = command list

Expand All @@ -34,14 +34,15 @@ let run_command cmd =
trace "Initializing...";
current_module := Some (Eval.init m)

| Invalid (m, re) ->
| AssertInvalid (m, re) ->
trace "Checking invalid...";
(match try Check.check_module m; None with Error.Error (at, s) -> Some s with
(match try Check.check_module m; None with Error.Error (_, s) -> Some s with
| None ->
Error.error cmd.at "expected invalid module"
| Some s ->
if not (Str.string_match (Str.regexp re) s 0) then
Error.error cmd.at ("validation failure \"" ^ s ^ "\" does not match: " ^ re))
Error.error cmd.at
("validation failure \"" ^ s ^ "\" does not match: \"" ^ re ^ "\""))

| Invoke (name, es) ->
trace "Invoking...";
Expand All @@ -53,7 +54,7 @@ let run_command cmd =
let vs' = Eval.invoke m name vs in
if vs' <> [] then Print.print_values vs'

| AssertEqInvoke (name, arg_es, expect_es) ->
| AssertEq (name, arg_es, expect_es) ->
trace "Assert invoking...";
let m = match !current_module with
| Some m -> m
Expand All @@ -75,9 +76,9 @@ let dry_command cmd =
| Define m ->
Check.check_module m;
if !Flags.print_sig then Print.print_module_sig m
| Invalid (m, re) -> ()
| AssertInvalid _ -> ()
| Invoke _ -> ()
| AssertEqInvoke _ -> ()
| AssertEq _ -> ()

let run script =
List.iter (if !Flags.dry then dry_command else run_command) script
4 changes: 2 additions & 2 deletions ml-proto/src/script.mli
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
type command = command' Source.phrase
and command' =
| Define of Ast.modul
| Invalid of Ast.modul * string
| AssertInvalid of Ast.modul * string
| Invoke of string * Ast.expr list
| AssertEqInvoke of string * Ast.expr list * Ast.expr list
| AssertEq of string * Ast.expr list * Ast.expr list

type script = command list

Expand Down
6 changes: 3 additions & 3 deletions ml-proto/test/exports.wasm
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
(module (func (const.i32 1)) (export "a" 0))
(module (func (const.i32 1)) (export "a" 0) (export "b" 0))
(module (func (const.i32 1)) (func (const.i32 2)) (export "a" 0) (export "b" 1))
(invalid
(assertinvalid
(module (func (const.i32 1)) (export "a" 1))
"unknown function 1")
(invalid
(assertinvalid
(module (func (const.i32 1)) (func (const.i32 2)) (export "a" 0) (export "a" 1))
"duplicate export name")
(invalid
(assertinvalid
(module (func (const.i32 1)) (export "a" 0) (export "a" 0))
"duplicate export name")

Expand Down
12 changes: 6 additions & 6 deletions ml-proto/test/memory.wasm
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
(module (memory 1 1 (segment 0 "a")))
(module (memory 100 1000 (segment 0 "a") (segment 99 "b")))
(module (memory 100 1000 (segment 0 "a") (segment 1 "b") (segment 2 "c")))
(invalid
(assertinvalid
(module (memory 1 0))
"initial memory size must be less than maximum")
(invalid
(assertinvalid
(module (memory 0 0 (segment 0 "a")))
"data segment does not fit memory")
(invalid
(assertinvalid
(module (memory 100 1000 (segment 0 "a") (segment 500 "b")))
"data segment does not fit memory")
(invalid
(assertinvalid
(module (memory 100 1000 (segment 0 "abc") (segment 0 "def")))
"data segment not disjoint and ordered")
(invalid
(assertinvalid
(module (memory 100 1000 (segment 3 "ab") (segment 0 "de")))
"data segment not disjoint and ordered")
(invalid
(assertinvalid
(module (memory 100 1000 (segment 0 "a") (segment 2 "b") (segment 1 "c")))
"data segment not disjoint and ordered")

Expand Down

0 comments on commit c8af2a5

Please sign in to comment.