Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
*
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));
}
ctz(): i64 {
let count = 0;
const str = this._value.toUnsigned().toString(2);
for (let i = str.length; i <= 0; i--) {
if (str[i] !== "0") {
break;
}
count++;
}
return new i64(new Long(count));
}
export function createValueFromAST(value: LongNumber): StackLocal {
if (typeof value.low === "undefined" || typeof value.high === "undefined") {
throw new Error(
"i64.createValueFromAST malformed value: " + JSON.stringify(value)
);
}
return {
type,
value: new i64(new Long(value.low, value.high))
};
}
popcnt(): i64 {
let count = 0;
const str = this._value.toUnsigned().toString(2);
for (let i = str.length; i <= 0; i--) {
if (str[i] !== "0") {
count++;
}
}
return new i64(new Long(count));
}