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 a93b73b commit 0d3659f
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 15 deletions.
4 changes: 3 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"rules": {
"recommended": true,
"style": {
"noParameterAssign": "off"
"noParameterAssign": "off",
"useNamingConvention": "off",
"useShorthandAssign": "error"
},
"suspicious": {
"noAssignInExpressions": "off",
Expand Down
10 changes: 5 additions & 5 deletions runtime/bigarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function caml_ba_get_size(dims) {
for (let i = 0; i < n_dims; i++) {
if (dims[i] < 0)
caml_invalid_argument("Bigarray.create: negative dimension");
size = size * dims[i];
size *= dims[i];
}
return size;
}
Expand Down Expand Up @@ -539,12 +539,12 @@ function caml_ba_sub(ba, ofs, len) {
let changed_dim;
let mul = 1;
if (ba.layout === 0) {
for (let i = 1; i < ba.dims.length; i++) mul = mul * ba.dims[i];
for (let i = 1; i < ba.dims.length; i++) mul *= ba.dims[i];
changed_dim = 0;
} else {
for (let i = 0; i < ba.dims.length - 1; i++) mul = mul * ba.dims[i];
for (let i = 0; i < ba.dims.length - 1; i++) mul *= ba.dims[i];
changed_dim = ba.dims.length - 1;
ofs = ofs - 1;
ofs -= 1;
}
if (ofs < 0 || len < 0 || ofs + len > ba.dims[changed_dim]) {
caml_invalid_argument("Bigarray.sub: bad sub-array");
Expand Down Expand Up @@ -606,7 +606,7 @@ function caml_ba_reshape(ba, vind) {
new_dim[i] = vind[i];
if (new_dim[i] < 0)
caml_invalid_argument("Bigarray.reshape: negative dimension");
num_elts = num_elts * new_dim[i];
num_elts *= new_dim[i];
}

const size = caml_ba_get_size(ba.dims);
Expand Down
4 changes: 2 additions & 2 deletions runtime/blake2.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ const blake2b = (() => {
}

// low 64 bits of offset
v[24] = v[24] ^ ctx.t;
v[25] = v[25] ^ (ctx.t / 0x100000000);
v[24] ^= ctx.t;
v[25] ^= ctx.t / 0x100000000;
// high 64 bits not supported, offset may not be higher than 2**53-1

// last block flag set ?
Expand Down
8 changes: 4 additions & 4 deletions runtime/int64.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ MlInt64.prototype.xor = function (x) {
return new MlInt64(this.lo ^ x.lo, this.mi ^ x.mi, this.hi ^ x.hi);
};
MlInt64.prototype.shift_left = function (s) {
s = s & 63;
s &= 63;
if (s === 0) return this;
if (s < 24) {
return new MlInt64(
Expand All @@ -114,7 +114,7 @@ MlInt64.prototype.shift_left = function (s) {
return new MlInt64(0, 0, this.lo << (s - 48));
};
MlInt64.prototype.shift_right_unsigned = function (s) {
s = s & 63;
s &= 63;
if (s === 0) return this;
if (s < 24)
return new MlInt64(
Expand All @@ -131,7 +131,7 @@ MlInt64.prototype.shift_right_unsigned = function (s) {
return new MlInt64(this.hi >> (s - 48), 0, 0);
};
MlInt64.prototype.shift_right = function (s) {
s = s & 63;
s &= 63;
if (s === 0) return this;
const h = (this.hi << 16) >> 16;
if (s < 24)
Expand All @@ -157,7 +157,7 @@ MlInt64.prototype.lsl1 = function () {
MlInt64.prototype.lsr1 = function () {
this.lo = ((this.lo >>> 1) | (this.mi << 23)) & 0xffffff;
this.mi = ((this.mi >>> 1) | (this.hi << 23)) & 0xffffff;
this.hi = this.hi >>> 1;
this.hi >>>= 1;
};
MlInt64.prototype.udivmod = function (x) {
let offset = 0;
Expand Down
2 changes: 1 addition & 1 deletion runtime/ints.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function caml_int_of_string(s) {
// For base different from 10, we expect an unsigned representation,
// hence any value of 'res' (less than 'threshold') is acceptable.
// But we have to convert the result back to a signed integer.
res = sign * res;
res *= sign;
if (signedness && (res | 0) !== res)
/* Signed representation expected, allow -2^(nbits-1) to 2^(nbits-1) - 1 */
caml_failwith("int_of_string");
Expand Down
2 changes: 1 addition & 1 deletion runtime/nat.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ function div_nat(nat1, ofs1, len1, nat2, ofs2, len2) {
nat1.data[ofs1 + i] !== 0 ||
compare_nat(nat1, ofs1 + i - len2, len2, nat2, ofs2, len2) >= 0
) {
quo = quo + 1;
quo += 1;
sub_nat(nat1, ofs1 + i - len2, len2 + 1, nat2, ofs2, len2, 1);
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/str.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ const re_match = (() => {
case opcodes.ACCEPT:
return accept();
case opcodes.GOTO:
pc = pc + sarg;
pc += sarg;
break;
case opcodes.PUSHBACK:
push({ pos: { pc: pc + sarg, txt: pos } });
Expand Down

0 comments on commit 0d3659f

Please sign in to comment.