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

Tweaks for js_of_ocaml #10

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading