Skip to content

Commit

Permalink
refactor pp functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zapashcanon committed Nov 25, 2023
1 parent e081858 commit 7600364
Show file tree
Hide file tree
Showing 12 changed files with 453 additions and 456 deletions.
4 changes: 2 additions & 2 deletions src/interpret.ml
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ module Make (P : Interpret_functor_intf.P) :
let locals = state.locals in
let st stack = Choice.return (State.Continue { state with stack }) in
Log.debug2 "stack : [ %a ]@." Stack.pp stack;
Log.debug2 "running instr: %a@." Types.Pp.instr instr;
Log.debug2 "running instr: %a@." Types.pp_instr instr;
match instr with
| Return -> Choice.return (State.return state)
| Nop -> Choice.return (State.Continue state)
Expand Down Expand Up @@ -1496,7 +1496,7 @@ module Make (P : Interpret_functor_intf.P) :
| Struct_new_default _ | Extern_externalize | Extern_internalize
| Ref_as_non_null | Ref_cast _ | Ref_test _ | Ref_eq | Br_on_cast _
| Br_on_cast_fail _ | Br_on_non_null _ | Br_on_null _ ) as i ->
Log.debug2 "TODO (Interpret.exec_instr) %a@\n" Types.Pp.instr i;
Log.debug2 "TODO (Interpret.exec_instr) %a@\n" Types.pp_instr i;
st stack

let rec loop (state : State.exec_state) =
Expand Down
4 changes: 2 additions & 2 deletions src/link.ml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ let load_memory (ls : 'f state) (import : limits Imported.t) :
if limit_is_included ~import:import.desc ~imported:imported_limit then Ok mem
else
error_s "incompatible import type for memory %s %s expected %a got %a"
import.modul import.name Pp.limits import.desc Pp.limits imported_limit
import.modul import.name pp_limits import.desc pp_limits imported_limit

let eval_memory ls (memory : (mem, limits) Runtime.t) :
Concrete_memory.t Result.t =
Expand Down Expand Up @@ -150,7 +150,7 @@ let load_table (ls : 'f state) (import : simplified table_type Imported.t) :
if table_types_are_compatible typ (t.limits, t.typ) then Ok t
else
error_s "incompatible import type for table %s %s expected %a got %a"
import.modul import.name Pp.table_type typ Pp.table_type (t.limits, t.typ)
import.modul import.name pp_table_type typ pp_table_type (t.limits, t.typ)

let eval_table ls (table : (_, simplified table_type) Runtime.t) :
table Result.t =
Expand Down
8 changes: 4 additions & 4 deletions src/menhir_parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ let func ==
| MExport e -> MExport { e with desc = Export_func func_id }
| MFunc f -> MFunc { f with id }
| MData _ | MElem _ | MGlobal _ | MStart _ | MType _ | MTable _ | MMem _ as field -> begin
Format.pp_err "got invalid field: `%a`@." Pp.module_field field;
Format.pp_err "got invalid field: `%a`@." pp_module_field field;
assert false
end
) func_fields
Expand Down Expand Up @@ -875,7 +875,7 @@ let table ==
| Import_func _ | Import_global _ | Import_mem _ -> assert false
end
| MMem _ | MData _ | MStart _ | MFunc _ | MGlobal _ | MType _ as field -> begin
Format.pp_err "got invalid field: `%a`@." Pp.module_field field;
Format.pp_err "got invalid field: `%a`@." pp_module_field field;
assert false
end
) table_fields
Expand Down Expand Up @@ -922,7 +922,7 @@ let memory ==
| Import_table _ | Import_func _ | Import_global _ -> assert false
end
| MElem _ | MType _ | MTable _ | MFunc _ | MGlobal _ | MStart _ as field -> begin
Format.pp_err "got invalid field: `%a`@." Pp.module_field field;
Format.pp_err "got invalid field: `%a`@." pp_module_field field;
assert false
end
) memory_fields
Expand Down Expand Up @@ -957,7 +957,7 @@ let global ==
| Import_mem _ | Import_table _ | Import_func _ -> assert false
end
| MStart _ | MFunc _ | MData _ | MElem _ | MMem _ | MTable _ | MType _ as field -> begin
Format.pp_err "got invalid field: `%a`@." Pp.module_field field;
Format.pp_err "got invalid field: `%a`@." pp_module_field field;
assert false
end
) global_fields
Expand Down
5 changes: 2 additions & 3 deletions src/rewrite.ml
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ let rewrite_expr (modul : Assigned.t) (locals : simplified param list)
| ( Array_new_data _ | Array_new _ | Array_new_elem _ | Array_new_fixed _
| Array_get_u _ | Struct_get _ | Struct_get_s _ | Struct_set _
| Struct_new _ | Br_on_non_null _ | Br_on_null _ ) as i ->
Log.debug2 "TODO (Rewrite.body) %a@\n" Text.Pp.instr i;
Log.debug2 "TODO (Rewrite.body) %a@\n" pp_instr i;
Ok Nop
and expr (e : text expr) (loop_count, block_ids) : simplified expr Result.t =
list_map (fun i -> body (loop_count, block_ids) i) e
Expand Down Expand Up @@ -391,8 +391,7 @@ let rewrite_const_expr (modul : Assigned.t) (expr : text expr) :
Array_new_default t
| Ref_i31 -> Ok Ref_i31
| i ->
error
@@ Format.asprintf "constant expression required, got %a" Text.Pp.instr i
error @@ Format.asprintf "constant expression required, got %a" pp_instr i
in
list_map const_instr expr

Expand Down
6 changes: 3 additions & 3 deletions src/script.ml
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ let value_of_const : text const -> V.t Result.t = function
Concrete_value.ref_null rt
| Const_extern i -> ok @@ Concrete_value.Ref (Host_externref.value i)
| i ->
Log.debug2 "TODO (Script.value_of_const) %a@\n" Text.Pp.const i;
Log.debug2 "TODO (Script.value_of_const) %a@\n" Types.pp_const i;
assert false

let action (link_state : Concrete_value.Func.extern_func Link.state) = function
| Text.Invoke (mod_id, f, args) -> begin
Log.debug5 "invoke %a %s %a...@\n"
(Format.pp_option ~none:Format.pp_nothing Format.pp_string)
mod_id f Text.Pp.consts args;
mod_id f Types.pp_consts args;
let* f, env_id = load_func_from_module link_state mod_id f in
let* stack = list_map value_of_const args in
let stack = List.rev stack in
Expand Down Expand Up @@ -222,7 +222,7 @@ let run ~no_exhaustion ~optimize script =
|| not (List.for_all2 compare_result_const res (List.rev stack))
then begin
Format.pp_err "got: %[email protected]: %a@." Stack.pp (List.rev stack)
Text.Pp.results res;
Text.pp_results res;
Error "Bad result"
end
else Ok link_state
Expand Down
2 changes: 1 addition & 1 deletion src/simplified.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module Pp = struct
let id fmt = Option.iter (fun id -> pp fmt " $%s" id)

let func fmt = function
| Runtime.Local f -> Types.Pp.func fmt f
| Runtime.Local f -> pp_func fmt f
| Runtime.Imported { Imported.modul; name; _ } -> pp fmt "%s.%s" modul name

let lst f fmt l = (pp_list ~pp_sep:pp_newline f) fmt (List.rev l)
Expand Down
Loading

0 comments on commit 7600364

Please sign in to comment.