Skip to content

Commit 610ab30

Browse files
authored
Fix toplevel/*.ml (#293)
1 parent c87b2b0 commit 610ab30

File tree

4 files changed

+27
-61
lines changed

4 files changed

+27
-61
lines changed

toplevel/byte/topeval.ml

+8-40
Original file line numberDiff line numberDiff line change
@@ -47,51 +47,16 @@ module EvalBase = struct
4747

4848
let eval_compilation_unit cu =
4949
try
50-
Symtable.get_global_value
51-
(cu |> Compilation_unit.to_global_ident_for_bytecode)
52-
with Symtable.Error (Undefined_global name) ->
53-
raise (Undefined_global name)
50+
Symtable.get_global_value (Symtable.Global.of_compilation_unit cu)
51+
with Symtable.Error (Undefined_global global) ->
52+
raise (Undefined_global (Symtable.Global.name global))
5453

5554
let eval_ident id =
56-
<<<<<<< HEAD
5755
let name = Translmod.toplevel_name id in
5856
try
5957
String.Map.find name !toplevel_value_bindings
6058
with Not_found ->
6159
raise (Undefined_global name)
62-
||||||| 121bedcfd2
63-
if Ident.persistent id || Ident.global id then begin
64-
try
65-
Symtable.get_global_value id
66-
with Symtable.Error (Undefined_global name) ->
67-
raise (Undefined_global name)
68-
end else begin
69-
let name = Translmod.toplevel_name id in
70-
try
71-
String.Map.find name !toplevel_value_bindings
72-
with Not_found ->
73-
raise (Undefined_global name)
74-
end
75-
=======
76-
if Ident.global id then begin
77-
let name = Ident.name id in
78-
let global =
79-
if Ident.persistent id
80-
then Symtable.Global.Glob_compunit (Cmo_format.Compunit name)
81-
else Symtable.Global.Glob_predef (Cmo_format.Predef_exn name)
82-
in
83-
try
84-
Symtable.get_global_value global
85-
with Symtable.Error (Undefined_global _) ->
86-
raise (Undefined_global name)
87-
end else begin
88-
let name = Translmod.toplevel_name id in
89-
try
90-
String.Map.find name !toplevel_value_bindings
91-
with Not_found ->
92-
raise (Undefined_global name)
93-
end
94-
>>>>>>> 5.2.0
9560

9661
end
9762

@@ -304,8 +269,11 @@ and really_load_file recursive ppf name filename ic =
304269
| Reloc_getcompunit cu
305270
when not (Symtable.is_global_defined
306271
(Symtable.Global.Glob_compunit cu)) ->
307-
let file = (Symtable.Compunit.name cu) ^ ".cmo" in
308-
begin match Load_path.find_normalized file with
272+
let file =
273+
(Compilation_unit.Name.to_string (Compilation_unit.name cu))
274+
^ ".cmo"
275+
in
276+
begin match Load_path.find_uncap file with
309277
| exception Not_found -> ()
310278
| file ->
311279
if not (load_file recursive ppf file) then raise Load_failed

toplevel/expunge.ml

+12-16
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,36 @@
1717
Usage: expunge <source file> <dest file> <names of modules to keep> *)
1818

1919
open Misc
20-
module String = Misc.Stdlib.String
2120

22-
let to_keep = ref String.Set.empty
21+
let to_keep = ref Compilation_unit.Name.Set.empty
2322

2423
let negate = Sys.argv.(3) = "-v"
2524

25+
let keep0 name =
26+
if negate then not (Compilation_unit.Name.Set.mem name !to_keep)
27+
else (Compilation_unit.Name.Set.mem name !to_keep)
28+
2629
let keep = function
2730
| Symtable.Global.Glob_predef _ -> true
28-
| Symtable.Global.Glob_compunit (Cmo_format.Compunit name) ->
29-
if negate then not (String.Set.mem name !to_keep)
30-
else (String.Set.mem name !to_keep)
31+
| Symtable.Global.Glob_compunit cu ->
32+
let name = Compilation_unit.name cu in
33+
keep0 name
3134

3235
let expunge_map tbl =
3336
Symtable.filter_global_map keep tbl
3437

3538
let expunge_crcs tbl =
36-
<<<<<<< HEAD
3739
Array.to_list tbl
38-
|> List.filter
39-
(fun import ->
40-
keep (Import_info.name import |> Compilation_unit.Name.to_string))
40+
|> List.filter (fun import -> keep0 (Import_info.name import))
4141
|> Array.of_list
42-
||||||| 121bedcfd2
43-
List.filter (fun (unit, _crc) -> keep unit) tbl
44-
=======
45-
List.filter (fun (compunit, _crc) ->
46-
keep (Symtable.Global.Glob_compunit (Cmo_format.Compunit compunit))) tbl
47-
>>>>>>> 5.2.0
4842

4943
let main () =
5044
let input_name = Sys.argv.(1) in
5145
let output_name = Sys.argv.(2) in
5246
for i = (if negate then 4 else 3) to Array.length Sys.argv - 1 do
53-
to_keep := String.Set.add (Unit_info.modulize Sys.argv.(i)) !to_keep
47+
let modname = Unit_info.modulize Sys.argv.(i) in
48+
let cu_name = Compilation_unit.Name.of_string modname in
49+
to_keep := Compilation_unit.Name.Set.add cu_name !to_keep
5450
done;
5551
let ic = open_in_bin input_name in
5652
let toc = Bytesections.read_toc ic in

toplevel/topcommon.ml

+6-4
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,13 @@ let try_run_directive ppf dir_name pdir_arg =
408408
(* Overriding exception printers with toplevel-specific ones *)
409409

410410
let loading_hint_printer ppf cu =
411-
let global = Symtable.Global.Glob_compunit (Cmo_format.Compunit cu) in
411+
let global = Symtable.Global.Glob_compunit cu in
412412
Symtable.report_error ppf (Symtable.Undefined_global global);
413413
let find_with_ext ext =
414-
try Some (Load_path.find_normalized (cu ^ ext)) with Not_found -> None
414+
let leafname =
415+
(Compilation_unit.Name.to_string (Compilation_unit.name cu)) ^ ext
416+
in
417+
try Some (Load_path.find_uncap leafname) with Not_found -> None
415418
in
416419
fprintf ppf
417420
"@.Hint: @[\
@@ -441,8 +444,7 @@ let () =
441444
Location.register_error_of_exn
442445
(function
443446
| Symtable.Error
444-
(Symtable.Undefined_global (Symtable.Global.Glob_compunit
445-
(Cmo_format.Compunit cu))) ->
447+
(Symtable.Undefined_global (Symtable.Global.Glob_compunit cu)) ->
446448
Some (Location.error_of_printer_file loading_hint_printer cu)
447449
| _ -> None
448450
)

toplevel/topdirs.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ let _ = add_directive "directory" (Directive_string dir_directory)
9595
let dir_remove_directory s =
9696
let d = expand_directory Config.standard_library s in
9797
let keep id =
98-
match Load_path.find_normalized (Ident.name id ^ ".cmi") with
98+
match Load_path.find_uncap (Ident.name id ^ ".cmi") with
9999
| exception Not_found -> true
100100
| fn -> Filename.dirname fn <> d
101101
in

0 commit comments

Comments
 (0)