Skip to content

Commit

Permalink
runtime: cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Sora Morimoto <[email protected]>
  • Loading branch information
smorimoto committed Sep 19, 2024
1 parent dda4aa2 commit d56aafc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 43 deletions.
37 changes: 6 additions & 31 deletions runtime/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,12 @@

//Provides: caml_array_sub mutable
function caml_array_sub(a, i, len) {
const a2 = new Array(len + 1);
a2[0] = 0;
for (let 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) {
const l1 = a1.length;
const l2 = a2.length;
const l = l1 + l2 - 1;
const a = new Array(l);
a[0] = 0;
let i = 1;
let 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
Expand Down Expand Up @@ -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();
const len_ = (len + 1) | 0;
const b = new Array(len_);
b[0] = 0;
for (let 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();
const len_ = (len + 1) | 0;
const b = new Array(len);
b[0] = 254;
for (let 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();
const len_ = (len + 1) | 0;
const b = new Array(len);
b[0] = 254;
for (let i = 1; i < len_; i++) b[i] = 0;
return b;
return [254, ...new Array(len).fill(0)];
}
14 changes: 7 additions & 7 deletions runtime/backtrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
let caml_record_backtrace_env_flag = FLAG("with-js-error");

(() => {
const r = jsoo_sys_getenv("OCAMLRUNPARAM");
if (r !== undefined) {
const l = r.split(",");
for (let i = 0; i < l.length; i++) {
if (l[i] === "b") {
const run_param = jsoo_sys_getenv("OCAMLRUNPARAM");
if (run_param !== undefined) {
const params = run_param.split(",");
for (const param of params) {
if (param === "b") {
caml_record_backtrace_env_flag = 1;
break;
}
if (l[i].startsWith("b=")) {
caml_record_backtrace_env_flag = +l[i].slice(2);
if (param.startsWith("b=")) {
caml_record_backtrace_env_flag = +param.slice(2);
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions runtime/bigarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ function caml_ba_init() {
//Provides: caml_ba_get_size
//Requires: caml_invalid_argument
function caml_ba_get_size(dims) {
const n_dims = dims.length;
let size = 1;
for (let i = 0; i < n_dims; i++) {
if (dims[i] < 0)
caml_invalid_argument("Bigarray.create: negative dimension");
size = size * dims[i];
for (const dim of dims) {
if (dim < 0) caml_invalid_argument("Bigarray.create: negative dimension");
size *= dim;
}
return size;
}
Expand Down

0 comments on commit d56aafc

Please sign in to comment.