UNPKG

ember-source

Version:

A JavaScript framework for creating ambitious web applications

33 lines (30 loc) 988 B
import { T as TYPE_SIZE, M as MAX_SIZE, A as ARG_SHIFT } from './flags-BsZlvEeR.js'; import { isDevelopingApp } from '@embroider/macros'; class InstructionEncoderImpl { constructor(buffer) { this.buffer = buffer; } size = 0; encode(type, machine, ...args) { if (type > TYPE_SIZE) { throw new Error(`Opcode type over 8-bits. Got ${type}.`); } let first = type | machine | arguments.length - 2 << ARG_SHIFT; this.buffer.push(first); for (const op of args) { if (isDevelopingApp() && typeof op === 'number' && op > MAX_SIZE) { throw new Error(`Operand over 32-bits. Got ${op}.`); } this.buffer.push(op); } this.size = this.buffer.length; } patch(position, target) { if (this.buffer[position + 1] === -1) { this.buffer[position + 1] = target; } else { throw new Error('Trying to patch operand in populated slot instead of a reserved slot.'); } } } export { InstructionEncoderImpl as I };