Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[interpreter/test] Allow typeuse syntax for call_indirect #602

Merged
merged 2 commits into from Nov 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion interpreter/README.md
Expand Up @@ -211,7 +211,7 @@ op:
br_table <var>+
return
call <var>
call_indirect <var>
call_indirect <func_sig>
drop
select
get_local <var>
Expand Down
2 changes: 1 addition & 1 deletion interpreter/text/arrange.ml
Expand Up @@ -234,7 +234,7 @@ let rec instr e =
"br_table " ^ String.concat " " (list var (xs @ [x])), []
| Return -> "return", []
| Call x -> "call " ^ var x, []
| CallIndirect x -> "call_indirect " ^ var x, []
| CallIndirect x -> "call_indirect", [Node ("type " ^ var x, [])]
| Drop -> "drop", []
| Select -> "select", []
| GetLocal x -> "get_local " ^ var x, []
Expand Down
58 changes: 57 additions & 1 deletion interpreter/text/parser.mly
Expand Up @@ -294,6 +294,7 @@ align_opt :

instr :
| plain_instr { let at = at () in fun c -> [$1 c @@ at] }
| call_instr { fun c -> let e, es = $1 c in e :: es }
| block_instr { let at = at () in fun c -> [$1 c @@ at] }
| expr { $1 } /* Sugar */

Expand All @@ -307,7 +308,6 @@ plain_instr :
br_table xs x }
| RETURN { fun c -> return }
| CALL var { fun c -> call ($2 c func) }
| CALL_INDIRECT var { fun c -> call_indirect ($2 c type_) }
| DROP { fun c -> drop }
| SELECT { fun c -> select }
| GET_LOCAL var { fun c -> get_local ($2 c local) }
Expand All @@ -326,6 +326,35 @@ plain_instr :
| BINARY { fun c -> $1 }
| CONVERT { fun c -> $1 }

call_instr :
| CALL_INDIRECT call_instr_sig
{ let at1 = ati 1 in
fun c -> let x, es = $2 c in call_indirect x @@ at1, es }

call_instr_sig :
| type_use call_instr_params
{ let at1 = ati 1 in
fun c ->
match $2 c with
| FuncType ([], []), es -> $1 c type_, es
| ft, es -> inline_type_explicit c ($1 c type_) ft at1, es }
| call_instr_params
{ let at1 = ati 1 in
fun c -> let ft, es = $1 c in inline_type c ft at1, es }

call_instr_params :
| LPAR PARAM value_type_list RPAR call_instr_params
{ fun c ->
let FuncType (ts1, ts2), es = $5 c in FuncType ($3 @ ts1, ts2), es }
| call_instr_results
{ fun c -> let ts, es = $1 c in FuncType ([], ts), es }

call_instr_results :
| LPAR RESULT value_type_list RPAR call_instr_results
{ fun c -> let ts, es = $5 c in $3 @ ts, es }
| instr
{ fun c -> [], $1 c }

block_instr :
| BLOCK labeling_opt block END labeling_end_opt
{ fun c -> let c' = $2 c $5 in let ts, es = $3 c' in block ts es }
Expand All @@ -351,6 +380,8 @@ expr : /* Sugar */

expr1 : /* Sugar */
| plain_instr expr_list { fun c -> $2 c, $1 c }
| CALL_INDIRECT call_expr_sig
{ fun c -> let x, es = $2 c in es, call_indirect x }
| BLOCK labeling_opt block
{ fun c -> let c' = $2 c [] in let ts, es = $3 c' in [], block ts es }
| LOOP labeling_opt block
Expand All @@ -359,6 +390,31 @@ expr1 : /* Sugar */
{ fun c -> let c' = $2 c [] in
let ts, (es, es1, es2) = $3 c c' in es, if_ ts es1 es2 }

call_expr_sig :
| type_use call_expr_params
{ let at1 = ati 1 in
fun c ->
match $2 c with
| FuncType ([], []), es -> $1 c type_, es
| ft, es -> inline_type_explicit c ($1 c type_) ft at1, es }
| call_expr_params
{ let at1 = ati 1 in
fun c -> let ft, es = $1 c in inline_type c ft at1, es }

call_expr_params :
| LPAR PARAM value_type_list RPAR call_expr_params
{ fun c ->
let FuncType (ts1, ts2), es = $5 c in FuncType ($3 @ ts1, ts2), es }
| call_expr_results
{ fun c -> let ts, es = $1 c in FuncType ([], ts), es }

call_expr_results :
| LPAR RESULT value_type_list RPAR call_expr_results
{ fun c -> let ts, es = $5 c in $3 @ ts, es }
| expr_list
{ fun c -> [], $1 c }


if_block :
| block_sig if_block { fun c c' -> let ts, ess = $2 c c' in $1 @ ts, ess }
| if_ { fun c c' -> [], $1 c c' }
Expand Down
8 changes: 4 additions & 4 deletions test/core/br.wast
Expand Up @@ -147,31 +147,31 @@
(table anyfunc (elem $f))
(func (export "as-call_indirect-func") (result i32)
(block (result i32)
(call_indirect $sig
(call_indirect (type $sig)
(br 0 (i32.const 20))
(i32.const 1) (i32.const 2) (i32.const 3)
)
)
)
(func (export "as-call_indirect-first") (result i32)
(block (result i32)
(call_indirect $sig
(call_indirect (type $sig)
(i32.const 0)
(br 0 (i32.const 21)) (i32.const 2) (i32.const 3)
)
)
)
(func (export "as-call_indirect-mid") (result i32)
(block (result i32)
(call_indirect $sig
(call_indirect (type $sig)
(i32.const 0)
(i32.const 1) (br 0 (i32.const 22)) (i32.const 3)
)
)
)
(func (export "as-call_indirect-last") (result i32)
(block (result i32)
(call_indirect $sig
(call_indirect (type $sig)
(i32.const 0)
(i32.const 1) (i32.const 2) (br 0 (i32.const 23))
)
Expand Down
8 changes: 4 additions & 4 deletions test/core/br_table.wast
Expand Up @@ -989,31 +989,31 @@
(table anyfunc (elem $f))
(func (export "as-call_indirect-first") (result i32)
(block (result i32)
(call_indirect $sig
(call_indirect (type $sig)
(br_table 0 (i32.const 20) (i32.const 1)) (i32.const 1) (i32.const 2)
(i32.const 3)
)
)
)
(func (export "as-call_indirect-mid") (result i32)
(block (result i32)
(call_indirect $sig
(call_indirect (type $sig)
(i32.const 0) (br_table 0 (i32.const 21) (i32.const 1)) (i32.const 2)
(i32.const 3)
)
)
)
(func (export "as-call_indirect-last") (result i32)
(block (result i32)
(call_indirect $sig
(call_indirect (type $sig)
(i32.const 0) (i32.const 1) (br_table 0 (i32.const 22) (i32.const 1))
(i32.const 3)
)
)
)
(func (export "as-call_indirect-func") (result i32)
(block (result i32)
(call_indirect $sig
(call_indirect (type $sig)
(i32.const 0) (i32.const 1) (i32.const 2)
(br_table 0 (i32.const 23) (i32.const 1))
)
Expand Down