Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Esy compat #1

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,5 @@ jscomp/outcome_printer/reason_syntax_util.mli
jscomp/bin/all_ounit_tests.ml
native/
vendor/ocaml

_esy
4 changes: 4 additions & 0 deletions OCAML_VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
4.06.1+BS

# The version string is the first line of this file.
# It must be in the format described in stdlib/sys.mli
61 changes: 61 additions & 0 deletions esy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "reason-rocket",
"version": "5.1.0",
"devDependencies": {
"ocaml": "~4.2.3000"
},
"peerDependencies": {
"ocaml": " >= 4.2.3"
},
"esy": {
"buildsInSource": true,
"build": [["node", "scripts/install.js"]],
"install": ["make install"],
"exportedEnv": {
"OCAMLLIB": {
"val": "#{self.lib / 'ocaml' }",
"scope": "global"
},
"CAML_LD_LIBRARY_PATH": {
"val": "#{self.lib / 'ocaml' / 'stublibs' : self.lib / 'ocaml' : $CAML_LD_LIBRARY_PATH}",
"scope": "global"
},
"OCAML_TOPLEVEL_PATH": {
"val": "#{self.lib / 'ocaml' }",
"scope": "global"
},
"bs_custom_resolution": {
"val": "true",
"scope": "global"
},
"bs_platform__install": {
"val": "#{self.install}",
"scope": "global"
},
"PATH": {
"val": "#{reason-rocket.lib : $PATH}",
"scope": "global"
}
}
},
"description": "bucklescript compiler for use in esy, ocaml standard libary by bucklescript and its required runtime support",
"repository": {
"type": "git",
"url": "git+https://github.com/reuniverse/reason-rocket.git"
},
"keywords": ["ocaml", "bucklescript", "stdlib", "functional programming"],
"author": {
"name": "Hongbo Zhang"
},
"maintainers": [
{
"name": "reuniverse",
"email": "[email protected]"
}
],
"license": "SEE LICENSE IN LICENSE",
"bugs": {
"url": "https://github.com/reuniverse/reason-rocket/issues"
},
"homepage": "https://github.com/reuniverse/reason-rocket#readme"
}
3 changes: 3 additions & 0 deletions esy.lock/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

# Set eol to LF so files aren't converted to CRLF-eol on Windows.
* text eol=lf
3 changes: 3 additions & 0 deletions esy.lock/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

# Reset any possible .gitignore, we want all esy.lock to be un-ignored.
!*
43 changes: 43 additions & 0 deletions esy.lock/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"checksum": "e17c6dafb73c8efbaf344e301ebfa25d",
"root": "reason-rocket@link-dev:./esy.json",
"node": {
"reason-rocket@link-dev:./esy.json": {
"id": "reason-rocket@link-dev:./esy.json",
"name": "reason-rocket",
"version": "link-dev:./esy.json",
"source": { "type": "link-dev", "path": ".", "manifest": "esy.json" },
"overrides": [],
"dependencies": [ "[email protected]@d41d8cd9" ],
"devDependencies": [ "[email protected]@d41d8cd9" ]
},
"[email protected]@d41d8cd9": {
"id": "[email protected]@d41d8cd9",
"name": "ocaml",
"version": "4.2.3007",
"source": {
"type": "install",
"source": [
"archive:https://registry.npmjs.org/ocaml/-/ocaml-4.2.3007.tgz#sha1:b36f3357f7da99e43e19d60c2c2cfb69bd8ab66d"
]
},
"overrides": [],
"dependencies": [ "[email protected]@d41d8cd9" ],
"devDependencies": []
},
"[email protected]@d41d8cd9": {
"id": "[email protected]@d41d8cd9",
"name": "flexdll-prebuilt",
"version": "0.37.4",
"source": {
"type": "install",
"source": [
"archive:https://registry.npmjs.org/flexdll-prebuilt/-/flexdll-prebuilt-0.37.4.tgz#sha1:c48478f4b2420a75e8dac9172f89c57bbf192598"
]
},
"overrides": [],
"dependencies": [],
"devDependencies": []
}
}
}
61 changes: 61 additions & 0 deletions jscomp/bsb/bsb_pkg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,64 @@ let resolve_bs_package ~cwd (package : t) =
(* (\* Bs_exception.error (Bs_package_not_found name) *\) *)
(* in *)
(* aux cwd *)

