Skip to content

Commit

Permalink
Merge remote-tracking branch 'jsoo/master' into converge-jsoo-tip-07
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierNicole committed Sep 26, 2024
2 parents 92108c7 + 30d4cd4 commit 58c61ef
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 62 deletions.
6 changes: 0 additions & 6 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
"rules": {
"recommended": true,
"complexity": {
"noUselessSwitchCase": "off",
"noUselessTernary": "off",
"useArrowFunction": "off",
"useOptionalChain": "off"
},
Expand All @@ -36,16 +34,12 @@
"noUselessElse": "off",
"noVar": "off",
"useExponentiationOperator": "off",
"useNodejsImportProtocol": "off",
"useSingleVarDeclarator": "off",
"useTemplate": "off"
},
"suspicious": {
"noAssignInExpressions": "off",
"noConfusingLabels": "off",
"noControlCharactersInRegex": "off",
"noDoubleEquals": "off",
"noDuplicateCase": "off",
"noFallthroughSwitchClause": "off",
"noRedeclare": "off",
"noSelfCompare": "off",
Expand Down
12 changes: 6 additions & 6 deletions compiler/lib/code.ml
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,10 @@ type constant =
| NativeString of Native_string.t
| Float of float
| Float_array of float array
| Int of int32
| Int32 of int32
| Int64 of int64
| NativeInt of nativeint
| Int of Int32.t
| Int32 of Int32.t
| Int64 of Int64.t
| NativeInt of Int32.t (* Native int are 32bit on all known backend *)
| Tuple of int * constant array * array_or_not

module Constant = struct
Expand All @@ -354,7 +354,7 @@ module Constant = struct
!same
| Int a, Int b | Int32 a, Int32 b -> Some (Int32.equal a b)
| Int64 a, Int64 b -> Some (Int64.equal a b)
| NativeInt a, NativeInt b -> Some (Nativeint.equal a b)
| NativeInt a, NativeInt b -> Some (Int32.equal a b)
| Float_array a, Float_array b -> Some (Array.equal Float.ieee_equal a b)
| Float a, Float b -> Some (Float.ieee_equal a b)
| String _, NativeString _ | NativeString _, String _ -> None
Expand Down Expand Up @@ -500,7 +500,7 @@ module Print = struct
| Int i -> Format.fprintf f "%ld" i
| Int32 i -> Format.fprintf f "%ldl" i
| Int64 i -> Format.fprintf f "%LdL" i
| NativeInt i -> Format.fprintf f "%ndn" i
| NativeInt i -> Format.fprintf f "%ldn" i
| Tuple (tag, a, _) -> (
Format.fprintf f "<%d>" tag;
match Array.length a with
Expand Down
8 changes: 4 additions & 4 deletions compiler/lib/code.mli
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ type constant =
| NativeString of Native_string.t
| Float of float
| Float_array of float array
| Int of int32
| Int32 of int32 (** Only produced when compiling to WebAssembly. *)
| Int64 of int64
| NativeInt of nativeint (** Only produced when compiling to WebAssembly. *)
| Int of Int32.t
| Int32 of Int32.t (** Only produced when compiling to WebAssembly. *)
| Int64 of Int64.t
| NativeInt of Int32.t (** Only produced when compiling to WebAssembly. *)
| Tuple of int * constant array * array_or_not

module Constant : sig
Expand Down
6 changes: 2 additions & 4 deletions runtime/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function caml_compare_val(a, b, total) {
caml_invalid_argument("equal: got Double_tag, should not happen");
break;
case 254: // Double_array_tag
// Cannot happen, handled above
// Cannot happen, handled in caml_compare_val_tag
caml_invalid_argument(
"equal: got Double_array_tag, should not happen",
);
Expand Down Expand Up @@ -236,9 +236,7 @@ function caml_compare_val(a, b, total) {
if (a > b) return 1;
}
break;
case 246: // Lazy_tag
case 254: // Double_array
default: // Block with other tag
default: // Lazy_tag or Block with other tag
if (caml_is_continuation_tag(tag_a)) {
caml_invalid_argument("compare: continuation value");
break;
Expand Down
18 changes: 5 additions & 13 deletions runtime/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,6 @@ function caml_raise_no_such_file(name) {
caml_raise_sys_error(name + ": No such file or directory");
}

//Provides: caml_raise_not_a_dir
//Requires: caml_raise_sys_error
function caml_raise_not_a_dir(name) {
caml_raise_sys_error(name + ": Not a directory");
}

//Provides: caml_sys_file_exists
//Requires: resolve_fs_device
function caml_sys_file_exists(name) {
Expand All @@ -237,7 +231,7 @@ function caml_sys_file_exists(name) {

//Provides: caml_sys_read_directory
//Requires: caml_string_of_jsbytes
//Requires: caml_raise_not_a_dir, resolve_fs_device
//Requires: resolve_fs_device
function caml_sys_read_directory(name) {
var root = resolve_fs_device(name);
var a = root.device.readdir(root.rest);
Expand All @@ -248,12 +242,10 @@ function caml_sys_read_directory(name) {
}

//Provides: caml_sys_remove
//Requires: caml_raise_no_such_file, resolve_fs_device, caml_jsbytes_of_string
//Requires: resolve_fs_device
function caml_sys_remove(name) {
var root = resolve_fs_device(name);
var ok = root.device.unlink(root.rest);
if (ok == 0) caml_raise_no_such_file(caml_jsbytes_of_string(name));
return 0;
return root.device.unlink(root.rest);
}

//Provides: caml_sys_is_directory
Expand All @@ -276,15 +268,15 @@ function caml_sys_rename(o, n) {
}

//Provides: caml_sys_mkdir
//Requires: resolve_fs_device, caml_raise_sys_error
//Requires: resolve_fs_device
function caml_sys_mkdir(name, perm) {
var root = resolve_fs_device(name);
root.device.mkdir(root.rest, perm);
return 0;
}

//Provides: caml_sys_rmdir
//Requires: resolve_fs_device, caml_raise_sys_error, caml_raise_not_a_dir
//Requires: resolve_fs_device
function caml_sys_rmdir(name) {
var root = resolve_fs_device(name);
root.device.rmdir(root.rest);
Expand Down
11 changes: 7 additions & 4 deletions runtime/fs_fake.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ MlFakeDevice.prototype.lookup = function (name) {
}
}
};
MlFakeDevice.prototype.exists = function (name) {
MlFakeDevice.prototype.exists = function (name, do_not_lookup) {
// The root of the device exists
if (name == "") return 1;
// Check if a directory exists
var name_slash = this.slash(name);
if (this.content[name_slash]) return 1;
// Check if a file exists
this.lookup(name);
if (!do_not_lookup) this.lookup(name);
return this.content[name] ? 1 : 0;
};
MlFakeDevice.prototype.isFile = function (name) {
Expand Down Expand Up @@ -213,9 +213,12 @@ MlFakeDevice.prototype.is_dir = function (name) {
return this.content[name_slash] ? 1 : 0;
};
MlFakeDevice.prototype.unlink = function (name) {
var ok = this.content[name] ? true : false;
if (!this.exists(name, true)) {
// [true] means no "lookup" if not found.
caml_raise_sys_error(name + ": No such file or directory");
}
delete this.content[name];
return ok;
return 0;
};
MlFakeDevice.prototype.open = function (name, f) {
var file;
Expand Down
11 changes: 5 additions & 6 deletions runtime/fs_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function fs_node_supported() {
//Requires: MlNodeFd, caml_raise_sys_error, caml_raise_with_args
//Requires: make_unix_err_args, caml_named_value, caml_string_of_jsstring
function MlNodeDevice(root) {
this.fs = require("fs");
this.fs = require("node:fs");
this.root = root;
}
MlNodeDevice.prototype.nm = function (name) {
Expand Down Expand Up @@ -87,15 +87,14 @@ MlNodeDevice.prototype.is_dir = function (name) {
};
MlNodeDevice.prototype.unlink = function (name, raise_unix) {
try {
var b = this.fs.existsSync(this.nm(name)) ? 1 : 0;
this.fs.unlinkSync(this.nm(name));
return b;
return 0;
} catch (err) {
this.raise_nodejs_error(err, raise_unix);
}
};
MlNodeDevice.prototype.open = function (name, f, raise_unix) {
var consts = require("constants");
var consts = require("node:constants");
var res = 0;
for (var key in f) {
switch (key) {
Expand Down Expand Up @@ -268,7 +267,7 @@ function MlNodeDevice() {}
//Provides: MlNodeFd
//Requires: MlFile, caml_uint8_array_of_string, caml_uint8_array_of_bytes, caml_bytes_set, caml_raise_sys_error
function MlNodeFd(fd, flags) {
this.fs = require("fs");
this.fs = require("node:fs");
this.fd = fd;
this.flags = flags;
}
Expand Down Expand Up @@ -327,7 +326,7 @@ function MlNodeFd() {}
function caml_sys_open_for_node(fd, flags) {
if (flags.name) {
try {
var fs = require("fs");
var fs = require("node:fs");
var fd2 = fs.openSync(flags.name, "rs");
return new MlNodeFd(fd2, flags);
} catch (e) {}
Expand Down
22 changes: 8 additions & 14 deletions runtime/internalMod.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,10 @@ function caml_CamlinternalMod_init_mod(loc, shape) {
//Version: < 4.13
function caml_CamlinternalMod_update_mod(shape, real, x) {
if (typeof shape === "number")
switch (shape) {
case 0: //function
case 1: //lazy
case 2: //class
default:
caml_update_dummy(real, x);
}
//function
//lazy
//class
caml_update_dummy(real, x);
else
switch (shape[0]) {
case 0: //module
Expand Down Expand Up @@ -123,13 +120,10 @@ function caml_CamlinternalMod_init_mod(loc, shape, cont) {
function caml_CamlinternalMod_update_mod(shape, real, x, cont) {
function loop(shape, real, x) {
if (typeof shape === "number")
switch (shape) {
case 0: //function
case 1: //lazy
case 2: //class
default:
caml_update_dummy(real, x);
}
//function
//lazy
//class
caml_update_dummy(real, x);
else
switch (shape[0]) {
case 0: //module
Expand Down
6 changes: 5 additions & 1 deletion runtime/marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,11 @@ function caml_marshal_data_size(s, ofs) {
);
}
break;
case 0x8495a6bf: /* Intext_magic_number_big */
case 0x8495a6bf /* Intext_magic_number_big */:
caml_failwith(
"Marshal.data_size: object too large to be read back on a 32-bit platform",
);
break;
default:
caml_failwith("Marshal.data_size: bad object");
break;
Expand Down
5 changes: 4 additions & 1 deletion runtime/mlBytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ function jsoo_is_ascii(s) {
// Spidermonkey gets much slower when s.length >= 24 (on 64 bit archs)
for (var i = 0; i < s.length; i++) if (s.charCodeAt(i) > 127) return false;
return true;
} else return !/[^\x00-\x7f]/.test(s);
}
// biome-ignore lint/suspicious/noControlCharactersInRegex: expected
else return !/[^\x00-\x7f]/.test(s);
}

//Provides: caml_bytes_unsafe_get mutable
Expand Down Expand Up @@ -907,6 +909,7 @@ function caml_ml_bytes_content(s) {
//Requires: jsoo_is_ascii
//If: js-string
function caml_is_ml_string(s) {
// biome-ignore lint/suspicious/noControlCharactersInRegex: expected
return typeof s === "string" && !/[^\x00-\xff]/.test(s);
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/sys.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function caml_sys_executable_name(a) {
function caml_sys_system_command(cmd) {
var cmd = caml_jsstring_of_string(cmd);
if (typeof require != "undefined") {
var child_process = require("child_process");
var child_process = require("node:child_process");
if (child_process && child_process.execSync)
try {
child_process.execSync(cmd, { stdio: "inherit" });
Expand Down
5 changes: 3 additions & 2 deletions runtime/unix.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function caml_unix_filedescr_of_fd(x) {
//Alias: unix_isatty
function caml_unix_isatty(fileDescriptor) {
if (fs_node_supported()) {
var tty = require("tty");
var tty = require("node:tty");
return tty.isatty(fileDescriptor) ? 1 : 0;
} else {
return 0;
Expand Down Expand Up @@ -296,7 +296,8 @@ function caml_unix_unlink(name) {
if (!root.device.unlink) {
caml_failwith("caml_unix_unlink: not implemented");
}
return root.device.unlink(root.rest, /* raise Unix_error */ true);
root.device.unlink(root.rest, /* raise Unix_error */ true);
return 0;
}

//Provides: caml_unix_getuid
Expand Down

0 comments on commit 58c61ef

Please sign in to comment.