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

Better runtime code #1672

Closed
wants to merge 12 commits into from
18 changes: 16 additions & 2 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.1/schema.json",
"$schema": "https://biomejs.dev/schemas/1.9.2/schema.json",
"files": {
"include": ["runtime"],
"ignore": ["runtime/zstd.ts"]
Expand All @@ -9,7 +9,21 @@
"useEditorconfig": true
},
"linter": {
"enabled": false
"enabled": true,
"rules": {
"recommended": true,
"style": {
"noParameterAssign": "off",
"useNamingConvention": "off"
},
"suspicious": {
"noAssignInExpressions": "off",
"noFallthroughSwitchClause": "off",
"noRedeclare": "off",
"noSelfCompare": "off",
"useDefaultSwitchClauseLast": "off"
}
}
},
"organizeImports": {
"enabled": true
Expand Down
53 changes: 14 additions & 39 deletions runtime/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,20 @@

//Provides: caml_array_sub mutable
function caml_array_sub(a, i, len) {
var a2 = new Array(len + 1);
a2[0] = 0;
for (var i2 = 1, i1 = i + 1; i2 <= len; i2++, i1++) {
a2[i2] = a[i1];
}
return a2;
return [0, ...a.slice(i + 1, i + len + 1)];
}

//Provides: caml_array_append mutable
function caml_array_append(a1, a2) {
var l1 = a1.length,
l2 = a2.length;
var l = l1 + l2 - 1;
var a = new Array(l);
a[0] = 0;
var i = 1,
j = 1;
for (; i < l1; i++) a[i] = a1[i];
for (; i < l; i++, j++) a[i] = a2[j];
return a;
return [0, ...a1.slice(1), ...a2.slice(1)];
}

//Provides: caml_array_concat mutable
function caml_array_concat(l) {
var a = [0];
const a = [0];
while (l !== 0) {
var b = l[1];
for (var i = 1; i < b.length; i++) a.push(b[i]);
const b = l[1];
for (let i = 1; i < b.length; i++) a.push(b[i]);
l = l[2];
}
return a;
Expand All @@ -55,19 +41,19 @@ function caml_array_concat(l) {
//Provides: caml_array_blit
function caml_array_blit(a1, i1, a2, i2, len) {
if (i2 <= i1) {
for (var j = 1; j <= len; j++) a2[i2 + j] = a1[i1 + j];
for (let j = 1; j <= len; j++) a2[i2 + j] = a1[i1 + j];
} else {
for (var j = len; j >= 1; j--) a2[i2 + j] = a1[i1 + j];
for (let j = len; j >= 1; j--) a2[i2 + j] = a1[i1 + j];
}
return 0;
}

//Provides: caml_floatarray_blit
function caml_floatarray_blit(a1, i1, a2, i2, len) {
if (i2 <= i1) {
for (var j = 1; j <= len; j++) a2[i2 + j] = a1[i1 + j];
for (let j = 1; j <= len; j++) a2[i2 + j] = a1[i1 + j];
} else {
for (var j = len; j >= 1; j--) a2[i2 + j] = a1[i1 + j];
for (let j = len; j >= 1; j--) a2[i2 + j] = a1[i1 + j];
}
return 0;
}
Expand All @@ -90,7 +76,7 @@ function caml_array_get(array, index) {

//Provides: caml_array_fill
function caml_array_fill(array, ofs, len, v) {
for (var i = 0; i < len; i++) {
for (let i = 0; i < len; i++) {
array[ofs + i + 1] = v;
}
return 0;
Expand All @@ -107,30 +93,19 @@ function caml_check_bound(array, index) {
//Requires: caml_array_bound_error
function caml_make_vect(len, init) {
if (len < 0) caml_array_bound_error();
var len = (len + 1) | 0;
var b = new Array(len);
b[0] = 0;
for (var i = 1; i < len; i++) b[i] = init;
return b;
return [0, ...new Array(len | 0).fill(init)];
}

//Provides: caml_make_float_vect const (const)
//Requires: caml_array_bound_error
function caml_make_float_vect(len) {
if (len < 0) caml_array_bound_error();
var len = (len + 1) | 0;
var b = new Array(len);
b[0] = 254;
for (var i = 1; i < len; i++) b[i] = 0;
return b;
return [254, ...new Array(len).fill(0)];
}

//Provides: caml_floatarray_create const (const)
//Requires: caml_array_bound_error
function caml_floatarray_create(len) {
if (len < 0) caml_array_bound_error();
var len = (len + 1) | 0;
var b = new Array(len);
b[0] = 254;
for (var i = 1; i < len; i++) b[i] = 0;
return b;
return [254, ...new Array(len).fill(0)];
}
19 changes: 10 additions & 9 deletions runtime/backtrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,27 @@

//Provides: caml_record_backtrace_env_flag
//Requires: jsoo_sys_getenv
var caml_record_backtrace_env_flag = FLAG("with-js-error");
let caml_record_backtrace_env_flag = FLAG("with-js-error");

(function () {
var r = jsoo_sys_getenv("OCAMLRUNPARAM");
(() => {
const r = jsoo_sys_getenv("OCAMLRUNPARAM");
if (r !== undefined) {
var l = r.split(",");
for (var i = 0; i < l.length; i++) {
if (l[i] == "b") {
const l = r.split(",");
for (let i = 0; i < l.length; i++) {
if (l[i] === "b") {
caml_record_backtrace_env_flag = 1;
break;
} else if (l[i].startsWith("b=")) {
}
if (l[i].startsWith("b=")) {
caml_record_backtrace_env_flag = +l[i].slice(2);
} else continue;
}
}
}
})();

//Provides: caml_record_backtrace_runtime_flag
//Requires: caml_record_backtrace_env_flag
var caml_record_backtrace_runtime_flag = caml_record_backtrace_env_flag;
let caml_record_backtrace_runtime_flag = caml_record_backtrace_env_flag;

//Provides: caml_ml_debug_info_status const
function caml_ml_debug_info_status() {
Expand Down
Loading