(* Some package managers will implement "postinstall" caches, that do not
* keep their build artifacts in the local node_modules. Similar to
* npm_config_prefix, bs_custom_resolution allows these to specify the
* exact location of build cache, but on a per-package basis. Implemented as
* environment lookup to avoid invasive changes to bsconfig and mandates. *)
let custom_resolution =
match Sys.getenv "bs_custom_resolution" with
| exception Not_found -> false
| "true" -> true
| _ -> false

let regex_at = Str.regexp "@"
let regex_unders = Str.regexp "_+"
let regex_slash = Str.regexp "\\/"
let regex_dot = Str.regexp "\\."
let regex_hyphen = Str.regexp "-"
let pkg_name_as_variable pkg =
Bsb_pkg_types.to_string pkg
|> Str.replace_first regex_at ""
|> Str.global_replace regex_unders "\\0_"
|> Str.global_replace regex_slash "__slash__"
|> Str.global_replace regex_dot "__dot__"
|> Str.global_replace regex_hyphen "_"

let resolve_bs_package ~cwd (pkg : t) =
if custom_resolution then
begin
Bsb_log.info "@{<error>Using Custom Resolution@}@.";
let custom_pkg_loc = pkg_name_as_variable pkg ^ "__install" in
match Sys.getenv custom_pkg_loc with
| exception Not_found ->
begin
Bsb_log.error
"@{<error>Custom resolution of package %s does not exist in var %s @}@."
(Bsb_pkg_types.to_string pkg)
custom_pkg_loc;
Bsb_exception.package_not_found ~pkg ~json:None
end
| path when not (Sys.file_exists path) ->
begin
Bsb_log.error
"@{<error>Custom resolution of package %s does not exist on disk: %s=%s @}@."
(Bsb_pkg_types.to_string pkg)
custom_pkg_loc
path;
Bsb_exception.package_not_found ~pkg ~json:None
end
| path ->
begin
Bsb_log.info
"@{<error>Custom Resolution of package %s in var %s found at %s@}@."
(Bsb_pkg_types.to_string pkg)
custom_pkg_loc
path;
path
end
end
else
resolve_bs_package ~cwd pkg
end
34 changes: 17 additions & 17 deletions jscomp/ext/ext_json_parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ let lf = '\010'

