Skip to content

Commit

Permalink
Rename assert_fault to assert_trap to match design repo terminology
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewagner committed Sep 17, 2015
1 parent 1888885 commit e343cdb
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion ml-proto/src/host/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ rule token = parse

| "assert_invalid" { ASSERTINVALID }
| "assert_eq" { ASSERTEQ }
| "assert_fault" { ASSERTFAULT }
| "assert_trap" { ASSERTTRAP }
| "invoke" { INVOKE }

| name as s { VAR s }
Expand Down
6 changes: 3 additions & 3 deletions ml-proto/src/host/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ let anon_label c = {c with labels = VarMap.map ((+) 1) c.labels}
%token GETLOCAL SETLOCAL LOADGLOBAL STOREGLOBAL LOAD STORE
%token CONST UNARY BINARY COMPARE CONVERT
%token FUNC PARAM RESULT LOCAL MODULE MEMORY SEGMENT GLOBAL IMPORT EXPORT TABLE
%token ASSERTINVALID ASSERTEQ ASSERTFAULT INVOKE
%token ASSERTINVALID ASSERTEQ ASSERTTRAP INVOKE
%token EOF

%token<string> INT
Expand Down Expand Up @@ -348,8 +348,8 @@ cmd :
{ Invoke ($3, $4 (c0 ())) @@ at() }
| LPAR ASSERTEQ LPAR INVOKE TEXT expr_list RPAR expr RPAR
{ AssertEq ($5, $6 (c0 ()), $8 (c0 ())) @@ at() }
| LPAR ASSERTFAULT LPAR INVOKE TEXT expr_list RPAR TEXT RPAR
{ AssertFault ($5, $6 (c0 ()), $8) @@ at() }
| LPAR ASSERTTRAP LPAR INVOKE TEXT expr_list RPAR TEXT RPAR
{ AssertTrap ($5, $6 (c0 ()), $8) @@ at() }
;
cmd_list :
| /* empty */ { [] }
Expand Down
10 changes: 5 additions & 5 deletions ml-proto/src/host/script.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ and command' =
| AssertInvalid of Ast.modul * string
| Invoke of string * Ast.expr list
| AssertEq of string * Ast.expr list * Ast.expr
| AssertFault of string * Ast.expr list * string
| AssertTrap of string * Ast.expr list * string

type script = command list

Expand Down Expand Up @@ -82,14 +82,14 @@ let run_command cmd =
Error.error cmd.at "assertion failed"
end

| AssertFault (name, es, re) ->
trace "Assert fault invoking...";
| AssertTrap (name, es, re) ->
trace "Assert trap invoking...";
let m = match !current_module with
| Some m -> m
| None -> Error.error cmd.at "no module defined to invoke"
in
let vs = eval_args es cmd.at in
assert_error (fun () -> Eval.invoke m name vs) "fault" re cmd.at
assert_error (fun () -> Eval.invoke m name vs) "trap" re cmd.at

let dry_command cmd =
match cmd.it with
Expand All @@ -99,7 +99,7 @@ let dry_command cmd =
| AssertInvalid _ -> ()
| Invoke _ -> ()
| AssertEq _ -> ()
| AssertFault _ -> ()
| AssertTrap _ -> ()

let run script =
List.iter (if !Flags.dry then dry_command else run_command) script
2 changes: 1 addition & 1 deletion ml-proto/src/host/script.mli
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and command' =
| AssertInvalid of Ast.modul * string
| Invoke of string * Ast.expr list
| AssertEq of string * Ast.expr list * Ast.expr
| AssertFault of string * Ast.expr list * string
| AssertTrap of string * Ast.expr list * string

type script = command list

Expand Down
18 changes: 0 additions & 18 deletions ml-proto/test/memory_fault.wasm

This file was deleted.

18 changes: 18 additions & 0 deletions ml-proto/test/memory_trap.wasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(module
(memory 100)

(export "store" $store)
(func $store (param $i i32) (param $v i32) (i32.store (get_local $i) (get_local $v)))

(export "load" $load)
(func $load (param $i i32) (result i32) (i32.load (get_local $i)))
)

(invoke "store" (i32.const 96) (i32.const 42))
(assert_eq (invoke "load" (i32.const 96)) (i32.const 42))
(assert_trap (invoke "store" (i32.const 97) (i32.const 13)) "runtime: out of bounds memory access")
(assert_trap (invoke "load" (i32.const 97)) "runtime: out of bounds memory access")
(assert_trap (invoke "store" (i32.const 98) (i32.const 13)) "runtime: out of bounds memory access")
(assert_trap (invoke "load" (i32.const 98)) "runtime: out of bounds memory access")
(assert_trap (invoke "store" (i32.const 99) (i32.const 13)) "runtime: out of bounds memory access")
(assert_trap (invoke "load" (i32.const 99)) "runtime: out of bounds memory access")

0 comments on commit e343cdb

Please sign in to comment.