Skip to content

Commit

Permalink
Call_ref expects a type id, not a block type... (this breaks the
Browse files Browse the repository at this point in the history
implementation for now)
  • Loading branch information
zapashcanon committed Jul 30, 2023
1 parent f59d56a commit f97c247
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/interpret.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,12 @@ let exec_instr instr (state : State.exec_state) =
call_indirect ~return:false state (tbl_i, typ_i)
| Return_call_indirect (tbl_i, typ_i) ->
call_indirect ~return:true state (tbl_i, typ_i)
| Call_ref typ_i -> call_ref ~return:false state typ_i
| Call_ref _typ_i ->
(* TODO:
let t = Env.get_type typ_i in
*)
let t = ([], []) in
call_ref ~return:false state t
| Return_call_ref typ_i -> call_ref ~return:true state typ_i
| Array_new _t ->
let len, stack = Stack.pop_i32_to_int stack in
Expand Down
2 changes: 1 addition & 1 deletion src/menhir_parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ let plain_instr :=
| RETURN_CALL; ~ = indice; <Return_call>
| RETURN_CALL_REF; ~ = indice; { Return_call_ref (bt_ind indice) }
| CALL; ~ = indice; <Call>
| CALL_REF; ~ = indice; { Call_ref (bt_ind indice) }
| CALL_REF; ~ = indice; { Call_ref (indice) }
| LOCAL_GET; ~ = indice; <Local_get>
| LOCAL_SET; ~ = indice; <Local_set>
| LOCAL_TEE; ~ = indice; <Local_tee>
Expand Down
6 changes: 3 additions & 3 deletions src/rewrite.ml
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ let rewrite_expr (modul : Assigned.t) (locals : param list)
let* tbl_i = find_table (Some tbl_i) in
let* bt = bt_some_to_raw bt in
ok @@ Return_call_indirect (tbl_i, bt)
| Call_ref bt ->
let* bt = bt_some_to_raw bt in
ok @@ Call_ref bt
| Call_ref t ->
let* t = find_type (Some t) in
ok @@ Call_ref t
| Return_call_ref bt ->
let* bt = bt_some_to_raw bt in
ok @@ Return_call_ref bt
Expand Down
8 changes: 6 additions & 2 deletions src/typecheck.ml
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,13 @@ let rec typecheck_instr (env : env) (stack : stack) (instr : instr) :
let pt, rt = Env.func_get i env in
let* stack = Stack.pop (List.rev_map typ_of_pt pt) stack in
Stack.push (List.rev_map typ_of_val_type rt) stack
| Call_ref bt ->
| Call_ref _t ->
let* stack = Stack.pop_ref stack in
Stack.pop_push (Some bt) stack
(* TODO:
let bt = Env.type_get t env in
Stack.pop_push (Some bt) stack
*)
Ok stack
| Return_call i ->
let pt, rt = Env.func_get i env in
let* _stack = Stack.pop (List.rev_map typ_of_pt pt) stack in
Expand Down
4 changes: 2 additions & 2 deletions src/types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ struct
| Return_call_ref of block_type
| Call of indice
| Call_indirect of indice * block_type
| Call_ref of block_type
| Call_ref of indice
(* Array instructions *)
| Array_get of indice
| Array_get_u of indice
Expand Down Expand Up @@ -651,7 +651,7 @@ struct
| Call id -> Format.fprintf fmt "call %a" indice id
| Call_indirect (tbl_id, ty_id) ->
Format.fprintf fmt "call_indirect %a %a" indice tbl_id block_type ty_id
| Call_ref ty_id -> Format.fprintf fmt "call_ref %a" block_type ty_id
| Call_ref ty_id -> Format.fprintf fmt "call_ref %a" indice ty_id
| Array_new id -> Format.fprintf fmt "array.new %a" indice id
| Array_new_data (id1, id2) ->
Format.fprintf fmt "array.new_data %a %a" indice id1 indice id2
Expand Down

0 comments on commit f97c247

Please sign in to comment.