Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemaurer committed Nov 15, 2024
1 parent 34192ef commit 025c20b
Show file tree
Hide file tree
Showing 17 changed files with 306 additions and 138 deletions.
26 changes: 26 additions & 0 deletions asmcomp/asminstantiator.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
(**********************************************************************************
* MIT License *
* *
* *
* Copyright (c) 2019-2024 Jane Street Group LLC *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy *
* of this software and associated documentation files (the "Software"), to deal *
* in the Software without restriction, including without limitation the rights *
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in all *
* copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
* SOFTWARE. *
* *
**********************************************************************************)

let read_unit_info file : Instantiator.unit_info =
let unit_info, _crc = Compilenv.read_unit_info file in
let { Cmx_format.ui_unit; ui_arg_descr; ui_format; _ } = unit_info in
Expand Down
26 changes: 26 additions & 0 deletions asmcomp/asminstantiator.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
(**********************************************************************************
* MIT License *
* *
* *
* Copyright (c) 2019-2024 Jane Street Group LLC *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy *
* of this software and associated documentation files (the "Software"), to deal *
* in the Software without restriction, including without limitation the rights *
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in all *
* copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
* SOFTWARE. *
* *
**********************************************************************************)

val instantiate
: (module Compiler_owee.Unix_intf.S)
-> src:string
Expand Down
8 changes: 4 additions & 4 deletions asmcomp/asmpackager.ml
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,17 @@ let make_package_object unix ~ppf_dump members target coercion
in
let code = Simplif.simplify_lambda code in
let main_module_block_format : Lambda.main_module_block_format =
Mb_record { mb_size = main_module_block_size }
Mb_struct { mb_size = main_module_block_size }
in
let arg_block_field =
let arg_block_field_idx =
(* Packs not supported as argument modules *)
None
in
let program =
{ Lambda.
code;
main_module_block_format;
arg_block_field;
arg_block_field_idx;
compilation_unit;
required_globals;
}
Expand Down Expand Up @@ -195,7 +195,7 @@ let build_package_cmx members cmxfile ~main_module_block_size =
let modname = Compilation_unit.name ui.ui_unit in
let format : Lambda.main_module_block_format =
(* Open modules not supported with packs, so always just a record *)
Mb_record { mb_size = main_module_block_size }
Mb_struct { mb_size = main_module_block_size }
in
let pkg_infos =
{ ui_unit = ui.ui_unit;
Expand Down
26 changes: 26 additions & 0 deletions bytecomp/byteinstantiator.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
(**********************************************************************************
* MIT License *
* *
* *
* Copyright (c) 2019-2024 Jane Street Group LLC *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy *
* of this software and associated documentation files (the "Software"), to deal *
* in the Software without restriction, including without limitation the rights *
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in all *
* copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
* SOFTWARE. *
* *
**********************************************************************************)

type error =
| Not_an_object_file of Misc.filepath

Expand Down
26 changes: 26 additions & 0 deletions bytecomp/byteinstantiator.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
(**********************************************************************************
* MIT License *
* *
* *
* Copyright (c) 2019-2024 Jane Street Group LLC *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy *
* of this software and associated documentation files (the "Software"), to deal *
* in the Software without restriction, including without limitation the rights *
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in all *
* copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
* SOFTWARE. *
* *
**********************************************************************************)

val instantiate : src:string -> args:string list -> string -> unit

type error =
Expand Down
2 changes: 1 addition & 1 deletion bytecomp/bytepackager.ml
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ let package_object_files ~ppf_dump files target coercion =
in
let format : Lambda.main_module_block_format =
(* Open modules not supported with packs, so always just a record *)
Mb_record { mb_size = main_module_block_size }
Mb_struct { mb_size = main_module_block_size }
in
let compunit =
{ cu_name = packed_compilation_unit;
Expand Down
21 changes: 12 additions & 9 deletions driver/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ let interface ~source_file ~output_prefix =

(** Bytecode compilation backend for .ml files. *)

let make_arg_descr ~param ~arg_block_field : Lambda.arg_descr option =
match param, arg_block_field with
| Some arg_param, Some arg_block_field -> Some { arg_param; arg_block_field }
let make_arg_descr ~param ~arg_block_field_idx : Lambda.arg_descr option =
match param, arg_block_field_idx with
| Some arg_param, Some arg_block_field_idx ->
Some { arg_param; arg_block_field_idx }
| None, None -> None
| Some _, None -> Misc.fatal_error "No argument field"
| None, Some _ -> Misc.fatal_error "Unexpected argument field"
Expand All @@ -43,7 +44,7 @@ let raw_lambda_to_bytecode i raw_lambda ~as_arg_for =
raw_lambda
|> Profile.(record ~accumulate:true generate)
(fun { Lambda.code = lambda; required_globals; main_module_block_format;
arg_block_field } ->
arg_block_field_idx } ->
Builtin_attributes.warn_unused ();
lambda
|> print_if i.ppf_dump Clflags.dump_rawlambda Printlambda.lambda
Expand All @@ -52,7 +53,9 @@ let raw_lambda_to_bytecode i raw_lambda ~as_arg_for =
|> Bytegen.compile_implementation i.module_name
|> print_if i.ppf_dump Clflags.dump_instr Printinstr.instrlist
|> fun bytecode ->
let arg_descr = make_arg_descr ~param:as_arg_for ~arg_block_field in
let arg_descr =
make_arg_descr ~param:as_arg_for ~arg_block_field_idx
in
bytecode, required_globals, main_module_block_format, arg_descr
)

Expand Down Expand Up @@ -129,15 +132,15 @@ let implementation_aux ~start_from ~source_file ~output_prefix
"-as-argument-for is not allowed (and not needed) with -instantiate"
| None -> ()
end;
let as_arg_for, arg_block_field =
let as_arg_for, arg_block_field_idx =
match (arg_descr : Lambda.arg_descr option) with
| Some { arg_param; arg_block_field } ->
Some arg_param, Some arg_block_field
| Some { arg_param; arg_block_field_idx } ->
Some arg_param, Some arg_block_field_idx
| None -> None, None
in
let impl =
Translmod.transl_instance info.module_name ~runtime_args
~main_module_block_size ~arg_block_field ~style:Set_global_to_block
~main_module_block_size ~arg_block_field_idx ~style:Set_global_to_block
in
let bytecode = raw_lambda_to_bytecode info impl ~as_arg_for in
emit_bytecode info bytecode
Expand Down
Loading

0 comments on commit 025c20b

Please sign in to comment.