Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
case "f32": {
const actuali32 = actual.value.reinterpret();
const expectedi32 = Long.fromString(expected.value).toInt();
assert(
actuali32.toNumber() === expectedi32,
`Expected value ${expectedi32}, got ${actuali32.toString()}`
);
break;
}
case "f64": {
const actuali32 = actual.value.reinterpret();
const expectedi32 = Long.fromString(expected.value).toNumber();
assert(
actuali32.toNumber() === expectedi32,
`Expected value ${expectedi32}, got ${actuali32.toString()}`
);
break;
}
case "i64": {
console.warn("eq with i64 is unsupported");
// const actuali64 = actual.value.toString();
// const expectedi64 = Long.fromString(expected.value)
// .toSigned()
// .toString();
function eq(actual: StackLocal, expected: Object) {
// check type
assert(
actual.type === expected.type,
`type mismatch; expected ${expected.type}, given ${actual.type}`
);
// check value
switch (expected.type) {
case "i32": {
const i32Value = Long.fromString(expected.value).toInt();
assert(
actual.value.toString() === i32Value.toString(),
`Expected value ${i32Value}, got ${actual.value.toString()}`
);
break;
}
case "f32": {
const actuali32 = actual.value.reinterpret();
const expectedi32 = Long.fromString(expected.value).toInt();
assert(
actuali32.toNumber() === expectedi32,
`Expected value ${expectedi32}, got ${actuali32.toString()}`
);
static fromArrayBuffer(
buffer: ArrayBuffer,
ptr: number,
extend: number,
signed: boolean
): i64 {
const slice = buffer.slice(ptr, ptr + 8);
const value = new Int32Array(slice);
let longVal = new Long(value[0], value[1]);
// shift left, then shift right by the same number of bits, using
// signed or unsigned shifts
longVal = longVal.shiftLeft(extend);
return new i64(
signed ? longVal.shiftRight(extend) : longVal.shiftRightUnsigned(extend)
);
}
}
* https://webassembly.github.io/spec/core/exec/runtime.html#administrative-instructions
*/
case "unreachable":
// https://webassembly.github.io/spec/core/exec/instructions.html#exec-unreachable
case "trap": {
// signalling abrupt termination
// https://webassembly.github.io/spec/core/exec/runtime.html#syntax-trap
throw createTrap();
}
case "local": {
// $FlowIgnore
const [valtype] = instruction.args;
if (valtype.name === "i64") {
const init = castIntoStackLocalOfType(valtype.name, new Long(0, 0));
frame.locals.push(init);
} else {
// $FlowIgnore
const init = castIntoStackLocalOfType(valtype.name, 0);
frame.locals.push(init);
}
// $FlowIgnore
trace("new local " + valtype.name);
break;
}
/**
* Memory Instructions
*
mul(operand: i32): i32 {
// https://webassembly.github.io/spec/core/exec/numerics.html#op-imul
return new i32(
Long.fromNumber(this._value)
.mul(Long.fromNumber(operand._value))
.mod(Math.pow(2, bits))
.toNumber()
);
}
mul(operand: i32): i32 {
// https://webassembly.github.io/spec/core/exec/numerics.html#op-imul
return new i32(
Long.fromNumber(this._value)
.mul(Long.fromNumber(operand._value))
.mod(Math.pow(2, bits))
.toNumber()
);
}
const compatibleArgs = args.map(x => {
if (x.type === "i64") {
return new Long.fromString(x.value);
}
return x.value;
});
function printLongNumberLiteral(n) {
if (typeof n.raw === "string") {
return n.raw;
}
var _n$value = n.value,
low = _n$value.low,
high = _n$value.high;
var v = new Long(low, high);
return v.toString();
}
function printLongNumberLiteral(n) {
if (typeof n.raw === "string") {
return n.raw;
}
var _n$value = n.value,
low = _n$value.low,
high = _n$value.high;
var v = new Long(low, high);
return v.toString();
}
clz(): i64 {
let lead = 0;
const str = this._value.toUnsigned().toString(2);
for (let i = 0, len = str.length; i < len; i++) {
if (str[i] !== "0") {
break;
}
lead++;
}
return new i64(new Long(lead));
}