# 124 "ext/ext_json_parse.ml"
let __ocaml_lex_tables = {
Lexing.lex_base =
Lexing.lex_base =
"\000\000\239\255\240\255\241\255\000\000\025\000\011\000\244\255\
\245\255\246\255\247\255\248\255\249\255\000\000\000\000\000\000\
\041\000\001\000\254\255\005\000\005\000\253\255\001\000\002\000\
Expand All @@ -131,7 +131,7 @@ let __ocaml_lex_tables = {
\001\000\253\255\254\255\023\000\255\255\006\000\246\255\189\000\
\248\255\215\000\255\255\249\255\249\000\181\000\252\255\009\000\
\063\000\075\000\234\000\251\255\032\001\250\255";
Lexing.lex_backtrk =
Lexing.lex_backtrk =
"\255\255\255\255\255\255\255\255\013\000\013\000\016\000\255\255\
\255\255\255\255\255\255\255\255\255\255\016\000\016\000\016\000\
\016\000\016\000\255\255\000\000\012\000\255\255\255\255\255\255\
Expand All @@ -140,7 +140,7 @@ let __ocaml_lex_tables = {
\255\255\255\255\255\255\001\000\255\255\255\255\255\255\008\000\
\255\255\255\255\255\255\255\255\006\000\006\000\255\255\006\000\
\001\000\002\000\255\255\255\255\255\255\255\255";
Lexing.lex_default =
Lexing.lex_default =
"\001\000\000\000\000\000\000\000\255\255\255\255\255\255\000\000\
\000\000\000\000\000\000\000\000\000\000\255\255\255\255\255\255\
\255\255\255\255\000\000\255\255\020\000\000\000\255\255\255\255\
Expand All @@ -149,7 +149,7 @@ let __ocaml_lex_tables = {
\042\000\000\000\000\000\255\255\000\000\047\000\000\000\047\000\
\000\000\051\000\000\000\000\000\255\255\255\255\000\000\255\255\
\255\255\255\255\255\255\000\000\255\255\000\000";
Lexing.lex_trans =
Lexing.lex_trans =
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
\000\000\019\000\018\000\018\000\019\000\017\000\019\000\255\255\
\048\000\019\000\255\255\057\000\000\000\000\000\000\000\000\000\
Expand Down Expand Up @@ -219,7 +219,7 @@ let __ocaml_lex_tables = {
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
\000\000";
Lexing.lex_check =
Lexing.lex_check =
"\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
\255\255\000\000\000\000\017\000\000\000\000\000\019\000\020\000\
\045\000\019\000\020\000\055\000\255\255\255\255\255\255\255\255\
Expand Down Expand Up @@ -289,22 +289,22 @@ let __ocaml_lex_tables = {
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
\255\255";
Lexing.lex_base_code =
Lexing.lex_base_code =
"";
Lexing.lex_backtrk_code =
Lexing.lex_backtrk_code =
"";
Lexing.lex_default_code =
Lexing.lex_default_code =
"";
Lexing.lex_trans_code =
Lexing.lex_trans_code =
"";
Lexing.lex_check_code =
Lexing.lex_check_code =
"";
Lexing.lex_code =
Lexing.lex_code =
"";
}

let rec lex_json buf lexbuf =
__ocaml_lex_lex_json_rec buf lexbuf 0
__ocaml_lex_lex_json_rec buf lexbuf 0
and __ocaml_lex_lex_json_rec buf lexbuf __ocaml_lex_state =
match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with
| 0 ->
Expand Down Expand Up @@ -406,11 +406,11 @@ let
( error lexbuf (Illegal_character c ))
# 408 "ext/ext_json_parse.ml"

| __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf;
| __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf;
__ocaml_lex_lex_json_rec buf lexbuf __ocaml_lex_state

and comment buf lexbuf =
__ocaml_lex_comment_rec buf lexbuf 40
__ocaml_lex_comment_rec buf lexbuf 40
and __ocaml_lex_comment_rec buf lexbuf __ocaml_lex_state =
match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with
| 0 ->
Expand All @@ -428,11 +428,11 @@ and __ocaml_lex_comment_rec buf lexbuf __ocaml_lex_state =
(error lexbuf Unterminated_comment)
# 430 "ext/ext_json_parse.ml"

| __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf;
| __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf;
__ocaml_lex_comment_rec buf lexbuf __ocaml_lex_state

and scan_string buf start lexbuf =
__ocaml_lex_scan_string_rec buf start lexbuf 45
__ocaml_lex_scan_string_rec buf start lexbuf 45
and __ocaml_lex_scan_string_rec buf start lexbuf __ocaml_lex_state =
match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with
| 0 ->
Expand Down Expand Up @@ -567,7 +567,7 @@ let
)
# 569 "ext/ext_json_parse.ml"

| __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf;
| __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf;
__ocaml_lex_scan_string_rec buf start lexbuf __ocaml_lex_state

;;
Expand Down
40 changes: 40 additions & 0 deletions jscomp/test/406_primitive_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

var Mt = require("./mt.js");
var Caml_exceptions = require("../../lib/js/caml_exceptions.js");
var Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js");

var suites = /* record */[/* contents : [] */0];

Expand All @@ -10,9 +12,47 @@ function eq(loc, x, y) {
return Mt.eq_suites(test_id, suites, loc, x, y);
}

var v = 32;

eq("File \"406_primitive_test.ml\", line 18, characters 6-13", v, 32);

var backend_type = /* Other */["BS"];

var max_array_length = 2147483647;

eq("File \"406_primitive_test.ml\", line 29, characters 6-13", backend_type, /* Other */["BS"]);

function f(param) {
var A = Caml_exceptions.create("A");
try {
for(var i = 0; i <= 200; ++i){
if (i === 10) {
throw [
A,
0
];
}

}
return /* () */0;
}
catch (raw_exn){
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
if (exn[0] === A) {
return /* () */0;
} else {
throw exn;
}
}
}

Mt.from_pair_suites("406_primitive_test", suites[0]);

exports.suites = suites;
exports.test_id = test_id;
exports.eq = eq;
exports.v = v;
exports.backend_type = backend_type;
exports.max_array_length = max_array_length;
exports.f = f;
/* Not a pure module */
17 changes: 8 additions & 9 deletions jscomp/test/adt_optimize_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,20 @@ function f8(param) {

function f9(param) {
if (typeof param === "number") {
switch (param) {
case 0 :
case 1 :
case 2 :
return 1;
default:
return 3;
if (param === 3) {
return 3;
} else {
return 1;
}
} else {
switch (param.tag | 0) {
case 0 :
case 1 :
return 2;
default:
return 3;
case 2 :
case 3 :
return 3;

}
}
}
Expand Down
Loading