Skip to content

Commit

Permalink
Tweaks for non-{bytecode,native} backends
Browse files Browse the repository at this point in the history
In other backends (e.g. js_of_ocaml), closures might not be
inspectable (in jsoo they are javascript closures), so treat them as
abstract.
  • Loading branch information
Armael committed Jan 19, 2024
1 parent 8231c05 commit bdf2b9e
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/core/repr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ let mk_block addr tag data =
Some important points:
- we need to keep track of the values that we have already translated,
in order to not loop on cyclic values, and to faithfully represent
sharing. This is donne using an association list.
sharing. This is done using an association list.
- Some tags must be singled out (see comments inside function).
*)
let rec mk_val assoc addr v =
Expand Down Expand Up @@ -203,12 +203,9 @@ let rec mk_val assoc addr v =
(fun i -> Double (Obj.double_field v i))
in
Fields a, assoc
else if tag = Obj.closure_tag then begin
(* Out of heap pointers (such as code pointers), must be accessed using
[raw_field], to avoid the Gc following them, and thus segfaults. *)
let assoc, fields = mk_closure_fields assoc v (Obj.size v) 0 [] in
Fields (Array.of_list (List.rev fields)), assoc
end else if tag < Obj.no_scan_tag then begin
else if tag = Obj.closure_tag then
mk_closure v assoc
else if tag < Obj.no_scan_tag then begin
(* General case, we parse an array of fields. *)
let tmp = ref assoc in
(* Format.eprintf "block size (%d): %d@." tag (Obj.size v); *)
Expand All @@ -227,6 +224,17 @@ let rec mk_val assoc addr v =
(v, addr) :: assoc
end

and mk_closure v assoc =
match Sys.backend_type with
| Native | Bytecode ->
(* Out of heap pointers (such as code pointers), must be accessed using
[raw_field], to avoid the Gc following them and segfault. *)
let assoc, fields = mk_closure_fields assoc v (Obj.size v) 0 [] in
Fields (Array.of_list (List.rev fields)), assoc
| Other _ ->
(* Don't attempt to inspect closures on other backends (e.g. js_of_ocaml) *)
Abstract, assoc

and mk_closinfo v offset =
let field = Obj.field v offset in
assert (Obj.is_int field);
Expand Down

0 comments on commit bdf2b9e

Please sign in to comment.