diff --git a/.gitignore b/.gitignore index c45216d265..fb77467b4a 100644 --- a/.gitignore +++ b/.gitignore @@ -48,4 +48,5 @@ ocaml/man jscomp/bench/*.js *.bak .vscode -osc \ No newline at end of file +osc +jscomp/pre_load.js \ No newline at end of file diff --git a/jscomp/compiler.mllib b/jscomp/compiler.mllib index 78eab44ded..82fcdc5e67 100644 --- a/jscomp/compiler.mllib +++ b/jscomp/compiler.mllib @@ -61,6 +61,7 @@ lam_group lam_current_unit j +js_config js_program_loader js_output js_dump diff --git a/jscomp/js.sh b/jscomp/js.sh index d0f4d8d8c9..6d0520f33e 100755 --- a/jscomp/js.sh +++ b/jscomp/js.sh @@ -9,3 +9,10 @@ js_of_ocaml -I +compiler-libs --toplevel +dynlink.js +toplevel.js +weak.js _bui rm -rf $OCAMLSCRIPT_DOC/js-demo/exports.js && cp _build/exports.js $OCAMLSCRIPT_DOC/js-demo/exports.js +ocamlbuild -use-ocamlfind -no-hygiene -no-links js_generate_require.byte -- +rm -rf $OCAMLSCRIPT_DOC/js-demo/pre_load.js +cp ./pre_load.js $OCAMLSCRIPT_DOC/js-demo/ +# TODO: build with amd first +cp runtime/*.js $OCAMLSCRIPT_DOC/js-demo/runtime +cp stdlib/*.js $OCAMLSCRIPT_DOC/js-demo/stdlib + diff --git a/jscomp/js_config.ml b/jscomp/js_config.ml new file mode 100644 index 0000000000..a60a168af9 --- /dev/null +++ b/jscomp/js_config.ml @@ -0,0 +1,104 @@ +(* OCamlScript compiler + * 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, with linking exception; + * either version 2.1 of the License, or (at your option) any 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. + *) + +(* Author: Hongbo Zhang *) + + +type env = + | Browser + | NodeJS + + +let default_env = ref NodeJS + +let get_env () = !default_env + +let set_env env = default_env := env + +let stdlib_set = String_set.of_list [ + "arg.js"; + "gc.js"; + "printexc.js"; + "array.js"; + "genlex.js"; + "printf.js"; + "arrayLabels.js"; + "hashtbl.js"; + "queue.js"; + "buffer.js"; + "int32.js"; + "random.js"; + "bytes.js"; + "int64.js"; + "scanf.js"; + "bytesLabels.js"; + "lazy.js"; + "set.js"; + "callback.js"; + "lexing.js"; + "sort.js"; + "camlinternalFormat.js"; + "list.js"; + "stack.js"; + "camlinternalFormatBasics.js"; + "listLabels.js"; + "stdLabels.js"; + "camlinternalLazy.js"; + "map.js"; + "std_exit.js"; + "camlinternalMod.js"; + "marshal.js"; + "stream.js"; + "camlinternalOO.js"; + "moreLabels.js"; + "string.js"; + "char.js"; + "nativeint.js"; + "stringLabels.js"; + "complex.js"; + "obj.js"; + "sys.js"; + "digest.js"; + "oo.js"; + "weak.js"; + "filename.js"; + "parsing.js"; + "format.js"; + "pervasives.js" +] + +let runtime_set = String_set.of_list [ + "caml_array.js"; + "caml_float.js"; + "caml_obj_runtime.js"; + (* "caml_sys.js"; *) + "caml_bigarray.js"; + "caml_format.js"; + "caml_oo.js"; + (* "caml_unix.js"; *) + "caml_c_ffi.js"; + "caml_int64.js"; + "caml_primitive.js"; + "caml_utils.js"; + "caml_exceptions.js"; + (* "caml_io.js"; *) + "curry.js"; + "caml_file.js"; + "caml_lexer.js"; + "caml_string.js" +] diff --git a/jscomp/js_config.mli b/jscomp/js_config.mli new file mode 100644 index 0000000000..10d258476f --- /dev/null +++ b/jscomp/js_config.mli @@ -0,0 +1,33 @@ +(* OCamlScript compiler + * 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, with linking exception; + * either version 2.1 of the License, or (at your option) any 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. + *) + +(* Author: Hongbo Zhang *) + +type env = + | Browser + | NodeJS + + +val get_env : unit -> env + +val set_env : env -> unit + +val runtime_set : String_set.t +val stdlib_set : String_set.t + + diff --git a/jscomp/js_dump.ml b/jscomp/js_dump.ml index 3412b948c1..26d1a87ad1 100644 --- a/jscomp/js_dump.ml +++ b/jscomp/js_dump.ml @@ -84,6 +84,7 @@ module L = struct let json = "JSON" let stringify = "stringify" let console = "console" + let define = "define" end let return_indent = (String.length L.return / Ext_pp.indent_length) @@ -284,8 +285,10 @@ let rec pp_function action return else let lexical = Ident_set.elements lexical in - - (if return then P.string f "return " else ()); + (if return then begin + P.string f L.return ; + P.space f + end else ()); P.string f "(function("; ignore @@ aux inner_cxt f lexical; P.string f ")"; @@ -1350,69 +1353,76 @@ let amd_program f ({modules; block = b ; exports = exp ; side_effect } : J.prog list ~pp_sep pp_v ppf vs in P.vgroup f 1 @@ fun _ -> - P.string f "define(["; - list ~pp_sep:(fun f _ -> P.string f L.comma) - (fun f (_,s) -> - pp_string f ~utf:true ~quote:(best_string_quote s) s; ) f modules; - P.string f "]"; - P.string f L.comma; - P.newline f; - P.string f L.function_; - P.string f "("; - let cxt = aux cxt f modules in - P.string f ")"; - - P.brace_vgroup f 1 @@ (fun _ -> - let cxt = statement_list true cxt f b in - (* FIXME AMD : use {[ function xx ]} or {[ var x = function ..]} *) - P.newline f; - P.string f L.return; - P.space f; - P.brace_vgroup f 1 @@ fun _ -> - let rec aux cxt f (idents : Ident.t list) = - match idents with - | [] -> cxt - | [id] -> - P.string f (Ext_ident.convert id.name); - P.space f ; - P.string f L.colon; - P.space f ; - ident cxt f id - | id :: rest - -> - P.string f (Ext_ident.convert id.name); - P.space f ; - P.string f L.colon; - P.space f; - let cxt = ident cxt f id in - P.string f L.comma; - P.space f ; - P.newline f ; - aux cxt f rest + P.string f L.define; + P.string f "(["; + list ~pp_sep:(fun f _ -> P.string f L.comma) + (fun f (_,s) -> + pp_string f ~utf:true ~quote:(best_string_quote s) s; ) f modules; + P.string f "]"; + P.string f L.comma; + P.newline f; + P.string f L.function_; + P.string f "("; + let cxt = aux cxt f modules in + P.string f ")"; + P.brace_vgroup f 1 @@ (fun _ -> + let () = P.string f "'use strict';" in + let () = P.newline f in + let cxt = statement_list true cxt f b in + (* FIXME AMD : use {[ function xx ]} or {[ var x = function ..]} *) + P.newline f; + P.string f L.return; + P.space f; + P.brace_vgroup f 1 @@ fun _ -> + let rec aux cxt f (idents : Ident.t list) = + match idents with + | [] -> cxt + | [id] -> + P.string f (Ext_ident.convert id.name); + P.space f ; + P.string f L.colon; + P.space f ; + ident cxt f id + | id :: rest + -> + P.string f (Ext_ident.convert id.name); + P.space f ; + P.string f L.colon; + P.space f; + let cxt = ident cxt f id in + P.string f L.comma; + P.space f ; + P.newline f ; + aux cxt f rest - in - ignore @@ aux cxt f exp); - P.string f ")"; + in + ignore @@ aux cxt f exp); + P.string f ")"; ;; let pp_program (program : J.program) (f : Ext_pp.t) = - let () = + begin P.string f "// Generated CODE, PLEASE EDIT WITH CARE"; P.newline f; - P.string f {|"use strict";|}; + P.string f "\"use strict\";"; (* TODO: use single quote in another commit*) P.newline f ; - in - (match Sys.getenv "OCAML_AMD_MODULE" with - | exception Not_found -> - ignore (node_program f program) - | _ -> amd_program f program ) ; - P.string f ( - match program.side_effect with - | None -> "/* No side effect */" - | Some v -> Printf.sprintf "/* %s Not a pure module */" v ); - P.newline f; - P.flush f () - + (match Js_config.get_env () with + | Browser -> + ignore (node_program f program) + | NodeJS -> + begin match Sys.getenv "OCAML_AMD_MODULE" with + | exception Not_found -> + ignore (node_program f program) + | _ -> amd_program f program + end ) ; + P.newline f ; + P.string f ( + match program.side_effect with + | None -> "/* No side effect */" + | Some v -> Printf.sprintf "/* %s Not a pure module */" v ); + P.newline f; + P.flush f () + end let dump_program (program : J.program) (oc : out_channel) = diff --git a/jscomp/js_generate_require.ml b/jscomp/js_generate_require.ml new file mode 100644 index 0000000000..728efa8850 --- /dev/null +++ b/jscomp/js_generate_require.ml @@ -0,0 +1,14 @@ + +let std_files = + String_set.elements Js_config.stdlib_set + |> List.map (fun x -> "./stdlib/" ^ x ) +let runtime_files = + String_set.elements Js_config.runtime_set + |> List.map (fun x -> "./runtime/" ^ x) + +let () = + Ext_pervasives.with_file_as_chan "./pre_load.js" (fun chan -> + output_string chan (Printf.sprintf "require([%s], function(){})" + (String.concat "," + (List.map (Printf.sprintf "%S" ) (std_files @ runtime_files)))) + ) diff --git a/jscomp/js_program_loader.ml b/jscomp/js_program_loader.ml index 5f50e1f373..d84b9e12a4 100644 --- a/jscomp/js_program_loader.ml +++ b/jscomp/js_program_loader.ml @@ -33,40 +33,51 @@ let string_of_module_id (x : module_id) : string = | Ml -> let id = x.id in let file = Printf.sprintf "%s.js" id.name in - if Ext_string.starts_with id.name "Caml_" then - let path = - (* For the runtime, only [JS] files are needed, and - unlike the stdlib, [osc] have some pre-built knowledge - about where it is, since in general, [runtime] - is *transparent* to the user - *) - match Sys.getenv "OCAML_JS_RUNTIME_PATH" with - | exception Not_found -> - Filename.concat - (Filename.dirname (Filename.dirname Sys.executable_name)) - "runtime" - | f -> f in - Ext_filename.node_relative_path !Location.input_name - (Filename.concat path (String.uncapitalize id.name)) - else - begin match Config_util.find file with - (* for some primitive files, no cmj support *) - | exception Not_found -> - Ext_log.warn __LOC__ "@[%s not found in search path - while compiling %s @] @." - file !Location.input_name ; - Printf.sprintf "%s" - (String.uncapitalize id.name) - (* maybe from third party library*) - (* Check: be consistent when generating js files - A.ml -> a.js - a.ml -> a.js - check generated [js] file if it's capital or not - Actually, we can not tell its original name just from [id], - so we just always general litte_case.js - *) - | path -> - Ext_filename.node_relative_path !Location.input_name path + begin match Js_config.get_env () with + | Browser + (* In browser *) + -> + let target = String.uncapitalize file in + if String_set.mem target Js_config.runtime_set then + "./runtime/" ^ target + else + "./stdlib/" ^ target + | NodeJS -> + if Ext_string.starts_with id.name "Caml_" then + let path = + (* For the runtime, only [JS] files are needed, and + unlike the stdlib, [osc] have some pre-built knowledge + about where it is, since in general, [runtime] + is *transparent* to the user + *) + match Sys.getenv "OCAML_JS_RUNTIME_PATH" with + | exception Not_found -> + Filename.concat + (Filename.dirname (Filename.dirname Sys.executable_name)) + "runtime" + | f -> f in + Ext_filename.node_relative_path !Location.input_name + (Filename.concat path (String.uncapitalize id.name)) + else + begin match Config_util.find file with + (* for some primitive files, no cmj support *) + | exception Not_found -> + Ext_log.warn __LOC__ "@[%s not found in search path - while compiling %s @] @." + file !Location.input_name ; + Printf.sprintf "%s" + (String.uncapitalize id.name) + (* maybe from third party library*) + (* Check: be consistent when generating js files + A.ml -> a.js + a.ml -> a.js + check generated [js] file if it's capital or not + Actually, we can not tell its original name just from [id], + so we just always general litte_case.js + *) + | path -> + Ext_filename.node_relative_path !Location.input_name path + end end | External name -> name diff --git a/jscomp/jsoo_driver.ml b/jscomp/jsoo_driver.ml index 6233ab8392..2701c11b4a 100644 --- a/jscomp/jsoo_driver.ml +++ b/jscomp/jsoo_driver.ml @@ -29,7 +29,7 @@ * type: "error" // or "warning" or "info" * } *) - +let () = Js_config.set_env Browser let implementation non_export ppf str = let modulename = "Test" in (* let env = !Toploop.toplevel_env in *) diff --git a/jscomp/lam_analysis.ml b/jscomp/lam_analysis.ml index 7f32b0570c..eb1ff687db 100644 --- a/jscomp/lam_analysis.ml +++ b/jscomp/lam_analysis.ml @@ -59,9 +59,6 @@ let rec no_side_effects (lam : Lambda.lambda) : bool = | Pbytes_of_string | Pchar_to_int (* might throw .. *) | Pchar_of_int - | Pignore - | Prevapply _ - | Pdirapply _ | Ploc _ | Pgetglobal _ @@ -120,6 +117,11 @@ let rec no_side_effects (lam : Lambda.lambda) : bool = | Pint_as_pointer | Poffsetint _ -> true + + | Pignore + | Prevapply _ + | Pdirapply _ + | Pstringsetu | Pstringsets | Pbytessetu diff --git a/jscomp/lam_compile_group.ml b/jscomp/lam_compile_group.ml index 1572c6fa71..daee7f3c8f 100644 --- a/jscomp/lam_compile_group.ml +++ b/jscomp/lam_compile_group.ml @@ -160,31 +160,40 @@ let compile ~filename non_export env _sigs lam : J.program = in let () = Translmod.reset () in (* To make toplevel happy - reentrant for js-demo *) let () = Lam_compile_env.reset () in - - let lam = Lam_group.deep_flatten lam in let _d = Lam_util.dump env filename in + let lam = _d lam in + let lam = Lam_group.deep_flatten lam in + let lam = _d lam in let meta = Lam_pass_collect.count_alias_globals env filename export_idents lam in let lam = let lam = lam + |> _d |> Lam_pass_exits.simplify_exits + |> _d |> Lam_pass_remove_alias.simplify_alias meta in (* Inling happens*) (* TODO: research how to combine those passes efficiently *) + let () = ignore @@ _d lam in let lam = Lam_group.deep_flatten lam in + let () = ignore @@ _d lam in let () = Lam_pass_collect.collect_helper meta lam in let lam = Lam_pass_remove_alias.simplify_alias meta lam in let lam = Lam_group.deep_flatten lam in let () = Lam_pass_collect.collect_helper meta lam in + let () = ignore @@ _d lam in let lam = lam |> Lam_pass_alpha_conversion.alpha_conversion meta |> Lam_pass_exits.simplify_exits in - let () = Lam_pass_collect.collect_helper meta lam - in + let () = Lam_pass_collect.collect_helper meta lam in + + lam + |> _d |> Lam_pass_remove_alias.simplify_alias meta + |> _d |> Lam_pass_alpha_conversion.alpha_conversion meta (* we should investigate a better way to put different passes : )*) |> Lam_pass_lets_dce.simplify_lets @@ -339,7 +348,7 @@ let lambda_as_module (lam : Lambda.lambda) = begin Lam_current_unit.set_file filename ; - Lam_current_unit.set_debug_file "ari_regress_test.ml"; + Lam_current_unit.iset_debug_file "ari_regress_test.ml"; Ext_pervasives.with_file_as_chan (Ext_filename.chop_extension ~loc:__LOC__ filename ^ ".js") (fun chan -> Js_dump.dump_program (compile ~filename false env sigs lam) chan) diff --git a/jscomp/lam_current_unit.ml b/jscomp/lam_current_unit.ml index d2147dce35..1fd67ad4c8 100644 --- a/jscomp/lam_current_unit.ml +++ b/jscomp/lam_current_unit.ml @@ -29,4 +29,5 @@ let iset_debug_file _ = () let set_debug_file f = debug_file := f let get_debug_file () = !debug_file -let is_same_file () = !debug_file = !file +let is_same_file () = + !debug_file != "" && !debug_file = !file diff --git a/jscomp/lam_dispatch_primitive.ml b/jscomp/lam_dispatch_primitive.ml index dbfb1bb9e7..bf8b50d09b 100644 --- a/jscomp/lam_dispatch_primitive.ml +++ b/jscomp/lam_dispatch_primitive.ml @@ -471,6 +471,7 @@ let query (prim : Lam_compile_env.primitive_description) | "caml_make_vect" -> E.runtime_call Js_helper.array prim.prim_name args + | "caml_ml_out_channels_list" | "caml_ml_open_descriptor_in" | "caml_ml_open_descriptor_out" | "caml_ml_output_char" @@ -582,7 +583,7 @@ let query (prim : Lam_compile_env.primitive_description) | "caml_ml_close_channel" | "caml_ml_output_int" | "caml_sys_exit" - | "caml_ml_out_channels_list" + | "caml_ml_channel_size_64" | "caml_ml_channel_size" | "caml_ml_pos_in_64" diff --git a/jscomp/lam_util.ml b/jscomp/lam_util.ml index 6edd0ab9c8..6ecd8163e0 100644 --- a/jscomp/lam_util.ml +++ b/jscomp/lam_util.ml @@ -276,9 +276,11 @@ let generate_label ?(name="") () = let log_counter = ref 0 -let dump env filename pred lam = +let dump env filename lam = incr log_counter ; - if pred + if Js_config.get_env () != Browser + (* TODO: when no [Browser] detection, it will go through.. bug in js_of_ocaml? *) + && Lam_current_unit.is_same_file () then Printlambda.seriaize env (Ext_filename.chop_extension ~loc:__LOC__ filename ^ diff --git a/jscomp/lam_util.mli b/jscomp/lam_util.mli index 7889b6b7b0..3dc7ac3b75 100644 --- a/jscomp/lam_util.mli +++ b/jscomp/lam_util.mli @@ -49,7 +49,9 @@ val sort_dag_args : J.expression Ident_map.t -> Ident.t list option TODO: make it a stable sort *) -val dump : Env.t -> string -> bool -> Lambda.lambda -> Lambda.lambda + +(** [dump] when {!Lam_current_unit.is_same_file}*) +val dump : Env.t -> string -> Lambda.lambda -> Lambda.lambda val ident_set_of_list : Ident.t list -> Ident_set.t diff --git a/jscomp/runtime/Makefile b/jscomp/runtime/Makefile index 6bdb98b1f3..f934f18f89 100644 --- a/jscomp/runtime/Makefile +++ b/jscomp/runtime/Makefile @@ -1,5 +1,6 @@ include ../Makefile.shared +CAMLC=../bin/osc SOURCE_LIST := $(shell cat runtime.mllib) @@ -15,7 +16,7 @@ clean:: rm -f *.annot rm -f *.rawlambda *.lam *.lambda *.map -CAMLC=../bin/osc + .mli.cmi: $(CAMLC) $(INCLUDES) $(COMPFLAGS) -c $< .ml.cmj: diff --git a/jscomp/runtime/caml_io.js b/jscomp/runtime/caml_io.js index 86e676658c..d414d782a2 100644 --- a/jscomp/runtime/caml_io.js +++ b/jscomp/runtime/caml_io.js @@ -109,6 +109,7 @@ function caml_ml_out_channels_list() { } return l; } +exports.caml_ml_out_channels_list = caml_ml_out_channels_list; function caml_std_output(chan, s) { var str = s; var slen = str.length; diff --git a/jscomp/runtime/caml_io.ts b/jscomp/runtime/caml_io.ts index b5c3e069f4..f9c54a4bd5 100644 --- a/jscomp/runtime/caml_io.ts +++ b/jscomp/runtime/caml_io.ts @@ -381,12 +381,13 @@ var stdout; var stderr; export { - stdin, - stdout, - stderr, - caml_ml_open_descriptor_in, - caml_ml_open_descriptor_out, - caml_ml_output_char, - caml_ml_output, - caml_ml_input_char + stdin, + stdout, + stderr, + caml_ml_open_descriptor_in, + caml_ml_open_descriptor_out, + caml_ml_output_char, + caml_ml_output, + caml_ml_input_char, + caml_ml_out_channels_list } \ No newline at end of file diff --git a/jscomp/runtime/caml_sys.js b/jscomp/runtime/caml_sys.js index a7afbc8d07..3b9049440d 100644 --- a/jscomp/runtime/caml_sys.js +++ b/jscomp/runtime/caml_sys.js @@ -23,7 +23,7 @@ var caml_array_1 = require('./caml_array'); var caml_exceptions_1 = require('./caml_exceptions'); function caml_sys_getenv(n) { //nodejs env - if (typeof process !== undefined + if (typeof process !== 'undefined' && process.env && process.env[n] != undefined) return process.env[n]; @@ -42,7 +42,7 @@ var IS_NODE_JS = true; function caml_sys_exit(code) { // process resides in global variable of // nodejs - if (IS_NODE_JS && process !== 'undefined') { + if (IS_NODE_JS && typeof process !== 'undefined') { process["exit"](code); } caml_exceptions_1.caml_invalid_argument("Function 'exit' not implemented"); diff --git a/jscomp/runtime/caml_sys.ts b/jscomp/runtime/caml_sys.ts index a0d6cc8675..633d3c7d73 100644 --- a/jscomp/runtime/caml_sys.ts +++ b/jscomp/runtime/caml_sys.ts @@ -26,7 +26,7 @@ import {caml_raise_not_found, caml_invalid_argument} from './caml_exceptions' function caml_sys_getenv (n : string) { //nodejs env - if(typeof process !== undefined + if(typeof process !== 'undefined' && process.env && process.env[n] != undefined) return process.env[n]; @@ -49,7 +49,7 @@ function caml_sys_exit (code) { // process resides in global variable of // nodejs - if(IS_NODE_JS && process !== 'undefined'){ + if(IS_NODE_JS && typeof process !== 'undefined'){ process["exit"](code); } diff --git a/jscomp/stdlib/pervasives.js b/jscomp/stdlib/pervasives.js index afaa50982e..bb9306f89b 100644 --- a/jscomp/stdlib/pervasives.js +++ b/jscomp/stdlib/pervasives.js @@ -218,7 +218,7 @@ function open_out_bin(name) { } function flush_all() { - var _param = Caml_primitive.caml_ml_out_channels_list(/* () */0); + var _param = Caml_io.caml_ml_out_channels_list(/* () */0); while(true) { var param = _param; if (param) { diff --git a/jscomp/test/.depend b/jscomp/test/.depend index 8868afd683..9ec0f6eb01 100644 --- a/jscomp/test/.depend +++ b/jscomp/test/.depend @@ -146,6 +146,8 @@ rec_value_test.cmo : mt.cmo ../stdlib/list.cmi ../stdlib/lazy.cmi rec_value_test.cmx : mt.cmx ../stdlib/list.cmx ../stdlib/lazy.cmx record_with_test.cmo : mt.cmo record_with_test.cmx : mt.cmx +regression_print.cmo : +regression_print.cmx : simple_lexer_test.cmo : ../stdlib/string.cmi mt.cmo ../stdlib/lexing.cmi simple_lexer_test.cmx : ../stdlib/string.cmx mt.cmx ../stdlib/lexing.cmx small_inline_test.cmo : @@ -500,6 +502,8 @@ rec_value_test.cmo : mt.cmo ../stdlib/list.cmi ../stdlib/lazy.cmi rec_value_test.cmj : mt.cmj ../stdlib/list.cmj ../stdlib/lazy.cmj record_with_test.cmo : mt.cmo record_with_test.cmj : mt.cmj +regression_print.cmo : +regression_print.cmj : simple_lexer_test.cmo : ../stdlib/string.cmi mt.cmo ../stdlib/lexing.cmi simple_lexer_test.cmj : ../stdlib/string.cmj mt.cmj ../stdlib/lexing.cmj small_inline_test.cmo : diff --git a/jscomp/test/regression_print.d.ts b/jscomp/test/regression_print.d.ts new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/jscomp/test/regression_print.d.ts @@ -0,0 +1 @@ + diff --git a/jscomp/test/regression_print.js b/jscomp/test/regression_print.js new file mode 100644 index 0000000000..1582980e90 --- /dev/null +++ b/jscomp/test/regression_print.js @@ -0,0 +1,9 @@ +// Generated CODE, PLEASE EDIT WITH CARE +"use strict"; + + +console.log(JSON.stringify(2)); + +console.log(JSON.stringify(1)); + +/* Not a pure module */ diff --git a/jscomp/test/regression_print.ml b/jscomp/test/regression_print.ml new file mode 100644 index 0000000000..37d1ca1d28 --- /dev/null +++ b/jscomp/test/regression_print.ml @@ -0,0 +1,11 @@ +include (struct +external to_str : 'a -> string = "js_json_stringify" +let debug x = print_endline (to_str x ) + +let () = + begin + debug @@ 2 ; + debug 1 + end + +end : sig end) diff --git a/jscomp/test/test.mllib b/jscomp/test/test.mllib index 21b09d3523..689db431dc 100644 --- a/jscomp/test/test.mllib +++ b/jscomp/test/test.mllib @@ -154,4 +154,5 @@ small_inline_test ari_regress_test record_with_test complex_if_test -module_parameter_test \ No newline at end of file +module_parameter_test +regression_print \ No newline at end of file diff --git a/jscomp/test/test_per.js b/jscomp/test/test_per.js index 3fb91c0a86..b83f6ee857 100644 --- a/jscomp/test/test_per.js +++ b/jscomp/test/test_per.js @@ -224,7 +224,7 @@ function open_out_bin(name) { } function flush_all() { - var _param = Caml_primitive.caml_ml_out_channels_list(/* () */0); + var _param = Caml_io.caml_ml_out_channels_list(/* () */0); while(true) { var param = _param; if (param) {