From 80fbe18e05930227e28a0b65702730244bb01fc2 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 16 Apr 2023 10:22:58 +0200 Subject: [PATCH] Remove obsolete generator scripts and doc --- jscomp/core/lambda.md | 227 ----------------------------------- scripts/caml_oo_curry_gen.ml | 71 ----------- scripts/curry_gen.ml | 167 -------------------------- 3 files changed, 465 deletions(-) delete mode 100644 jscomp/core/lambda.md delete mode 100644 scripts/caml_oo_curry_gen.ml delete mode 100644 scripts/curry_gen.ml diff --git a/jscomp/core/lambda.md b/jscomp/core/lambda.md deleted file mode 100644 index d6eefd6760..0000000000 --- a/jscomp/core/lambda.md +++ /dev/null @@ -1,227 +0,0 @@ - - - -## Difference from Lambda - -`Levent` is removed, it hurts pattern match peep-hole - -Based on `ocaml/bytecomp/bytegen.ml` - -```ocaml -| Lifused (_, exp) -> - comp_expr env exp sz cont -``` - -`ocaml/bytecomp/simplif.ml` -``` - | Lifused(v, l) -> - if count_var v > 0 then count bv l -``` - -`ocaml/bytecomp/simplif.ml` -``` - | Lifused(v, l) -> - if count_var v > 0 then simplif l else lambda_unit -``` - -`ocaml/bytecomp/translclass.ml` -``` -List.fold_right -(fun (id, expr) rem -> - lsequence (Lifused (id, set_inst_var obj id expr)) rem) -``` - -If we don't shake away `Lifused`, the diff would be simliar to -``` -diff --git a/jscomp/test/class3_test.js b/jscomp/test/class3_test.js -index c5fc8ac..450fcb5 100644 ---- a/jscomp/test/class3_test.js -+++ b/jscomp/test/class3_test.js -@@ -83,6 +83,7 @@ function eq(loc, x, y) { - } - - function point_init($$class) { -+ var x_init = CamlinternalOO.new_variable($$class, ""); - var ids = CamlinternalOO.new_methods_variables($$class, shared$1, shared$5); - var move = ids[0]; - var get_x = ids[1]; -@@ -98,9 +99,10 @@ function point_init($$class) { - return /* () */0; - } - ]); -- return function (_, self, x_init) { -+ return function (_, self, x_init$1) { - var self$1 = CamlinternalOO.create_object_opt(self, $$class); -- self$1[x] = x_init; -+ self$1[x_init] = x_init$1; -+ self$1[x] = x_init$1; - return self$1; - }; - } -@@ -112,6 +114,7 @@ var p = Curry._2(point[0], 0, 7); - eq("File \"class3_test.ml\", line 17, characters 12-19", Caml_oo_curry.js1(291546447, 1, p), 7); - - function adjusted_point_init($$class) { -+ var x_init = CamlinternalOO.new_variable($$class, ""); - var origin = CamlinternalOO.new_variable($$class, ""); - var ids = CamlinternalOO.new_methods_variables($$class, shared$7, shared$5); - var move = ids[0]; -@@ -133,10 +136,11 @@ function adjusted_point_init($$class) { - return /* () */0; - } - ]); -- return function (_, self, x_init) { -- var origin$1 = Caml_int32.imul(x_init / 10 | 0, 10); -+ return function (_, self, x_init$1) { -+ var origin$1 = Caml_int32.imul(x_init$1 / 10 | 0, 10); - var self$1 = CamlinternalOO.create_object_opt(self, $$class); - self$1[origin] = origin$1; -+ self$1[x_init] = x_init$1; - self$1[x] = origin$1; - return self$1; - }; -@@ -184,6 +188,7 @@ var tmp$1 = Curry._2(adjusted_point2_000, 0, 31); - eq("File \"class3_test.ml\", line 33, characters 12-19", Caml_oo_curry.js1(291546447, 3, tmp$1), 30); - - function printable_point_init($$class) { -+ var x_init = CamlinternalOO.new_variable($$class, ""); - var ids = CamlinternalOO.new_methods_variables($$class, shared$8, shared$5); - var print = ids[0]; - var move = ids[1]; -@@ -204,9 +209,10 @@ function printable_point_init($$class) { - return Curry._1(self$neg4[0][get_x], self$neg4); - } - ]); -- return function (_, self, x_init) { -+ return function (_, self, x_init$1) { - var self$1 = CamlinternalOO.create_object_opt(self, $$class); -- self$1[x] = x_init; -+ self$1[x_init] = x_init$1; -+ self$1[x] = x_init$1; - return self$1; - }; - } -@@ -264,6 +270,8 @@ var v = /* int array */[ - ]; - - function printable_point2_init($$class) { -+ var x_init = CamlinternalOO.new_variable($$class, ""); -+ var origin = CamlinternalOO.new_variable($$class, ""); - var ids = CamlinternalOO.new_methods_variables($$class, shared$8, shared$5); - var print = ids[0]; - var move = ids[1]; -@@ -288,10 +296,12 @@ function printable_point2_init($$class) { - console.log("initializingFile \"class3_test.ml\", line 76, characters 50-57"); - return Caml_array.caml_array_set(v, 0, self$neg6[x]); - }); -- return function (_, self, x_init) { -- var origin = Caml_int32.imul(x_init / 10 | 0, 10); -+ return function (_, self, x_init$1) { -+ var origin$1 = Caml_int32.imul(x_init$1 / 10 | 0, 10); - var self$1 = CamlinternalOO.create_object_opt(self, $$class); -- self$1[x] = origin; -+ self$1[origin] = origin$1; -+ self$1[x_init] = x_init$1; -+ self$1[x] = origin$1; - return CamlinternalOO.run_initializers_opt(self, self$1, $$class); - }; - } -@@ -328,6 +338,7 @@ var abstract_point = [ - ]; - - function vpoint_init($$class) { -+ var x_init = CamlinternalOO.new_variable($$class, ""); - var ids = CamlinternalOO.new_methods_variables($$class, shared$1, shared$5); - var move = ids[0]; - var get_x = ids[1]; -@@ -345,10 +356,11 @@ function vpoint_init($$class) { - return /* () */0; - } - ]); -- return function (_, self, x_init) { -+ return function (_, self, x_init$1) { - var self$1 = CamlinternalOO.create_object_opt(self, $$class); -- Curry._2(obj_init, self$1, x_init); -- self$1[x] = x_init; -+ self$1[x_init] = x_init$1; -+ Curry._2(obj_init, self$1, x_init$1); -+ self$1[x] = x_init$1; - return CamlinternalOO.run_initializers_opt(self, self$1, $$class); - }; - } -@@ -415,6 +427,7 @@ var vv = Caml_oo_curry.js1(-792262820, 11, h$1); - eq("File \"class3_test.ml\", line 128, characters 12-19", vv, 32); - - function restricted_point_init($$class) { -+ var x_init = CamlinternalOO.new_variable($$class, ""); - var ids = CamlinternalOO.new_methods_variables($$class, [ - "move", - "get_x", -@@ -439,9 +452,10 @@ function restricted_point_init($$class) { - return Curry._2(self$neg11[0][move], self$neg11, 1); - } - ]); -- return function (_, self, x_init) { -+ return function (_, self, x_init$1) { - var self$1 = CamlinternalOO.create_object_opt(self, $$class); -- self$1[x] = x_init; -+ self$1[x_init] = x_init$1; -+ self$1[x] = x_init$1; - return self$1; - }; - } -@@ -460,12 +474,14 @@ var h$2 = Caml_oo_curry.js1(291546447, 13, p$2); - eq("File \"class3_test.ml\", line 144, characters 12-19", h$2, 1); - - function point_again_init($$class) { -+ var x = CamlinternalOO.new_variable($$class, ""); - CamlinternalOO.get_method_label($$class, "move"); - var inh = CamlinternalOO.inherits($$class, shared$5, 0, shared, restricted_point, 1); - var obj_init = inh[0]; -- return function (_, self, x) { -+ return function (_, self, x$1) { - var self$1 = CamlinternalOO.create_object_opt(self, $$class); -- Curry._2(obj_init, self$1, x); -+ self$1[x] = x$1; -+ Curry._2(obj_init, self$1, x$1); - return CamlinternalOO.run_initializers_opt(self, self$1, $$class); - }; - } -@@ -485,11 +501,13 @@ var hh = Caml_oo_curry.js1(291546447, 17, p$3); - eq("File \"class3_test.ml\", line 161, characters 12-19", hh, 8); - - function point_again2_init($$class) { -+ var x = CamlinternalOO.new_variable($$class, ""); - var inh = CamlinternalOO.inherits($$class, shared$5, 0, shared, restricted_point, 1); - var obj_init = inh[0]; -- return function (_, self, x) { -+ return function (_, self, x$1) { - var self$1 = CamlinternalOO.create_object_opt(self, $$class); -- Curry._2(obj_init, self$1, x); -+ self$1[x] = x$1; -+ Curry._2(obj_init, self$1, x$1); - return CamlinternalOO.run_initializers_opt(self, self$1, $$class); - }; - } -@@ -509,14 +527,16 @@ var hhh = Caml_oo_curry.js1(291546447, 21, p$4); - eq("File \"class3_test.ml\", line 177, characters 12-19", hhh, 35); - - function point_again3_init($$class) { -+ var x = CamlinternalOO.new_variable($$class, ""); - var move = CamlinternalOO.get_method_label($$class, "move"); - var inh = CamlinternalOO.inherits($$class, shared$5, 0, shared, restricted_point, 1); - var obj_init = inh[0]; - var move$1 = inh[4]; - CamlinternalOO.set_method($$class, move, Curry.__1(move$1)); -- return function (_, self, x) { -+ return function (_, self, x$1) { - var self$1 = CamlinternalOO.create_object_opt(self, $$class); -- Curry._2(obj_init, self$1, x); -+ self$1[x] = x$1; -+ Curry._2(obj_init, self$1, x$1); - return CamlinternalOO.run_initializers_opt(self, self$1, $$class); - }; - } - -``` -## Pattern match reverse-engineering diff --git a/scripts/caml_oo_curry_gen.ml b/scripts/caml_oo_curry_gen.ml deleted file mode 100644 index 8e144c4217..0000000000 --- a/scripts/caml_oo_curry_gen.ml +++ /dev/null @@ -1,71 +0,0 @@ -let prelude ={| -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -(** Generated by scripts/caml_oo_curry_gen.ml *) -external function_length : 'a -> int = "#function_length" - -(** For efficiency, [args.(0)] would contain obj as well *) -let js label cacheid obj args = - let meth = - (Obj.magic Caml_oo.caml_get_public_method obj label cacheid) in - Curry.app meth args - -|} - -let list_init n fn = Array.to_list (Array.init n fn) - - -let number = 8 - - -let generate_fun args_number = - let args_array = - Array.init args_number (fun i -> Printf.sprintf "a%d" i) in - let args = Array.to_list args_array in - let args_string = (String.concat " " args) in - Printf.sprintf {| -let js%d label cacheid %s = - Curry._%d (Obj.magic Caml_oo.caml_get_public_method %s label cacheid) %s -|} - - args_number - args_string - args_number - (List.hd args) - args_string - - -let () = - print_endline - @@ Printf.sprintf - "%s\n%s" - prelude - - (String.concat "\n" - (list_init 8 (fun i -> generate_fun (i + 1)))) - -(* local variables: *) -(* compile-command: "ocaml caml_oo_curry_gen.ml > ../jscomp/runtime/caml_oo_curry.ml" *) -(* end: *) diff --git a/scripts/curry_gen.ml b/scripts/curry_gen.ml deleted file mode 100644 index 54814afe8c..0000000000 --- a/scripts/curry_gen.ml +++ /dev/null @@ -1,167 +0,0 @@ - - -(* no mli file emitted, since mli is not very meaningful - except which identifiers are exposed - exported functions: - - - [ app f args] - called when apply a curried function with a list of arugments - - [ _1 o arg ] .. [ _n] - called when apply a curried function with [n] argument - - [ __1 o] .. [ __n o] -*) -let prelude ={| -(* Copyright (C) 2015 - Hongbo Zhang, Authors of ReScript - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -(* Generated by scripts/curry_gen.ml *) -external function_length : 'a -> int = "#function_length" -external apply_args : ('a -> 'b) -> _ array -> 'b = "#apply" -external sub : 'a array -> int -> int -> 'a array = "?array_sub" - -(* Public *) -let rec app f args = - let init_arity = function_length f in - let arity = if init_arity = 0 then 1 else init_arity in (* arity fixing *) - let len = Caml_array_extern.length args in - let d = arity - len in - if d = 0 then - apply_args f args (* f.apply (null,args) *) - else if d < 0 then - (* TODO: could avoid copy by tracking the index *) - app (Obj.magic (apply_args f (sub args 0 arity))) - (sub args arity (-d)) - else - Obj.magic (fun x -> app f (Caml_array_extern.append args [|x|] )) - -|} - -let list_init n fn = Array.to_list (Array.init n fn) - -let generate_case - ?arity - ~args_number args_array args = - match arity with - | None -> - Printf.sprintf " _ -> Obj.magic (app o [|%s|])" - (String.concat ";"args) - | Some arity -> - Printf.sprintf " %d -> %s" arity - (if arity >= args_number then - Printf.sprintf "apply%d (Obj.magic o) %s" - arity (String.concat " " args) - else - Printf.sprintf - "app (apply%d (Obj.magic o) %s) [|%s|]" - arity - (String.concat " "(Array.to_list (Array.sub args_array 0 arity))) - (String.concat ";" - (Array.to_list (Array.sub args_array arity (args_number - arity))))) - - - -let number = 8 - -let generate_apply arity = - let vars = - list_init (arity + 1) - (fun i -> Printf.sprintf "'a%d" i) in - let ty = - match vars with - | [] -> assert false - | x::xs - -> - List.fold_left - (fun acc x -> acc ^ " -> " ^ x ) - x xs in - Printf.sprintf - "(* Internal use *)\n\ - external apply%d : (%s) -> %s = \"#apply%d\"" - arity ty ty arity - - - -let generate_fun args_number = - let args_array = - Array.init args_number (fun i -> Printf.sprintf "a%d" i) in - let args = Array.to_list args_array in - let args_string = (String.concat " " args) in - - Printf.sprintf {| - -let %%private curry_%d o %s arity = - match arity with - |%s - -(* Public *) -let _%d o %s = - let arity = function_length o in - if arity = %d then apply%d o %s - else curry_%d o %s arity - -(* Public *) -let __%d o = - let arity = function_length o in - if arity = %d then o - else fun %s -> _%d o %s -|} - args_number - args_string - (String.concat "\n |" - - (list_init (number - 1) - (fun arity -> generate_case ~arity:(arity + 1) ~args_number args_array args) - @ [ generate_case ~args_number args_array args] - ) - ) - - args_number - args_string - args_number - args_number - args_string - args_number - args_string - - - args_number - args_number - args_string - args_number - args_string - -let () = - print_endline - @@ Printf.sprintf - "%s\n%s\n%s" - prelude - (String.concat "\n" - (list_init number (fun i -> generate_apply (i + 1))) - ) - (String.concat "\n" - (list_init 8 (fun i -> generate_fun (i + 1)))) - -(* local variables: *) -(* compile-command: "ocaml curry_gen.ml > ../jscomp/runtime/curry.ml" *) -(* end: *)