Skip to content

Commit 50c37ff

Browse files
authored
Make bytecomp/*.ml build (#288)
1 parent 4b51c3f commit 50c37ff

File tree

14 files changed

+190
-767
lines changed

14 files changed

+190
-767
lines changed

bytecomp/bytegen.ml

Lines changed: 11 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ let add_pseudo_event loc modname c =
291291
let ev_defname = string_of_scoped_location loc in
292292
let ev =
293293
{ ev_pos = 0; (* patched in emitcode *)
294-
ev_module = modname;
294+
ev_module = Compilation_unit.full_path_as_string modname;
295295
ev_loc = to_location loc;
296296
ev_defname;
297297
ev_kind = Event_pseudo;
@@ -363,7 +363,7 @@ let functions_to_compile = (Stack.create () : function_to_compile Stack.t)
363363

364364
(* Name of current compilation unit (for debugging events) *)
365365

366-
let compunit_name = ref ""
366+
let compunit_name = ref Compilation_unit.dummy
367367

368368
let check_stack stack_info sz =
369369
let curr = stack_info.max_stack_used in
@@ -395,11 +395,9 @@ let array_primitive (index_kind : Lambda.array_index_kind) prefix =
395395
let comp_primitive stack_info p sz args =
396396
check_stack stack_info sz;
397397
match p with
398-
Pgetglobal cu ->
399-
Kgetglobal (cu |> Compilation_unit.to_global_ident_for_bytecode)
400-
| Psetglobal cu ->
401-
Ksetglobal (cu |> Compilation_unit.to_global_ident_for_bytecode)
402-
| Pgetpredef id -> Kgetglobal id
398+
Pgetglobal cu -> Kgetglobal cu
399+
| Psetglobal cu -> Ksetglobal cu
400+
| Pgetpredef id -> Kgetpredef id
403401
| Pintcomp cmp -> Kintcomp cmp
404402
| Pcompare_ints -> Kccall("caml_int_compare", 2)
405403
| Pcompare_floats Pfloat64 -> Kccall("caml_float_compare", 2)
@@ -709,16 +707,8 @@ let rec comp_expr stack_info env exp sz cont =
709707
let fv = Ident.Set.elements(free_variables exp) in
710708
let entries = closure_entries Single_non_recursive fv in
711709
let to_compile =
712-
<<<<<<< HEAD
713710
{ params = List.map (fun p -> p.name) params; body = body; label = lbl;
714-
free_vars = fv; num_defs = 1; rec_vars = []; rec_pos = 0 } in
715-
||||||| 121bedcfd2
716-
{ params = List.map fst params; body = body; label = lbl;
717-
free_vars = fv; num_defs = 1; rec_vars = []; rec_pos = 0 } in
718-
=======
719-
{ params = List.map fst params; body = body; label = lbl;
720711
entries = entries; rec_pos = 0 } in
721-
>>>>>>> 5.2.0
722712
Stack.push to_compile functions_to_compile;
723713
comp_args stack_info env (List.map (fun n -> Lvar n) fv) sz
724714
(Kclosure(lbl, List.length fv) :: cont)
@@ -729,18 +719,19 @@ let rec comp_expr stack_info env exp sz cont =
729719
(add_pop 1 cont))
730720
| Lletrec(decl, body) ->
731721
let ndecl = List.length decl in
732-
<<<<<<< HEAD
733722
let fv =
734723
Ident.Set.elements (free_variables (Lletrec(decl, lambda_unit))) in
735724
let rec_idents = List.map (fun { id } -> id) decl in
725+
let entries =
726+
closure_entries (Multiple_recursive rec_idents) fv
727+
in
736728
let rec comp_fun pos = function
737729
[] -> []
738730
| { def = {params; body} } :: rem ->
739731
let lbl = new_label() in
740732
let to_compile =
741733
{ params = List.map (fun p -> p.name) params; body = body; label = lbl;
742-
free_vars = fv; num_defs = ndecl; rec_vars = rec_idents;
743-
rec_pos = pos} in
734+
entries = entries; rec_pos = pos} in
744735
Stack.push to_compile functions_to_compile;
745736
lbl :: comp_fun (pos + 1) rem
746737
in
@@ -756,107 +747,6 @@ let rec comp_expr stack_info env exp sz cont =
756747
| Punbox_float (Pfloat64 | Pfloat32)), [arg], _) ->
757748
comp_expr stack_info env arg sz cont
758749
| Lprim((Pbox_int _ | Punbox_int _), [arg], _) ->
759-
||||||| 121bedcfd2
760-
if List.for_all (function (_, Lfunction _) -> true | _ -> false)
761-
decl then begin
762-
(* let rec of functions *)
763-
let fv =
764-
Ident.Set.elements (free_variables (Lletrec(decl, lambda_unit))) in
765-
let rec_idents = List.map (fun (id, _lam) -> id) decl in
766-
let rec comp_fun pos = function
767-
[] -> []
768-
| (_id, Lfunction{params; body}) :: rem ->
769-
let lbl = new_label() in
770-
let to_compile =
771-
{ params = List.map fst params; body = body; label = lbl;
772-
free_vars = fv; num_defs = ndecl; rec_vars = rec_idents;
773-
rec_pos = pos} in
774-
Stack.push to_compile functions_to_compile;
775-
lbl :: comp_fun (pos + 1) rem
776-
| _ -> assert false in
777-
let lbls = comp_fun 0 decl in
778-
comp_args stack_info env (List.map (fun n -> Lvar n) fv) sz
779-
(Kclosurerec(lbls, List.length fv) ::
780-
(comp_expr stack_info
781-
(add_vars rec_idents (sz+1) env) body (sz + ndecl)
782-
(add_pop ndecl cont)))
783-
end else begin
784-
let decl_size =
785-
List.map (fun (id, exp) -> (id, exp, size_of_lambda Ident.empty exp))
786-
decl in
787-
let rec comp_init new_env sz = function
788-
| [] -> comp_nonrec new_env sz ndecl decl_size
789-
| (id, _exp, RHS_floatblock blocksize) :: rem ->
790-
Kconst(Const_base(Const_int blocksize)) ::
791-
Kccall("caml_alloc_dummy_float", 1) :: Kpush ::
792-
comp_init (add_var id (sz+1) new_env) (sz+1) rem
793-
| (id, _exp, RHS_block blocksize) :: rem ->
794-
Kconst(Const_base(Const_int blocksize)) ::
795-
Kccall("caml_alloc_dummy", 1) :: Kpush ::
796-
comp_init (add_var id (sz+1) new_env) (sz+1) rem
797-
| (id, _exp, RHS_infix { blocksize; offset }) :: rem ->
798-
Kconst(Const_base(Const_int offset)) ::
799-
Kpush ::
800-
Kconst(Const_base(Const_int blocksize)) ::
801-
Kccall("caml_alloc_dummy_infix", 2) :: Kpush ::
802-
comp_init (add_var id (sz+1) new_env) (sz+1) rem
803-
| (id, _exp, RHS_function (blocksize,arity)) :: rem ->
804-
Kconst(Const_base(Const_int arity)) ::
805-
Kpush ::
806-
Kconst(Const_base(Const_int blocksize)) ::
807-
Kccall("caml_alloc_dummy_function", 2) :: Kpush ::
808-
comp_init (add_var id (sz+1) new_env) (sz+1) rem
809-
| (id, _exp, RHS_nonrec) :: rem ->
810-
Kconst(Const_base(Const_int 0)) :: Kpush ::
811-
comp_init (add_var id (sz+1) new_env) (sz+1) rem
812-
and comp_nonrec new_env sz i = function
813-
| [] -> comp_rec new_env sz ndecl decl_size
814-
| (_id, _exp, (RHS_block _ | RHS_infix _ |
815-
RHS_floatblock _ | RHS_function _))
816-
:: rem ->
817-
comp_nonrec new_env sz (i-1) rem
818-
| (_id, exp, RHS_nonrec) :: rem ->
819-
comp_expr stack_info new_env exp sz
820-
(Kassign (i-1) :: comp_nonrec new_env sz (i-1) rem)
821-
and comp_rec new_env sz i = function
822-
| [] -> comp_expr stack_info new_env body sz (add_pop ndecl cont)
823-
| (_id, exp, (RHS_block _ | RHS_infix _ |
824-
RHS_floatblock _ | RHS_function _))
825-
:: rem ->
826-
comp_expr stack_info new_env exp sz
827-
(Kpush :: Kacc i :: Kccall("caml_update_dummy", 2) ::
828-
comp_rec new_env sz (i-1) rem)
829-
| (_id, _exp, RHS_nonrec) :: rem ->
830-
comp_rec new_env sz (i-1) rem
831-
in
832-
comp_init env sz decl_size
833-
end
834-
| Lprim(Popaque, [arg], _) ->
835-
=======
836-
let fv =
837-
Ident.Set.elements (free_variables (Lletrec(decl, lambda_unit))) in
838-
let rec_idents = List.map (fun { id } -> id) decl in
839-
let entries =
840-
closure_entries (Multiple_recursive rec_idents) fv
841-
in
842-
let rec comp_fun pos = function
843-
[] -> []
844-
| { def = {params; body} } :: rem ->
845-
let lbl = new_label() in
846-
let to_compile =
847-
{ params = List.map fst params; body = body; label = lbl;
848-
entries = entries; rec_pos = pos} in
849-
Stack.push to_compile functions_to_compile;
850-
lbl :: comp_fun (pos + 1) rem
851-
in
852-
let lbls = comp_fun 0 decl in
853-
comp_args stack_info env (List.map (fun n -> Lvar n) fv) sz
854-
(Kclosurerec(lbls, List.length fv) ::
855-
(comp_expr stack_info
856-
(add_vars rec_idents (sz+1) env) body (sz + ndecl)
857-
(add_pop ndecl cont)))
858-
| Lprim(Popaque, [arg], _) ->
859-
>>>>>>> 5.2.0
860750
comp_expr stack_info env arg sz cont
861751
| Lprim(Pignore, [arg], _) ->
862752
comp_expr stack_info env arg sz (add_const_unit cont)
@@ -1186,7 +1076,7 @@ let rec comp_expr stack_info env exp sz cont =
11861076
let ev_defname = string_of_scoped_location lev.lev_loc in
11871077
let event kind info =
11881078
{ ev_pos = 0; (* patched in emitcode *)
1189-
ev_module = !compunit_name;
1079+
ev_module = Compilation_unit.full_path_as_string !compunit_name;
11901080
ev_loc = to_location lev.lev_loc;
11911081
ev_kind = kind;
11921082
ev_defname;
@@ -1353,7 +1243,7 @@ let comp_remainder cont =
13531243

13541244
let reset () =
13551245
label_counter := 0;
1356-
compunit_name := "";
1246+
compunit_name := Compilation_unit.dummy;
13571247
Stack.clear functions_to_compile
13581248

13591249
let compile_gen ?modulename ~init_stack expr =

bytecomp/bytegen.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
open Lambda
1919
open Instruct
2020

21-
val compile_implementation: string -> lambda -> instruction list
21+
val compile_implementation: Compilation_unit.t -> lambda -> instruction list
2222
val compile_phrase: lambda -> instruction list * bool
2323

2424
val merge_events:

0 commit comments

Comments
 (0)