Skip to content

Modernize stdlib #1764

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

Merged
merged 3 commits into from
Dec 30, 2024
Merged
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 EMCASCRIPT.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Features are grouped by ECMAScript version.
## ECMAScript 2015 - ES6
### rest parameters
- added in Nodejs 6
### spread in function call
- added in Nodejs 5
### Object.assign
- added In Nodejs 4
### ArrowFunction
Expand Down
2 changes: 0 additions & 2 deletions compiler/lib-runtime-files/tests/all.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ let%expect_test _ =
+prng.js
+runtime_events.js
+stdlib.js
+stdlib_modern.js
+str.js
+sync.js
+sys.js
Expand Down Expand Up @@ -98,5 +97,4 @@ let%expect_test _ =
printl extra;
[%expect {|
+dynlink.js
+stdlib_modern.js
+toplevel.js |}]
2 changes: 1 addition & 1 deletion compiler/tests-compiler/gh1051.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
let prog = {|let () = Printf.printf "%nx" 0xffffffffn;;|}

let%expect_test _ =
Util.compile_and_run ~skip_modern:true prog;
Util.compile_and_run prog;
[%expect
{|
Warning: integer overflow: native integer 0xffffffff (4294967295) truncated to 0xffffffff (-1); the generated code might be incorrect.
Expand Down
31 changes: 3 additions & 28 deletions compiler/tests-compiler/util/util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -566,23 +566,15 @@ let compile_and_run_bytecode ?unix s =
|> run_bytecode
|> print_endline)

let compile_and_run
?debug
?pretty
?(skip_modern = false)
?(flags = [])
?effects
?use_js_string
?unix
s =
let compile_and_run ?debug ?pretty ?(flags = []) ?effects ?use_js_string ?unix s =
with_temp_dir ~f:(fun () ->
let bytecode_file =
s
|> Filetype.ocaml_text_of_string
|> Filetype.write_ocaml ~name:"test.ml"
|> compile_ocaml_to_bc ?debug ?unix
in
let output_without_stdlib_modern =
let output =
compile_bc_to_javascript
?pretty
~flags
Expand All @@ -592,24 +584,7 @@ let compile_and_run
bytecode_file
|> run_javascript
in
print_endline output_without_stdlib_modern;
if not skip_modern
then
let output_with_stdlib_modern =
compile_bc_to_javascript
~flags:(flags @ [ "+stdlib_modern.js" ])
?effects
?use_js_string
?sourcemap:debug
bytecode_file
|> run_javascript
in
if not (String.equal output_without_stdlib_modern output_with_stdlib_modern)
then (
print_endline "Output was different with stdlib_modern.js:";
print_endline "===========================================";
print_string output_with_stdlib_modern;
print_endline "==========================================="))
print_endline output)

let compile_and_parse_whole_program
?(debug = true)
Expand Down
1 change: 0 additions & 1 deletion compiler/tests-compiler/util/util.mli
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ val print_double_fun_decl : Javascript.program -> string -> unit
val compile_and_run :
?debug:bool
-> ?pretty:bool
-> ?skip_modern:bool
-> ?flags:string list
-> ?effects:[ `Disabled | `Cps | `Double_translation ]
-> ?use_js_string:bool
Expand Down
19 changes: 10 additions & 9 deletions runtime/js/stdlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ function caml_call_gen(f, args) {
var n = f.l >= 0 ? f.l : (f.l = f.length);
var argsLen = args.length;
var d = n - argsLen;
if (d === 0) return f.apply(null, args);
if (d === 0) return f(...args);
else if (d < 0) {
var g = f.apply(null, args.slice(0, n));
var g = f(...args.slice(0, n));
if (typeof g !== "function") return g;
return caml_call_gen(g, args.slice(n));
} else {
Expand All @@ -36,7 +36,7 @@ function caml_call_gen(f, args) {
var nargs = new Array(argsLen + 1);
for (var i = 0; i < argsLen; i++) nargs[i] = args[i];
nargs[argsLen] = x;
return f.apply(null, nargs);
return f(...nargs);
};
break;
}
Expand All @@ -46,7 +46,7 @@ function caml_call_gen(f, args) {
for (var i = 0; i < argsLen; i++) nargs[i] = args[i];
nargs[argsLen] = x;
nargs[argsLen + 1] = y;
return f.apply(null, nargs);
return f(...nargs);
};
break;
}
Expand All @@ -70,8 +70,9 @@ function caml_call_gen(f, args) {
var n = f.l >= 0 ? f.l : (f.l = f.length);
var argsLen = args.length;
var d = n - argsLen;
if (d === 0) return f.apply(null, args);
else if (d < 0) {
if (d === 0) {
return f(...args);
} else if (d < 0) {
var rest = args.slice(n - 1);
var k = args[argsLen - 1];
args = args.slice(0, n);
Expand All @@ -81,7 +82,7 @@ function caml_call_gen(f, args) {
args[args.length - 1] = k;
return caml_call_gen(g, args);
};
return f.apply(null, args);
return f(...args);
} else {
argsLen--;
var k = args[argsLen];
Expand All @@ -92,7 +93,7 @@ function caml_call_gen(f, args) {
for (var i = 0; i < argsLen; i++) nargs[i] = args[i];
nargs[argsLen] = x;
nargs[argsLen + 1] = y;
return f.apply(null, nargs);
return f(...nargs);
};
break;
}
Expand All @@ -103,7 +104,7 @@ function caml_call_gen(f, args) {
nargs[argsLen] = x;
nargs[argsLen + 1] = y;
nargs[argsLen + 2] = z;
return f.apply(null, nargs);
return f(...nargs);
};
break;
}
Expand Down
205 changes: 0 additions & 205 deletions runtime/js/stdlib_modern.js

This file was deleted.

Loading