42 Companion zmachine.js (21/28)

        case 0x12: { if (!a) return this.store(0); const p = this.findProp(a, b); return this.store(p ? p.addr : 0); }
        case 0x13: {
          if (!a) return this.store(0);
          let addr = this.firstProp(a);
          if (b) {
            const p = this.findProp(a, b);
            if (!p) throw new ZError(`get_next_prop: object ${a} has no property ${b}`);
            addr = p.addr + p.len;
          }
          const next = this.propAt(addr);
          return this.store(next ? next.num : 0);
        }
        case 0x14: return this.store(s16(a) + s16(b));
        case 0x15: return this.store(s16(a) - s16(b));
        case 0x16: return this.store(Math.imul(s16(a), s16(b)));
        case 0x17: if (!s16(b)) throw new ZError('division by zero'); return this.store(Math.trunc(s16(a) / s16(b)));
        case 0x18: if (!s16(b)) throw new ZError('division by zero'); return this.store(s16(a) % s16(b));
        case 0x19: return this.call(a, o.slice(1), this.mem[this.pc++]);
        case 0x1a: return this.call(a, o.slice(1), -1);
        case 0x1b: return; // set_colour
        case 0x1c: { // throw
          while (this.frames.length > b) this.frames.pop();
          return this.ret(a);
        }
      }
    } else if (form === '1op') {
      const [a] = o;
      switch (num) {
        case 0x00: return this.branch(a === 0);
        case 0x01: { const s = a ? this.sibling(a) : 0; this.store(s); return this.branch(s !== 0); }
‹ PreviousReader file (.txt)Next ›