From 0653696456aad6f2f3d6878a98b9862c25b25d8d Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Fri, 7 Apr 2023 16:37:17 +0000 Subject: [PATCH 01/27] playground: make jsoo_main compile --- dune-project | 1 + jscomp/common/dune | 4 +-- jscomp/core/dune | 2 +- jscomp/core/js_dump_program.mli | 8 +++++ jscomp/core/js_name_of_module_id.ml | 29 +++++++++--------- jscomp/core/lam_util.ml | 2 +- jscomp/ext/dune | 46 ++++++++++++++--------------- jscomp/frontend/dune | 2 +- jscomp/main/dune | 8 ++++- jscomp/main/jsoo_main.ml | 46 ++++++++++++----------------- mel/dune | 2 +- mel_workspace/dune | 2 +- 12 files changed, 80 insertions(+), 72 deletions(-) diff --git a/dune-project b/dune-project index 6c6c2c69a..20aa74918 100644 --- a/dune-project +++ b/dune-project @@ -47,6 +47,7 @@ (cppo :build) (ounit :with-test) (reason :with-test) + (js_of_ocaml :with-test) (reactjs-jsx-ppx :with-test))) (package diff --git a/jscomp/common/dune b/jscomp/common/dune index 7b21a4a8e..59d443b47 100644 --- a/jscomp/common/dune +++ b/jscomp/common/dune @@ -5,7 +5,7 @@ (flags :standard -w -9 -open Melange_compiler_libs) (preprocess (action - (run cppo %{env:CPPO_FLAGS=} %{input-file}))) + (run cppo %{env:CPPO_FLAGS=} -D BS_BROWSER %{input-file}))) (modules_without_implementation js_raw_info lam_tag_info) (libraries ext melange-compiler-libs js_parser)) @@ -13,7 +13,7 @@ (target js_config.ml) (deps js_config.cppo.ml) (action - (run cppo %{env:CPPO_FLAGS=} %{deps} -o %{target}))) + (run cppo %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{target}))) (rule (targets melange_version.ml) diff --git a/jscomp/core/dune b/jscomp/core/dune index 9f683c5a3..a2b8e118f 100644 --- a/jscomp/core/dune +++ b/jscomp/core/dune @@ -5,7 +5,7 @@ (:standard -w -9-30 -open Melange_compiler_libs)) (preprocess (action - (run cppo %{env:CPPO_FLAGS=} %{input-file}))) + (run cppo %{env:CPPO_FLAGS=} -D BS_BROWSER %{input-file}))) (modules_without_implementation lam_pass_unused_params lam_runtime) (libraries ext common melange.ppx melange-compiler-libs)) diff --git a/jscomp/core/js_dump_program.mli b/jscomp/core/js_dump_program.mli index 803de0d95..e3c94f240 100644 --- a/jscomp/core/js_dump_program.mli +++ b/jscomp/core/js_dump_program.mli @@ -32,3 +32,11 @@ val dump_deps_program : J.deps_program -> out_channel -> unit + +val pp_deps_program : + package_info:Js_packages_info.t -> + output_info:Js_packages_info.output_info -> + output_prefix:string -> + Ext_pp.t -> + J.deps_program -> + unit diff --git a/jscomp/core/js_name_of_module_id.ml b/jscomp/core/js_name_of_module_id.ml index 9a3aa1707..6e1dd8891 100644 --- a/jscomp/core/js_name_of_module_id.ml +++ b/jscomp/core/js_name_of_module_id.ml @@ -25,6 +25,21 @@ let (=) (x : int) (y:float) = assert false *) +#ifdef BS_BROWSER + +let string_of_module_id_in_browser (x : Lam_module_ident.t) = + match x.kind with + | External { name } -> name + | Runtime | Ml -> + "./stdlib/" ^ Ext_string.uncapitalize_ascii (Lam_module_ident.name x) ^ ".js" + +let string_of_module_id ~package_info:_ ~output_info:_ (id : Lam_module_ident.t) + ~output_dir:(_ : string) : string = + string_of_module_id_in_browser id +;; + +#else + let ( // ) = Filename.concat let fix_path_for_windows : string -> string = @@ -190,18 +205,4 @@ let string_of_module_id ~package_info ~output_info | None -> Bs_exception.error (Js_not_found js_file)))) ;; -(* Override it in browser *) -#ifdef BS_BROWSER - -let string_of_module_id_in_browser (x : Lam_module_ident.t) = - match x.kind with - | External { name } -> name - | Runtime | Ml -> - "./stdlib/" ^ Ext_string.uncapitalize_ascii x.id.name ^ ".js" - -let string_of_module_id ~package_info:_ ~output_info:_ (id : Lam_module_ident.t) - ~output_dir:(_ : string) : string = - string_of_module_id_in_browser id -;; - #endif diff --git a/jscomp/core/lam_util.ml b/jscomp/core/lam_util.ml index 9acb8b771..ad44dbce8 100644 --- a/jscomp/core/lam_util.ml +++ b/jscomp/core/lam_util.ml @@ -213,7 +213,7 @@ let generate_label ?(name="") () = Printf.sprintf "%s_tailcall_%04d" name !count #if (defined BS_BROWSER || defined BS_RELEASE_BUILD) -let dump ext lam = +let dump _ext _lam = () #else let log_counter = ref 0 diff --git a/jscomp/ext/dune b/jscomp/ext/dune index 4f76d0445..df8551b38 100644 --- a/jscomp/ext/dune +++ b/jscomp/ext/dune @@ -16,31 +16,31 @@ (target bs_hash_stubs.ml) (deps bs_hash_stubs.cppo.ml) (action - (run cppo %{env:CPPO_FLAGS=} %{deps} -o %{target}))) + (run cppo %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{target}))) (rule (targets ext_string.ml) (deps ext_string.cppo.ml) (action - (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) + (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) (rule (targets ext_string.mli) (deps ext_string.cppo.mli) (action - (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) + (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) (rule (targets hash_gen.ml) (deps hash_gen.cppo.ml) (action - (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) + (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) (rule (targets hash_set_gen.ml) (deps hash_set_gen.cppo.ml) (action - (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) + (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) (rule (targets js_reserved_map.ml) @@ -54,108 +54,108 @@ (targets hash_set_string.ml) (deps hash_set.cppo.ml) (action - (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) + (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) (rule (targets hash_set_int.ml) (deps hash_set.cppo.ml) (action - (run cppo -D TYPE_INT %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) + (run cppo -D TYPE_INT %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) (rule (targets hash_set_ident.ml) (deps hash_set.cppo.ml) (action - (run cppo -D TYPE_IDENT %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) + (run cppo -D TYPE_IDENT %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) (rule (targets hash_set.ml) (deps hash_set.cppo.ml) (action - (run cppo -D TYPE_FUNCTOR %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) + (run cppo -D TYPE_FUNCTOR %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) (rule (targets hash_set_poly.ml) (deps hash_set.cppo.ml) (action - (run cppo -D TYPE_POLY %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) + (run cppo -D TYPE_POLY %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) (rule (targets vec_int.ml) (deps vec.cppo.ml) (action - (run cppo -D TYPE_INT %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) + (run cppo -D TYPE_INT %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) (rule (targets vec.ml) (deps vec.cppo.ml) (action - (run cppo -D TYPE_FUNCTOR %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) + (run cppo -D TYPE_FUNCTOR %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) (rule (targets set_string.ml) (deps set.cppo.ml) (action - (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) + (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) (rule (targets set_int.ml) (deps set.cppo.ml) (action - (run cppo -D TYPE_INT %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) + (run cppo -D TYPE_INT %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) (rule (targets set_ident.ml) (deps set.cppo.ml) (action - (run cppo -D TYPE_IDENT %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) + (run cppo -D TYPE_IDENT %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) (rule (targets map_string.ml) (deps map.cppo.ml) (action - (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) + (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) (rule (targets map_int.ml) (deps map.cppo.ml) (action - (run cppo -D TYPE_INT %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) + (run cppo -D TYPE_INT %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) (rule (targets map_ident.ml) (deps map.cppo.ml) (action - (run cppo -D TYPE_IDENT %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) + (run cppo -D TYPE_IDENT %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) (rule (targets ordered_hash_map_local_ident.ml) (deps ordered_hash_map.cppo.ml) (action - (run cppo -D TYPE_LOCAL_IDENT %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) + (run cppo -D TYPE_LOCAL_IDENT %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) (rule (targets hash_string.ml) (deps hash.cppo.ml) (action - (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) + (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) (rule (targets hash_int.ml) (deps hash.cppo.ml) (action - (run cppo -D TYPE_INT %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) + (run cppo -D TYPE_INT %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) (rule (targets hash_ident.ml) (deps hash.cppo.ml) (action - (run cppo -D TYPE_IDENT %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) + (run cppo -D TYPE_IDENT %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) (rule (targets hash.ml) (deps hash.cppo.ml) (action - (run cppo -D TYPE_FUNCTOR %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) + (run cppo -D TYPE_FUNCTOR %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) (ocamllex ext_json_parse) diff --git a/jscomp/frontend/dune b/jscomp/frontend/dune index e527c4c41..98aa08d67 100644 --- a/jscomp/frontend/dune +++ b/jscomp/frontend/dune @@ -5,5 +5,5 @@ (:standard -w -9 -open Melange_compiler_libs)) (preprocess (action - (run cppo %{env:CPPO_FLAGS=} %{input-file}))) + (run cppo %{env:CPPO_FLAGS=} -D BS_BROWSER %{input-file}))) (libraries ext common melange-compiler-libs)) diff --git a/jscomp/main/dune b/jscomp/main/dune index 2dd8b59a9..26fc5bb02 100644 --- a/jscomp/main/dune +++ b/jscomp/main/dune @@ -8,7 +8,7 @@ (preprocessor_deps ../../package.json ../../bsconfig.json) (preprocess (action - (run cppo %{env:CPPO_FLAGS=} %{input-file})))) + (run cppo %{env:CPPO_FLAGS=} -D BS_BROWSER %{input-file})))) (executable (public_name mel) @@ -23,3 +23,9 @@ (modes native) (modules ounit_tests_main) (libraries ounit2 str ounit_tests)) + +(executable + (name jsoo_main) + (modules jsoo_main jsoo_common) + (libraries core melange-compiler-libs melange_ppx) + (modes js)) diff --git a/jscomp/main/jsoo_main.ml b/jscomp/main/jsoo_main.ml index 2a5cfc83a..8249bbfea 100644 --- a/jscomp/main/jsoo_main.ml +++ b/jscomp/main/jsoo_main.ml @@ -23,6 +23,9 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) module Js = Jsoo_common.Js + +open Melange_compiler_libs + (** *) (* @@ -43,7 +46,7 @@ let error_of_exn e = | Some (`Ok e) -> Some e | Some `Already_displayed | None -> None -let implementation ~use_super_errors impl str : Js.Unsafe.obj = +let compile impl str : Js.Unsafe.obj = let modulename = "Test" in (* let env = !Toploop.toplevel_env in *) (* Res_compmisc.init_path false; *) @@ -54,32 +57,28 @@ let implementation ~use_super_errors impl str : Js.Unsafe.obj = (* Question ?? *) (* let finalenv = ref Env.empty in *) let types_signature = ref [] in - if use_super_errors then ( - Misc.Color.setup (Some Always); - Lazy.force Super_main.setup); - try - Js_config.jsx_version := 3; (* default *) let ast = impl (Lexing.from_string str) in - let ast = Ppx_entry.rewrite_implementation ast in + let ast = Melange_ppx.Ppx_entry.rewrite_implementation ast in let typed_tree = - let a, b, _, signature = + let { Typedtree.structure; coercion; shape = _; signature }, _finalenv = Typemod.type_implementation_more modulename modulename modulename env ast in (* finalenv := c ; *) types_signature := signature; - (a, b) + (structure, coercion) in typed_tree |> Translmod.transl_implementation modulename - |> (* Printlambda.lambda ppf *) fun { Lambda.code = lam } -> + |> (* Printlambda.lambda ppf *) fun { Lambda.code = lam; _ } -> let buffer = Buffer.create 1000 in let () = Js_dump_program.pp_deps_program ~output_prefix:"" - (* does not matter here *) NodeJS - (Lam_compile_main.compile "" lam) + ~package_info:Js_packages_info.empty + ~output_info:{ Js_packages_info.module_system = NodeJS; suffix = Js } (Ext_pp.from_buffer buffer) + (Lam_compile_main.compile "" lam) in let v = Buffer.contents buffer in Js.Unsafe.(obj [| ("js_code", inject @@ Js.string v) |]) @@ -87,19 +86,20 @@ let implementation ~use_super_errors impl str : Js.Unsafe.obj = with e -> ( match error_of_exn e with | Some error -> - Location.report_error Format.err_formatter error; - Jsoo_common.mk_js_error error.loc error.msg + Location.print_report Format.err_formatter error; + (* TODO: replace js_error_msg below with the following (how to get string from error.main.txt?) + Jsoo_common.mk_js_error error.main.loc error.main.txt *) + Js.Unsafe.( + obj [| ("js_error_msg", inject @@ Js.string (Printexc.to_string e)) |]) | None -> Js.Unsafe.( obj [| ("js_error_msg", inject @@ Js.string (Printexc.to_string e)) |])) -let compile impl ~use_super_errors = implementation ~use_super_errors impl let export (field : string) v = Js.Unsafe.set Js.Unsafe.global field v (* To add a directory to the load path *) -let dir_directory d = Config.load_path := d :: !Config.load_path -let () = dir_directory "/static" +let () = Load_path.add_dir "/static" let make_compiler name impl = export name @@ -109,16 +109,8 @@ let make_compiler name impl = ( "compile", inject @@ Js.wrap_meth_callback (fun _ code -> - compile impl ~use_super_errors:false (Js.to_string code)) ); - ( "compile_super_errors", - inject - @@ Js.wrap_meth_callback (fun _ code -> - compile impl ~use_super_errors:true (Js.to_string code)) ); - ("version", Js.Unsafe.inject (Js.string Bs_version.version)); + compile impl (Js.to_string code)) ); + ("version", Js.Unsafe.inject (Js.string Melange_version.version)); |]) let () = make_compiler "ocaml" Parse.implementation - -(* local variables: *) -(* compile-command: "ocamlbuild -use-ocamlfind -pkg compiler-libs -no-hygiene driver.cmo" *) -(* end: *) diff --git a/mel/dune b/mel/dune index 0d496508a..e996b415d 100644 --- a/mel/dune +++ b/mel/dune @@ -2,7 +2,7 @@ (name mellib) (preprocess (action - (run %{bin:cppo} %{env:CPPO_FLAGS=} %{input-file}))) + (run %{bin:cppo} %{env:CPPO_FLAGS=} -D BS_BROWSER %{input-file}))) (modules_without_implementation bsb_config_types) (flags (:standard -w -9)) diff --git a/mel_workspace/dune b/mel_workspace/dune index bcfc53c63..11b4c298a 100644 --- a/mel_workspace/dune +++ b/mel_workspace/dune @@ -2,5 +2,5 @@ (name mel_workspace) (preprocess (action - (run %{bin:cppo} %{env:CPPO_FLAGS=} %{input-file}))) + (run %{bin:cppo} %{env:CPPO_FLAGS=} -D BS_BROWSER %{input-file}))) (libraries melange.ext unix)) From 6944289695ace23995dfd18542cf0392c7976a24 Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Sat, 6 May 2023 11:34:35 +0000 Subject: [PATCH 02/27] playground: updates after merging main --- jscomp/main/jsoo_main.ml | 3 +-- jscomp/main/jsoo_main.mli | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jscomp/main/jsoo_main.ml b/jscomp/main/jsoo_main.ml index 8249bbfea..98095c7ed 100644 --- a/jscomp/main/jsoo_main.ml +++ b/jscomp/main/jsoo_main.ml @@ -23,7 +23,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) module Js = Jsoo_common.Js - open Melange_compiler_libs (** *) @@ -60,7 +59,7 @@ let compile impl str : Js.Unsafe.obj = try (* default *) let ast = impl (Lexing.from_string str) in - let ast = Melange_ppx.Ppx_entry.rewrite_implementation ast in + let ast = Melange_ppx_lib.Ppx_entry.rewrite_implementation ast in let typed_tree = let { Typedtree.structure; coercion; shape = _; signature }, _finalenv = Typemod.type_implementation_more modulename modulename modulename env diff --git a/jscomp/main/jsoo_main.mli b/jscomp/main/jsoo_main.mli index a5f1becd5..443650cf1 100644 --- a/jscomp/main/jsoo_main.mli +++ b/jscomp/main/jsoo_main.mli @@ -22,4 +22,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -val make_compiler : string -> (Lexing.lexbuf -> Parsetree.structure) -> unit +val make_compiler : + string -> (Lexing.lexbuf -> Melange_compiler_libs.Parsetree.structure) -> unit From 080942418f1b503a4afc09eda33cc2da1e0b941c Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Mon, 29 May 2023 10:51:45 +0000 Subject: [PATCH 03/27] playground: use private melange comp libs --- jscomp/main/dune | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jscomp/main/dune b/jscomp/main/dune index 63972e533..c30bc3abb 100644 --- a/jscomp/main/dune +++ b/jscomp/main/dune @@ -41,5 +41,5 @@ (executable (name jsoo_main) (modules jsoo_main jsoo_common) - (libraries core melange-compiler-libs melange_ppx) + (libraries core melange_compiler_libs melange_ppx) (modes js)) From 9cbe9c5aca9ce5ea62ec48c8fea78d52b8e330c5 Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Mon, 29 May 2023 10:56:13 +0000 Subject: [PATCH 04/27] playground: pick up change in translmod --- vendor/melange-compiler-libs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/melange-compiler-libs b/vendor/melange-compiler-libs index 17a06ec6c..3e84247ca 160000 --- a/vendor/melange-compiler-libs +++ b/vendor/melange-compiler-libs @@ -1 +1 @@ -Subproject commit 17a06ec6c8a5da27adeb76496ff7fab6c58091f5 +Subproject commit 3e84247cabca72a99e3f63855dbb48e598332276 From ec1fbe3dd89347d26e4d888daefe80b81a93057c Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Mon, 29 May 2023 14:25:32 +0000 Subject: [PATCH 05/27] playground: better error handling --- jscomp/main/jsoo_common.ml | 32 ++++++++++++++++++++++++++++---- jscomp/main/jsoo_common.mli | 4 ++-- jscomp/main/jsoo_main.ml | 7 +------ 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/jscomp/main/jsoo_common.ml b/jscomp/main/jsoo_common.ml index 80dae52b0..9e857fc5b 100644 --- a/jscomp/main/jsoo_common.ml +++ b/jscomp/main/jsoo_common.ml @@ -32,7 +32,30 @@ module Js = struct external to_bytestring : js_string t -> string = "caml_js_to_byte_string" end -let mk_js_error (loc : Location.t) (msg : string) = +let string_of_formatted ~f x = + let buffer = Buffer.create 64 in + let str_fmt = Format.formatter_of_buffer buffer in + f str_fmt x; + Format.pp_print_flush str_fmt (); + Buffer.contents buffer + +let mk_js_error (error : Location.report) = + let kind, type_ = + match error.kind with + | Location.Report_error -> ("Error", "error") + | Report_warning w -> (Printf.sprintf "Warning: %s" w, "warning") + | Report_warning_as_error w -> + (Printf.sprintf "Error: (warning %s)" w, "warning_as_error") + | Report_alert w -> (Printf.sprintf "Alert: %s" w, "alert") + | Report_alert_as_error w -> + (Printf.sprintf "Error: (alert %s)" w, "alert_as_error") + in + let txt = + string_of_formatted + ~f:(fun fmt -> Format.fprintf fmt "@[%t@]") + error.main.txt + in + let loc = error.main.loc in let _file, line, startchar = Location.get_pos_info loc.Location.loc_start in let _file, endline, endchar = Location.get_pos_info loc.Location.loc_end in Js.Unsafe.( @@ -40,12 +63,13 @@ let mk_js_error (loc : Location.t) (msg : string) = [| ( "js_error_msg", inject - @@ Js.string (Printf.sprintf "Line %d, %d:\n %s" line startchar msg) + @@ Js.string + (Printf.sprintf "Line %d, %d:\n %s %s" line startchar kind txt) ); ("row", inject (line - 1)); ("column", inject startchar); ("endRow", inject (endline - 1)); ("endColumn", inject endchar); - ("text", inject @@ Js.string msg); - ("type", inject @@ Js.string "error"); + ("text", inject @@ Js.string txt); + ("type", inject @@ Js.string type_); |]) diff --git a/jscomp/main/jsoo_common.mli b/jscomp/main/jsoo_common.mli index 4e8144fad..dd674ba6b 100644 --- a/jscomp/main/jsoo_common.mli +++ b/jscomp/main/jsoo_common.mli @@ -35,6 +35,6 @@ module Js : sig end (* -Creates a Js Error object for given location with and a certain error message +Creates a Js Error object for given location with and a certain location report *) -val mk_js_error : Location.t -> string -> Js.Unsafe.obj +val mk_js_error : Location.report -> Js.Unsafe.obj diff --git a/jscomp/main/jsoo_main.ml b/jscomp/main/jsoo_main.ml index 98095c7ed..2f2b10d4f 100644 --- a/jscomp/main/jsoo_main.ml +++ b/jscomp/main/jsoo_main.ml @@ -84,12 +84,7 @@ let compile impl str : Js.Unsafe.obj = (* Format.fprintf output_ppf {| { "js_code" : %S }|} v ) *) with e -> ( match error_of_exn e with - | Some error -> - Location.print_report Format.err_formatter error; - (* TODO: replace js_error_msg below with the following (how to get string from error.main.txt?) - Jsoo_common.mk_js_error error.main.loc error.main.txt *) - Js.Unsafe.( - obj [| ("js_error_msg", inject @@ Js.string (Printexc.to_string e)) |]) + | Some error -> Jsoo_common.mk_js_error error | None -> Js.Unsafe.( obj [| ("js_error_msg", inject @@ Js.string (Printexc.to_string e)) |])) From ba38c05a5d241c30defd89416c61b6646120f98c Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Mon, 29 May 2023 15:55:30 +0000 Subject: [PATCH 06/27] playground: remove hardcoded BS_BROWSER --- jscomp/common/dune | 4 +- jscomp/core/dune | 2 +- jscomp/ext/dune | 46 +++++++++++------------ jscomp/frontend/dune | 2 +- jscomp/main/browser/dune | 10 +++++ jscomp/main/{ => browser}/jsoo_common.ml | 0 jscomp/main/{ => browser}/jsoo_common.mli | 0 jscomp/main/{ => browser}/jsoo_main.ml | 0 jscomp/main/{ => browser}/jsoo_main.mli | 0 jscomp/main/dune | 5 --- 10 files changed, 37 insertions(+), 32 deletions(-) create mode 100644 jscomp/main/browser/dune rename jscomp/main/{ => browser}/jsoo_common.ml (100%) rename jscomp/main/{ => browser}/jsoo_common.mli (100%) rename jscomp/main/{ => browser}/jsoo_main.ml (100%) rename jscomp/main/{ => browser}/jsoo_main.mli (100%) diff --git a/jscomp/common/dune b/jscomp/common/dune index 25dcc96f8..1f7509aab 100644 --- a/jscomp/common/dune +++ b/jscomp/common/dune @@ -5,7 +5,7 @@ (flags :standard -w -9 -open Melange_compiler_libs) (preprocess (action - (run cppo %{env:CPPO_FLAGS=} -D BS_BROWSER %{input-file}))) + (run cppo %{env:CPPO_FLAGS=} %{input-file}))) (modules_without_implementation js_raw_info lam_tag_info) (libraries ext melange_compiler_libs js_parser dune-build-info)) @@ -13,7 +13,7 @@ (target js_config.ml) (deps js_config.cppo.ml) (action - (run cppo %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{target}))) + (run cppo %{env:CPPO_FLAGS=} %{deps} -o %{target}))) (rule (targets git_commit.ml) diff --git a/jscomp/core/dune b/jscomp/core/dune index d7d9010ff..4771d89cb 100644 --- a/jscomp/core/dune +++ b/jscomp/core/dune @@ -5,7 +5,7 @@ (:standard -w -9-30 -open Melange_compiler_libs)) (preprocess (action - (run cppo %{env:CPPO_FLAGS=} -D BS_BROWSER %{input-file}))) + (run cppo %{env:CPPO_FLAGS=} %{input-file}))) (modules_without_implementation lam_pass_unused_params lam_runtime) (libraries ext diff --git a/jscomp/ext/dune b/jscomp/ext/dune index 71bb1779f..4bdac8f06 100644 --- a/jscomp/ext/dune +++ b/jscomp/ext/dune @@ -16,31 +16,31 @@ (target bs_hash_stubs.ml) (deps bs_hash_stubs.cppo.ml) (action - (run cppo %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{target}))) + (run cppo %{env:CPPO_FLAGS=} %{deps} -o %{target}))) (rule (targets ext_string.ml) (deps ext_string.cppo.ml) (action - (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) + (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) (rule (targets ext_string.mli) (deps ext_string.cppo.mli) (action - (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) + (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) (rule (targets hash_gen.ml) (deps hash_gen.cppo.ml) (action - (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) + (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) (rule (targets hash_set_gen.ml) (deps hash_set_gen.cppo.ml) (action - (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) + (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) (rule (targets js_reserved_map.ml) @@ -54,106 +54,106 @@ (targets hash_set_string.ml) (deps hash_set.cppo.ml) (action - (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) + (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) (rule (targets hash_set_int.ml) (deps hash_set.cppo.ml) (action - (run cppo -D TYPE_INT %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) + (run cppo -D TYPE_INT %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) (rule (targets hash_set_ident.ml) (deps hash_set.cppo.ml) (action - (run cppo -D TYPE_IDENT %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) + (run cppo -D TYPE_IDENT %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) (rule (targets hash_set.ml) (deps hash_set.cppo.ml) (action - (run cppo -D TYPE_FUNCTOR %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) + (run cppo -D TYPE_FUNCTOR %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) (rule (targets hash_set_poly.ml) (deps hash_set.cppo.ml) (action - (run cppo -D TYPE_POLY %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) + (run cppo -D TYPE_POLY %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) (rule (targets vec_int.ml) (deps vec.cppo.ml) (action - (run cppo -D TYPE_INT %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) + (run cppo -D TYPE_INT %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) (rule (targets vec.ml) (deps vec.cppo.ml) (action - (run cppo -D TYPE_FUNCTOR %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) + (run cppo -D TYPE_FUNCTOR %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) (rule (targets set_string.ml) (deps set.cppo.ml) (action - (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) + (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) (rule (targets set_int.ml) (deps set.cppo.ml) (action - (run cppo -D TYPE_INT %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) + (run cppo -D TYPE_INT %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) (rule (targets set_ident.ml) (deps set.cppo.ml) (action - (run cppo -D TYPE_IDENT %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) + (run cppo -D TYPE_IDENT %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) (rule (targets map_string.ml) (deps map.cppo.ml) (action - (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) + (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) (rule (targets map_int.ml) (deps map.cppo.ml) (action - (run cppo -D TYPE_INT %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) + (run cppo -D TYPE_INT %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) (rule (targets map_ident.ml) (deps map.cppo.ml) (action - (run cppo -D TYPE_IDENT %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) + (run cppo -D TYPE_IDENT %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) (rule (targets ordered_hash_map_local_ident.ml) (deps ordered_hash_map.cppo.ml) (action - (run cppo -D TYPE_LOCAL_IDENT %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) + (run cppo -D TYPE_LOCAL_IDENT %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) (rule (targets hash_string.ml) (deps hash.cppo.ml) (action - (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) + (run cppo -D TYPE_STRING %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) (rule (targets hash_int.ml) (deps hash.cppo.ml) (action - (run cppo -D TYPE_INT %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) + (run cppo -D TYPE_INT %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) (rule (targets hash_ident.ml) (deps hash.cppo.ml) (action - (run cppo -D TYPE_IDENT %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) + (run cppo -D TYPE_IDENT %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) (rule (targets hash.ml) (deps hash.cppo.ml) (action - (run cppo -D TYPE_FUNCTOR %{env:CPPO_FLAGS=} -D BS_BROWSER %{deps} -o %{targets}))) + (run cppo -D TYPE_FUNCTOR %{env:CPPO_FLAGS=} %{deps} -o %{targets}))) diff --git a/jscomp/frontend/dune b/jscomp/frontend/dune index eca37ac73..1374307cc 100644 --- a/jscomp/frontend/dune +++ b/jscomp/frontend/dune @@ -29,6 +29,6 @@ (:standard -w -9 -open Melange_ppx_lib)) (preprocess (action - (run cppo %{env:CPPO_FLAGS=} -D BS_BROWSER %{input-file}))) + (run cppo %{env:CPPO_FLAGS=} %{input-file}))) (modules melange_ppx) (libraries melange.ppxlib-ast melange.ppxlib ppxlib ast_extensions)) diff --git a/jscomp/main/browser/dune b/jscomp/main/browser/dune new file mode 100644 index 000000000..52df62aca --- /dev/null +++ b/jscomp/main/browser/dune @@ -0,0 +1,10 @@ +(env + (_ + (env-vars + (CPPO_FLAGS -D=BS_BROWSER)))) + +(executable + (name jsoo_main) + (modules jsoo_main jsoo_common) + (libraries core melange_compiler_libs melange_ppx) + (modes js)) diff --git a/jscomp/main/jsoo_common.ml b/jscomp/main/browser/jsoo_common.ml similarity index 100% rename from jscomp/main/jsoo_common.ml rename to jscomp/main/browser/jsoo_common.ml diff --git a/jscomp/main/jsoo_common.mli b/jscomp/main/browser/jsoo_common.mli similarity index 100% rename from jscomp/main/jsoo_common.mli rename to jscomp/main/browser/jsoo_common.mli diff --git a/jscomp/main/jsoo_main.ml b/jscomp/main/browser/jsoo_main.ml similarity index 100% rename from jscomp/main/jsoo_main.ml rename to jscomp/main/browser/jsoo_main.ml diff --git a/jscomp/main/jsoo_main.mli b/jscomp/main/browser/jsoo_main.mli similarity index 100% rename from jscomp/main/jsoo_main.mli rename to jscomp/main/browser/jsoo_main.mli diff --git a/jscomp/main/dune b/jscomp/main/dune index c30bc3abb..0ce8d3600 100644 --- a/jscomp/main/dune +++ b/jscomp/main/dune @@ -38,8 +38,3 @@ (modules ounit_tests_main) (libraries ounit2 ounit_tests)) -(executable - (name jsoo_main) - (modules jsoo_main jsoo_common) - (libraries core melange_compiler_libs melange_ppx) - (modes js)) From ca209c44b842b14ce47e2bcd5a9090f52dcf7535 Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Tue, 30 May 2023 13:32:44 +0000 Subject: [PATCH 07/27] opam: add jsoo --- melange.opam | 1 + 1 file changed, 1 insertion(+) diff --git a/melange.opam b/melange.opam index ae10ef341..a1668d6ae 100644 --- a/melange.opam +++ b/melange.opam @@ -15,6 +15,7 @@ depends: [ "cppo" {build} "ounit" {with-test} "reason" {with-test} + "js_of_ocaml" {with-test} "ppxlib" "reactjs-jsx-ppx" {with-test} "odoc" {with-doc} From d1ce4edcc3efae237c8c6cc12c6eb927b6d9bb1a Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Tue, 30 May 2023 13:33:00 +0000 Subject: [PATCH 08/27] playground: update in-code comment --- jscomp/main/browser/jsoo_common.mli | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jscomp/main/browser/jsoo_common.mli b/jscomp/main/browser/jsoo_common.mli index dd674ba6b..4d3aae272 100644 --- a/jscomp/main/browser/jsoo_common.mli +++ b/jscomp/main/browser/jsoo_common.mli @@ -35,6 +35,6 @@ module Js : sig end (* -Creates a Js Error object for given location with and a certain location report +Creates a Js Error object for given location report *) val mk_js_error : Location.report -> Js.Unsafe.obj From 01c797bb9017b1bfbb75e0527ec27f6eadcf9bf0 Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Tue, 30 May 2023 15:53:45 +0000 Subject: [PATCH 09/27] playground: add new profile browser --- Makefile | 4 ++++ dune | 5 ++++- jscomp/main/browser/dune | 10 ---------- jscomp/main/dune | 5 +++++ jscomp/main/{browser => }/jsoo_common.ml | 0 jscomp/main/{browser => }/jsoo_common.mli | 0 jscomp/main/{browser => }/jsoo_main.ml | 0 jscomp/main/{browser => }/jsoo_main.mli | 0 8 files changed, 13 insertions(+), 11 deletions(-) delete mode 100644 jscomp/main/browser/dune rename jscomp/main/{browser => }/jsoo_common.ml (100%) rename jscomp/main/{browser => }/jsoo_common.mli (100%) rename jscomp/main/{browser => }/jsoo_main.ml (100%) rename jscomp/main/{browser => }/jsoo_main.mli (100%) diff --git a/Makefile b/Makefile index be4465d6c..843d1c244 100644 --- a/Makefile +++ b/Makefile @@ -41,3 +41,7 @@ opam-install-dev: opam-install-test ## Install development dependencies .PHONY: opam-init opam-init: opam-create-switch opam-install-test ## Configure everything to develop this repository in local + +.PHONY: playground +playground: + opam exec -- dune build --profile=browser jscomp/main/jsoo_main.bc.js diff --git a/dune b/dune index 390179e31..f4b97cd4b 100644 --- a/dune +++ b/dune @@ -8,4 +8,7 @@ (env-vars (CPPO_FLAGS -D=BS_RELEASE_BUILD)) (ocamlopt_flags - (:standard -O3 -unbox-closures)))) + (:standard -O3 -unbox-closures))) + (browser + (env-vars + (CPPO_FLAGS -D=BS_BROWSER)))) diff --git a/jscomp/main/browser/dune b/jscomp/main/browser/dune deleted file mode 100644 index 52df62aca..000000000 --- a/jscomp/main/browser/dune +++ /dev/null @@ -1,10 +0,0 @@ -(env - (_ - (env-vars - (CPPO_FLAGS -D=BS_BROWSER)))) - -(executable - (name jsoo_main) - (modules jsoo_main jsoo_common) - (libraries core melange_compiler_libs melange_ppx) - (modes js)) diff --git a/jscomp/main/dune b/jscomp/main/dune index 0ce8d3600..c30bc3abb 100644 --- a/jscomp/main/dune +++ b/jscomp/main/dune @@ -38,3 +38,8 @@ (modules ounit_tests_main) (libraries ounit2 ounit_tests)) +(executable + (name jsoo_main) + (modules jsoo_main jsoo_common) + (libraries core melange_compiler_libs melange_ppx) + (modes js)) diff --git a/jscomp/main/browser/jsoo_common.ml b/jscomp/main/jsoo_common.ml similarity index 100% rename from jscomp/main/browser/jsoo_common.ml rename to jscomp/main/jsoo_common.ml diff --git a/jscomp/main/browser/jsoo_common.mli b/jscomp/main/jsoo_common.mli similarity index 100% rename from jscomp/main/browser/jsoo_common.mli rename to jscomp/main/jsoo_common.mli diff --git a/jscomp/main/browser/jsoo_main.ml b/jscomp/main/jsoo_main.ml similarity index 100% rename from jscomp/main/browser/jsoo_main.ml rename to jscomp/main/jsoo_main.ml diff --git a/jscomp/main/browser/jsoo_main.mli b/jscomp/main/jsoo_main.mli similarity index 100% rename from jscomp/main/browser/jsoo_main.mli rename to jscomp/main/jsoo_main.mli From 4e64b6f0b827569413fd9177bda3e4e464a6cf02 Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Tue, 30 May 2023 16:19:29 +0000 Subject: [PATCH 10/27] playground: build in ci --- .github/workflows/opam-build.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/opam-build.yml b/.github/workflows/opam-build.yml index 02a6c5d57..99f3d6262 100644 --- a/.github/workflows/opam-build.yml +++ b/.github/workflows/opam-build.yml @@ -57,6 +57,11 @@ jobs: opam update make opam-install-test + - name: Build playground + working-directory: melange + run: | + make playground + - name: Clone melange-opam-template run: | git clone https://github.com/melange-re/melange-opam-template.git From b1789305610773b072193d690a7e65d11439eda6 Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Wed, 31 May 2023 07:06:22 +0000 Subject: [PATCH 11/27] Revert "playground: pick up change in translmod" This reverts commit 9cbe9c5aca9ce5ea62ec48c8fea78d52b8e330c5. --- vendor/melange-compiler-libs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/melange-compiler-libs b/vendor/melange-compiler-libs index 3e84247ca..17a06ec6c 160000 --- a/vendor/melange-compiler-libs +++ b/vendor/melange-compiler-libs @@ -1 +1 @@ -Subproject commit 3e84247cabca72a99e3f63855dbb48e598332276 +Subproject commit 17a06ec6c8a5da27adeb76496ff7fab6c58091f5 From b9a255477db1e5428f3cfd0bf99e11595da0986b Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Wed, 31 May 2023 08:47:18 +0000 Subject: [PATCH 12/27] playground: add dev mode for faster builds --- Makefile | 4 ++++ dune | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/Makefile b/Makefile index 843d1c244..287fb5d5b 100644 --- a/Makefile +++ b/Makefile @@ -45,3 +45,7 @@ opam-init: opam-create-switch opam-install-test ## Configure everything to devel .PHONY: playground playground: opam exec -- dune build --profile=browser jscomp/main/jsoo_main.bc.js + +.PHONY: playground-dev +playground-dev: + opam exec -- dune build --profile=browser-dev jscomp/main/jsoo_main.bc.js diff --git a/dune b/dune index f4b97cd4b..8edba6c1d 100644 --- a/dune +++ b/dune @@ -10,5 +10,10 @@ (ocamlopt_flags (:standard -O3 -unbox-closures))) (browser + (env-vars + (CPPO_FLAGS -D=BS_BROWSER))) + (browser-dev + (js_of_ocaml + (compilation_mode separate)) (env-vars (CPPO_FLAGS -D=BS_BROWSER)))) From 08be8255e8fc4f8955d4c501f3d1f2b04f1aa2fb Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Wed, 31 May 2023 09:16:33 +0000 Subject: [PATCH 13/27] playground: apply ppxlib driver on structure --- jscomp/main/jsoo_main.ml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jscomp/main/jsoo_main.ml b/jscomp/main/jsoo_main.ml index 2f2b10d4f..c9984e9fa 100644 --- a/jscomp/main/jsoo_main.ml +++ b/jscomp/main/jsoo_main.ml @@ -60,6 +60,11 @@ let compile impl str : Js.Unsafe.obj = (* default *) let ast = impl (Lexing.from_string str) in let ast = Melange_ppx_lib.Ppx_entry.rewrite_implementation ast in + let ast = + Melange_ppxlib_ast.Of_ppxlib.copy_structure + (Ppxlib.Driver.map_structure + (Melange_ppxlib_ast.To_ppxlib.copy_structure ast)) + in let typed_tree = let { Typedtree.structure; coercion; shape = _; signature }, _finalenv = Typemod.type_implementation_more modulename modulename modulename env From b23d4f44ac28ce45eb82cb7527eceda363461e32 Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Wed, 31 May 2023 09:18:33 +0000 Subject: [PATCH 14/27] playground: add comment --- jscomp/main/dune | 1 + 1 file changed, 1 insertion(+) diff --git a/jscomp/main/dune b/jscomp/main/dune index c30bc3abb..9c3321fc4 100644 --- a/jscomp/main/dune +++ b/jscomp/main/dune @@ -41,5 +41,6 @@ (executable (name jsoo_main) (modules jsoo_main jsoo_common) + ; Need to use melange_ppx, not melange_ppx_lib, so Driver.V2.register_transformation runs (libraries core melange_compiler_libs melange_ppx) (modes js)) From 5f7c877cbf4a27515846d2a4121f3eb659c87ad2 Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Fri, 2 Jun 2023 17:45:50 +0000 Subject: [PATCH 15/27] playground: fix errors after merging main --- jscomp/core/js_implementation.mli | 5 +++++ jscomp/core/js_name_of_module_id.ml | 2 +- jscomp/main/jsoo_main.ml | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/jscomp/core/js_implementation.mli b/jscomp/core/js_implementation.mli index 0a70090e8..947f161a6 100644 --- a/jscomp/core/js_implementation.mli +++ b/jscomp/core/js_implementation.mli @@ -37,3 +37,8 @@ val implementation : val implementation_cmj : Format.formatter -> string -> unit (** [implementation_cmj ppf cmj_file] compiles a cmj to JS *) + +module Ppx_entry : sig + val rewrite_signature : Parsetree.signature -> Parsetree.signature + val rewrite_implementation : Parsetree.structure -> Parsetree.structure +end diff --git a/jscomp/core/js_name_of_module_id.ml b/jscomp/core/js_name_of_module_id.ml index 8a7ee2095..58c67ddd9 100644 --- a/jscomp/core/js_name_of_module_id.ml +++ b/jscomp/core/js_name_of_module_id.ml @@ -30,7 +30,7 @@ let (=) (x : int) (y:float) = assert false let string_of_module_id_in_browser (x : Lam_module_ident.t) = match x.kind with | External { name } -> name - | Runtime | Ml -> "./stdlib/" ^ String.uncapitalize_ascii x.id.name ^ ".js" + | Runtime | Ml -> "./stdlib/" ^ String.uncapitalize_ascii (Lam_module_ident.name x) ^ ".js" let string_of_module_id ~package_info:_ ~output_info:_ (id : Lam_module_ident.t) ~output_dir:(_ : string) : string = diff --git a/jscomp/main/jsoo_main.ml b/jscomp/main/jsoo_main.ml index c9984e9fa..05abeab85 100644 --- a/jscomp/main/jsoo_main.ml +++ b/jscomp/main/jsoo_main.ml @@ -59,7 +59,7 @@ let compile impl str : Js.Unsafe.obj = try (* default *) let ast = impl (Lexing.from_string str) in - let ast = Melange_ppx_lib.Ppx_entry.rewrite_implementation ast in + let ast = Js_implementation.Ppx_entry.rewrite_implementation ast in let ast = Melange_ppxlib_ast.Of_ppxlib.copy_structure (Ppxlib.Driver.map_structure From 529df6a7f99e8e04996370261e1b6a9db546348e Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Mon, 5 Jun 2023 09:39:49 +0000 Subject: [PATCH 16/27] fixes after merge --- bin/dune | 6 ------ bin/jsoo_main.ml | 18 +++++++++++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/bin/dune b/bin/dune index 66be0a829..4ecf08f02 100644 --- a/bin/dune +++ b/bin/dune @@ -14,12 +14,6 @@ (modules melppx) (libraries melange.ppx ppxlib)) -(test - (name ounit_tests_main) - (package melange) - (modules ounit_tests_main) - (libraries ounit2 ounit_tests)) - (executable (name jsoo_main) (modules jsoo_main jsoo_common) diff --git a/bin/jsoo_main.ml b/bin/jsoo_main.ml index 05abeab85..20f0a7f94 100644 --- a/bin/jsoo_main.ml +++ b/bin/jsoo_main.ml @@ -45,6 +45,11 @@ let error_of_exn e = | Some (`Ok e) -> Some e | Some `Already_displayed | None -> None +module Convert = + Ppxlib_ast.Convert + (Ppxlib_ast__.Versions.OCaml_414) + (Ppxlib_ast__.Versions.OCaml_current) + let compile impl str : Js.Unsafe.obj = let modulename = "Test" in (* let env = !Toploop.toplevel_env in *) @@ -59,11 +64,14 @@ let compile impl str : Js.Unsafe.obj = try (* default *) let ast = impl (Lexing.from_string str) in - let ast = Js_implementation.Ppx_entry.rewrite_implementation ast in - let ast = - Melange_ppxlib_ast.Of_ppxlib.copy_structure - (Ppxlib.Driver.map_structure - (Melange_ppxlib_ast.To_ppxlib.copy_structure ast)) + let ast : Melange_compiler_libs.Parsetree.structure = + let ppxlib_ast : Ppxlib_ast__.Versions.OCaml_414.Ast.Parsetree.structure = + Obj.magic (ast : Melange_compiler_libs.Parsetree.structure) + in + let converted = + Convert.copy_structure (Ppxlib.Driver.map_structure ppxlib_ast) + in + (Obj.magic converted : Melange_compiler_libs.Parsetree.structure) in let typed_tree = let { Typedtree.structure; coercion; shape = _; signature }, _finalenv = From abdb6ae192772eb3bbd90c280c055e3977d32fbc Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Mon, 5 Jun 2023 09:41:34 +0000 Subject: [PATCH 17/27] remove unneeded exposure of ppx_entry --- jscomp/core/js_implementation.mli | 5 ----- 1 file changed, 5 deletions(-) diff --git a/jscomp/core/js_implementation.mli b/jscomp/core/js_implementation.mli index 947f161a6..0a70090e8 100644 --- a/jscomp/core/js_implementation.mli +++ b/jscomp/core/js_implementation.mli @@ -37,8 +37,3 @@ val implementation : val implementation_cmj : Format.formatter -> string -> unit (** [implementation_cmj ppf cmj_file] compiles a cmj to JS *) - -module Ppx_entry : sig - val rewrite_signature : Parsetree.signature -> Parsetree.signature - val rewrite_implementation : Parsetree.structure -> Parsetree.structure -end From df0a373a9204b3b4a47a02e99065f939f8f3ebba Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Mon, 5 Jun 2023 09:50:13 +0000 Subject: [PATCH 18/27] remove d_browser --- bin/dune | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/dune b/bin/dune index 4ecf08f02..adfa054e1 100644 --- a/bin/dune +++ b/bin/dune @@ -6,7 +6,7 @@ (modules melc melc_cli) (preprocess (action - (run cppo "%{env:CPPO_FLAGS=}" -D BS_BROWSER %{input-file})))) + (run cppo "%{env:CPPO_FLAGS=}" %{input-file})))) (executable (public_name melppx) From 655102b11930e5729cccafc63f8ce7d31baa6169 Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Mon, 5 Jun 2023 10:10:19 +0000 Subject: [PATCH 19/27] playground: update makefile with new paths --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a34b669bb..339b0829a 100644 --- a/Makefile +++ b/Makefile @@ -43,8 +43,8 @@ opam-init: opam-create-switch opam-install-test ## Configure everything to devel .PHONY: playground playground: - opam exec -- dune build --profile=browser jscomp/main/jsoo_main.bc.js + opam exec -- dune build --profile=browser bin/jsoo_main.bc.js .PHONY: playground-dev playground-dev: - opam exec -- dune build --profile=browser-dev jscomp/main/jsoo_main.bc.js + opam exec -- dune build --profile=browser-dev bin/jsoo_main.bc.js From ef574d039d9896c2ed758c8c8605025cb58d4b8e Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Mon, 5 Jun 2023 13:07:10 +0000 Subject: [PATCH 20/27] add test for playground --- .github/workflows/opam-build.yml | 4 +-- Makefile | 8 +++++ test/blackbox-tests/dune | 8 +++++ test/blackbox-tests/playground.t | 56 ++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 test/blackbox-tests/playground.t diff --git a/.github/workflows/opam-build.yml b/.github/workflows/opam-build.yml index 2a9326d73..c6abd59d9 100644 --- a/.github/workflows/opam-build.yml +++ b/.github/workflows/opam-build.yml @@ -57,10 +57,10 @@ jobs: opam update make opam-install-test - - name: Build playground + - name: Test playground working-directory: melange run: | - make playground + make playground-test - name: Clone melange-opam-template run: | diff --git a/Makefile b/Makefile index 339b0829a..f2724a53c 100644 --- a/Makefile +++ b/Makefile @@ -48,3 +48,11 @@ playground: .PHONY: playground-dev playground-dev: opam exec -- dune build --profile=browser-dev bin/jsoo_main.bc.js + +.PHONY: playground-dev-test +playground-dev-test: + opam exec -- dune build --profile=browser-dev @@test/blackbox-tests/playground + +.PHONY: playground-test +playground-test: + opam exec -- dune build --profile=browser @@test/blackbox-tests/playground diff --git a/test/blackbox-tests/dune b/test/blackbox-tests/dune index da0a2c8a4..3ee304614 100644 --- a/test/blackbox-tests/dune +++ b/test/blackbox-tests/dune @@ -4,3 +4,11 @@ (env_var MELANGE_LIB) setup.sh (package melange))) + +(cram + (applies_to playground) + (enabled_if + (or + (= %{profile} browser) + (= %{profile} browser-dev))) + (deps %{bin:js_of_ocaml} ../../bin/jsoo_main.bc.js)) diff --git a/test/blackbox-tests/playground.t b/test/blackbox-tests/playground.t new file mode 100644 index 000000000..ae42fdd76 --- /dev/null +++ b/test/blackbox-tests/playground.t @@ -0,0 +1,56 @@ +Generate runtime cmijs for building against melange libs from the playground + + $ find $DUNE_SOURCEROOT/_build/default/jscomp/stdlib/.stdlib.objs/melange -name "*.cmi" -or -name "*.cmj" | xargs js_of_ocaml build-fs -o stdlib-cmijs.js + $ find $DUNE_SOURCEROOT/_build/default/jscomp/runtime/.runtime.objs/melange -name "*.cmi" -or -name "*.cmj" | xargs js_of_ocaml build-fs -o runtime-cmijs.js + $ find $DUNE_SOURCEROOT/_build/default/jscomp/others/.belt.objs/melange -name "*.cmi" -or -name "*.cmj" | xargs js_of_ocaml build-fs -o belt-cmijs.js + +Prepare an input file to test some snippets to exercise common functionality + + $ cat > input.js < require(process.env.DUNE_SOURCEROOT + '/_build/default/bin/jsoo_main.bc.js'); + > require('./stdlib-cmijs.js'); + > require('./runtime-cmijs.js'); + > require('./belt-cmijs.js'); + > console.log(ocaml.compile("let t = 1")); + > console.log(ocaml.compile(\`let john = [%bs.obj { name = "john"; age = 99 }] let t = john##name\`)); + > console.log(ocaml.compile(\`let foo = Belt.List.map\`)); + > EOF + + $ node input.js + { + js_code: '// Generated by Melange\n' + + "'use strict';\n" + + '\n' + + '\n' + + 'var t = 1;\n' + + '\n' + + 'exports.t = t;\n' + + '/* No side effect */\n' + } + { + js_code: '// Generated by Melange\n' + + "'use strict';\n" + + '\n' + + '\n' + + 'var john = {\n' + + ' name: "john",\n' + + ' age: 99\n' + + '};\n' + + '\n' + + 'var t = john.name;\n' + + '\n' + + 'exports.john = john;\n' + + 'exports.t = t;\n' + + '/* t Not a pure module */\n' + } + { + js_code: '// Generated by Melange\n' + + "'use strict';\n" + + '\n' + + 'var Belt_List = require("./stdlib/belt_List.js");\n' + + '\n' + + 'var foo = Belt_List.map;\n' + + '\n' + + 'exports.foo = foo;\n' + + '/* No side effect */\n' + } From c4ad80d59c355c0478dc3787ad404386d212c11a Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Mon, 5 Jun 2023 13:10:46 +0000 Subject: [PATCH 21/27] playground: remove obsolete comment --- bin/dune | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/dune b/bin/dune index adfa054e1..da842808a 100644 --- a/bin/dune +++ b/bin/dune @@ -17,6 +17,5 @@ (executable (name jsoo_main) (modules jsoo_main jsoo_common) - ; Need to use melange_ppx, not melange_ppx_lib, so Driver.V2.register_transformation runs (libraries core melange_compiler_libs melange_ppx) (modes js)) From 1620cbc9024e36c83775c7f4ba2dc7461d2fddf4 Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Mon, 5 Jun 2023 13:13:18 +0000 Subject: [PATCH 22/27] playground: open melange_comp_libs in flags --- bin/dune | 1 + bin/jsoo_main.ml | 9 +++------ bin/jsoo_main.mli | 3 +-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/bin/dune b/bin/dune index da842808a..0be1f1185 100644 --- a/bin/dune +++ b/bin/dune @@ -16,6 +16,7 @@ (executable (name jsoo_main) + (flags :standard -open Melange_compiler_libs) (modules jsoo_main jsoo_common) (libraries core melange_compiler_libs melange_ppx) (modes js)) diff --git a/bin/jsoo_main.ml b/bin/jsoo_main.ml index 20f0a7f94..7a99f2d73 100644 --- a/bin/jsoo_main.ml +++ b/bin/jsoo_main.ml @@ -23,9 +23,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) module Js = Jsoo_common.Js -open Melange_compiler_libs - -(** *) (* Error: @@ -64,14 +61,14 @@ let compile impl str : Js.Unsafe.obj = try (* default *) let ast = impl (Lexing.from_string str) in - let ast : Melange_compiler_libs.Parsetree.structure = + let ast : Parsetree.structure = let ppxlib_ast : Ppxlib_ast__.Versions.OCaml_414.Ast.Parsetree.structure = - Obj.magic (ast : Melange_compiler_libs.Parsetree.structure) + Obj.magic (ast : Parsetree.structure) in let converted = Convert.copy_structure (Ppxlib.Driver.map_structure ppxlib_ast) in - (Obj.magic converted : Melange_compiler_libs.Parsetree.structure) + (Obj.magic converted : Parsetree.structure) in let typed_tree = let { Typedtree.structure; coercion; shape = _; signature }, _finalenv = diff --git a/bin/jsoo_main.mli b/bin/jsoo_main.mli index 443650cf1..a5f1becd5 100644 --- a/bin/jsoo_main.mli +++ b/bin/jsoo_main.mli @@ -22,5 +22,4 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -val make_compiler : - string -> (Lexing.lexbuf -> Melange_compiler_libs.Parsetree.structure) -> unit +val make_compiler : string -> (Lexing.lexbuf -> Parsetree.structure) -> unit From f478585fb437351ea5c427b558abf69e16cab281 Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Mon, 5 Jun 2023 13:17:32 +0000 Subject: [PATCH 23/27] playground: add more tests --- test/blackbox-tests/playground.t | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/blackbox-tests/playground.t b/test/blackbox-tests/playground.t index ae42fdd76..a488b5797 100644 --- a/test/blackbox-tests/playground.t +++ b/test/blackbox-tests/playground.t @@ -14,6 +14,8 @@ Prepare an input file to test some snippets to exercise common functionality > console.log(ocaml.compile("let t = 1")); > console.log(ocaml.compile(\`let john = [%bs.obj { name = "john"; age = 99 }] let t = john##name\`)); > console.log(ocaml.compile(\`let foo = Belt.List.map\`)); + > console.log(ocaml.compile(\`let +foo\`)); + > console.log(ocaml.compile(\`let foo = "fpp" + 2\`)); > EOF $ node input.js @@ -54,3 +56,22 @@ Prepare an input file to test some snippets to exercise common functionality 'exports.foo = foo;\n' + '/* No side effect */\n' } + { + js_error_msg: 'Line 1, 5:\n Error Syntax error', + row: 0, + column: 5, + endRow: 0, + endColumn: 8, + text: 'Syntax error', + type: 'error' + } + { + js_error_msg: 'Line 1, 10:\n' + + ' Error This expression has type string but an expression was expected of type int', + row: 0, + column: 10, + endRow: 0, + endColumn: 15, + text: 'This expression has type string but an expression was expected of type int', + type: 'error' + } From 9329c8714320bcf9988f1792c243d7b5af89be8f Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Mon, 5 Jun 2023 13:19:40 +0000 Subject: [PATCH 24/27] playground: remove str_of_formatted --- bin/jsoo_common.ml | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/bin/jsoo_common.ml b/bin/jsoo_common.ml index 9e857fc5b..0cff5d996 100644 --- a/bin/jsoo_common.ml +++ b/bin/jsoo_common.ml @@ -32,13 +32,6 @@ module Js = struct external to_bytestring : js_string t -> string = "caml_js_to_byte_string" end -let string_of_formatted ~f x = - let buffer = Buffer.create 64 in - let str_fmt = Format.formatter_of_buffer buffer in - f str_fmt x; - Format.pp_print_flush str_fmt (); - Buffer.contents buffer - let mk_js_error (error : Location.report) = let kind, type_ = match error.kind with @@ -50,11 +43,7 @@ let mk_js_error (error : Location.report) = | Report_alert_as_error w -> (Printf.sprintf "Error: (alert %s)" w, "alert_as_error") in - let txt = - string_of_formatted - ~f:(fun fmt -> Format.fprintf fmt "@[%t@]") - error.main.txt - in + let txt = Format.asprintf "@[%t@]" error.main.txt in let loc = error.main.loc in let _file, line, startchar = Location.get_pos_info loc.Location.loc_start in let _file, endline, endchar = Location.get_pos_info loc.Location.loc_end in From 68cc036be37829273f1dc2274e691e12e26498f2 Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Mon, 5 Jun 2023 13:55:44 +0000 Subject: [PATCH 25/27] playground: add failing test with bs.deriving --- test/blackbox-tests/playground.t | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/blackbox-tests/playground.t b/test/blackbox-tests/playground.t index a488b5797..2afb5f7bd 100644 --- a/test/blackbox-tests/playground.t +++ b/test/blackbox-tests/playground.t @@ -16,6 +16,12 @@ Prepare an input file to test some snippets to exercise common functionality > console.log(ocaml.compile(\`let foo = Belt.List.map\`)); > console.log(ocaml.compile(\`let +foo\`)); > console.log(ocaml.compile(\`let foo = "fpp" + 2\`)); + > console.log(ocaml.compile(\`type person = { + > name: string ; + > age: int + > }[@@bs.deriving abstract] + > + > let person1 = person ~name:"joe" ~last:"bar" ~age:10\`)); > EOF $ node input.js @@ -75,3 +81,17 @@ Prepare an input file to test some snippets to exercise common functionality text: 'This expression has type string but an expression was expected of type int', type: 'error' } + File "_none_", line 4, characters 4-15: + Alert unused: Unused attribute [@bs.deriving] + This means such annotation is not annotated properly. + For example, some annotations are only meaningful in externals + + { + js_error_msg: 'Line 6, 14:\n Error Unbound value person', + row: 5, + column: 14, + endRow: 5, + endColumn: 20, + text: 'Unbound value person', + type: 'error' + } From a255638d948091b306664b91df6b82400ff6c93e Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Mon, 5 Jun 2023 14:07:37 +0000 Subject: [PATCH 26/27] playground: fix test by replacing bs.deriving with deriving --- test/blackbox-tests/playground.t | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/test/blackbox-tests/playground.t b/test/blackbox-tests/playground.t index 2afb5f7bd..950efd200 100644 --- a/test/blackbox-tests/playground.t +++ b/test/blackbox-tests/playground.t @@ -15,13 +15,13 @@ Prepare an input file to test some snippets to exercise common functionality > console.log(ocaml.compile(\`let john = [%bs.obj { name = "john"; age = 99 }] let t = john##name\`)); > console.log(ocaml.compile(\`let foo = Belt.List.map\`)); > console.log(ocaml.compile(\`let +foo\`)); - > console.log(ocaml.compile(\`let foo = "fpp" + 2\`)); + > console.log(ocaml.compile(\`let foo = "" + 2\`)); > console.log(ocaml.compile(\`type person = { > name: string ; > age: int - > }[@@bs.deriving abstract] + > }[@@deriving abstract] > - > let person1 = person ~name:"joe" ~last:"bar" ~age:10\`)); + > let person1: person = person ~name:"joe" ~age:10\`)); > EOF $ node input.js @@ -77,21 +77,20 @@ Prepare an input file to test some snippets to exercise common functionality row: 0, column: 10, endRow: 0, - endColumn: 15, + endColumn: 12, text: 'This expression has type string but an expression was expected of type int', type: 'error' } - File "_none_", line 4, characters 4-15: - Alert unused: Unused attribute [@bs.deriving] - This means such annotation is not annotated properly. - For example, some annotations are only meaningful in externals - { - js_error_msg: 'Line 6, 14:\n Error Unbound value person', - row: 5, - column: 14, - endRow: 5, - endColumn: 20, - text: 'Unbound value person', - type: 'error' + js_code: '// Generated by Melange\n' + + "'use strict';\n" + + '\n' + + '\n' + + 'var person1 = {\n' + + ' name: "joe",\n' + + ' age: 10\n' + + '};\n' + + '\n' + + 'exports.person1 = person1;\n' + + '/* No side effect */\n' } From 53dc2dceba5759a49db71ad00cb59b091e1ba7b9 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Mon, 5 Jun 2023 16:18:51 -0700 Subject: [PATCH 27/27] fix: ppxlib AST conversion --- bin/jsoo_main.ml | 32 +++++++++++++++++++------------- nix/shell.nix | 1 + 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/bin/jsoo_main.ml b/bin/jsoo_main.ml index 7a99f2d73..d963f815e 100644 --- a/bin/jsoo_main.ml +++ b/bin/jsoo_main.ml @@ -42,12 +42,14 @@ let error_of_exn e = | Some (`Ok e) -> Some e | Some `Already_displayed | None -> None -module Convert = - Ppxlib_ast.Convert - (Ppxlib_ast__.Versions.OCaml_414) - (Ppxlib_ast__.Versions.OCaml_current) +module From_ppxlib = + Ppxlib_ast.Convert (Ppxlib_ast.Selected_ast) (Ppxlib_ast__.Versions.OCaml_414) -let compile impl str : Js.Unsafe.obj = +module To_ppxlib = + Ppxlib_ast.Convert (Ppxlib_ast__.Versions.OCaml_414) (Ppxlib_ast.Selected_ast) + +let compile ~(impl : Lexing.lexbuf -> Melange_compiler_libs.Parsetree.structure) + str : Js.Unsafe.obj = let modulename = "Test" in (* let env = !Toploop.toplevel_env in *) (* Res_compmisc.init_path false; *) @@ -61,14 +63,18 @@ let compile impl str : Js.Unsafe.obj = try (* default *) let ast = impl (Lexing.from_string str) in - let ast : Parsetree.structure = - let ppxlib_ast : Ppxlib_ast__.Versions.OCaml_414.Ast.Parsetree.structure = - Obj.magic (ast : Parsetree.structure) + let ast = + let ppxlib_ast : Ppxlib_ast.Parsetree.structure = + (* Copy to ppxlib version *) + To_ppxlib.copy_structure + (Obj.magic ast + : Ppxlib_ast__.Versions.OCaml_414.Ast.Parsetree.structure) in - let converted = - Convert.copy_structure (Ppxlib.Driver.map_structure ppxlib_ast) + let melange_converted_ast = + From_ppxlib.copy_structure (Ppxlib.Driver.map_structure ppxlib_ast) in - (Obj.magic converted : Parsetree.structure) + (Obj.magic melange_converted_ast + : Melange_compiler_libs.Parsetree.structure) in let typed_tree = let { Typedtree.structure; coercion; shape = _; signature }, _finalenv = @@ -113,8 +119,8 @@ let make_compiler name impl = ( "compile", inject @@ Js.wrap_meth_callback (fun _ code -> - compile impl (Js.to_string code)) ); + compile ~impl (Js.to_string code)) ); ("version", Js.Unsafe.inject (Js.string Melange_version.version)); |]) -let () = make_compiler "ocaml" Parse.implementation +let () = make_compiler "ocaml" Melange_compiler_libs.Parse.implementation diff --git a/nix/shell.nix b/nix/shell.nix index 1b5f2665a..4660ee116 100644 --- a/nix/shell.nix +++ b/nix/shell.nix @@ -35,6 +35,7 @@ mkShell { nodejs_latest yarn nodePackages.mocha + js_of_ocaml-compiler ] ++ lib.optionals release-mode ([ cacert curl