Esempio n. 1
0
  protected short op_call() {
    int nlocals;
    int i;
    short thislocal;

    if (operands[0] == 0) {
      /* calls to zero return false */
      /*
       * Can't just return false because call is not treated as a store in
       * execute_instruction
       */
      zm.set_variable(storevar, ZFALSE);
    } else {
      zm.zstack.push(new ZFrameBound(isstore()));
      zm.zstack.push(new Integer(storevar));
      zm.zstack.push(new Integer(zm.pc));
      zm.zstack.push(zm.locals);
      // System.err.print("From ");
      // System.err.print(Integer.toString(zm.pc, 16));
      zm.pc = zm.routine_address(operands[0]);
      // System.err.print(" calling routine at ");
      // System.err.println(Integer.toString(zm.pc, 16));
      nlocals = zm.get_code_byte();
      zm.locals = new short[nlocals];
      for (i = 0; i < nlocals; i++) {
        thislocal = (short) (((zm.get_code_byte() << 8) & 0xFF00) | (zm.get_code_byte() & 0xFF));
        if (i < (count - 1)) {
          zm.locals[i] = operands[i + 1];
        } else {
          zm.locals[i] = thislocal;
        }
      }
    }
    return ZFALSE;
  }
Esempio n. 2
0
  protected void z_ret() {
    Object tos;

    do tos = zm.zstack.pop();
    while (!(tos instanceof short[]));
    zm.locals = (short[]) tos;
    // System.err.print("From ");
    // System.err.print(Integer.toString(zm.pc, 16));
    zm.pc = ((Integer) zm.zstack.pop()).intValue();
    // System.err.print(" returning to ");
    // System.err.println(Integer.toString(zm.pc, 16));
    storevar = (short) (((Integer) zm.zstack.pop()).intValue());
    zm.zstack.pop(); /* stack frame boundary */
  }
Esempio n. 3
0
 protected short op_print() {
   int nchars;
   nchars = zm.print_string(zm.pc);
   zm.pc += nchars;
   return ZFALSE;
 }
Esempio n. 4
0
 protected short op_jump() {
   zm.pc += operands[0] - 2;
   return ZFALSE;
 }
Esempio n. 5
0
  public void execute() {
    short result;

    // System.err.println("Executing instruction " + opnum);
    switch (opnum) {
      case OP_JE:
        result = op_je();
        break;
      case OP_JL:
        result = op_jl();
        break;
      case OP_JG:
        result = op_jg();
        break;
      case OP_DEC_CHK:
        result = op_dec_chk();
        break;
      case OP_INC_CHK:
        result = op_inc_chk();
        break;
      case OP_JIN:
        result = op_jin();
        break;
      case OP_TEST:
        result = op_test();
        break;
      case OP_OR:
        result = op_or();
        break;
      case OP_AND:
        result = op_and();
        break;
      case OP_TEST_ATTR:
        result = op_test_attr();
        break;
      case OP_SET_ATTR:
        result = op_set_attr();
        break;
      case OP_CLEAR_ATTR:
        result = op_clear_attr();
        break;
      case OP_STORE:
        result = op_store();
        break;
      case OP_INSERT_OBJ:
        result = op_insert_obj();
        break;
      case OP_LOADW:
        result = op_loadw();
        break;
      case OP_LOADB:
        result = op_loadb();
        break;
      case OP_GET_PROP:
        result = op_get_prop();
        break;
      case OP_GET_PROP_ADDR:
        result = op_get_prop_addr();
        break;
      case OP_GET_NEXT_PROP:
        result = op_get_next_prop();
        break;
      case OP_ADD:
        result = op_add();
        break;
      case OP_SUB:
        result = op_sub();
        break;
      case OP_MUL:
        result = op_mul();
        break;
      case OP_DIV:
        result = op_div();
        break;
      case OP_MOD:
        result = op_mod();
        break;
      case OP_JZ:
        result = op_jz();
        break;
      case OP_GET_SIBLING:
        result = op_get_sibling();
        break;
      case OP_GET_CHILD:
        result = op_get_child();
        break;
      case OP_GET_PARENT:
        result = op_get_parent();
        break;
      case OP_GET_PROP_LEN:
        result = op_get_prop_len();
        break;
      case OP_INC:
        result = op_inc();
        break;
      case OP_DEC:
        result = op_dec();
        break;
      case OP_PRINT_ADDR:
        result = op_print_addr();
        break;
      case OP_CALL_1S:
        result = op_call_1s();
        break;
      case OP_REMOVE_OBJ:
        result = op_remove_obj();
        break;
      case OP_PRINT_OBJ:
        result = op_print_obj();
        break;
      case OP_RET:
        result = op_ret();
        break;
      case OP_JUMP:
        result = op_jump();
        break;
      case OP_PRINT_PADDR:
        result = op_print_paddr();
        break;
      case OP_LOAD:
        result = op_load();
        break;
      case OP_NOT:
        result = op_not();
        break;
      case OP_RTRUE:
        result = op_rtrue();
        break;
      case OP_RFALSE:
        result = op_rfalse();
        break;
      case OP_PRINT:
        result = op_print();
        break;
      case OP_PRINT_RET:
        result = op_print_ret();
        break;
      case OP_NOP:
        result = op_nop();
        break;
      case OP_SAVE:
        result = op_save();
        break;
      case OP_RESTORE:
        result = op_restore();
        break;
      case OP_RESTART:
        result = op_restart();
        break;
      case OP_RET_POPPED:
        result = op_ret_popped();
        break;
      case OP_POP:
        result = op_pop();
        break;
      case OP_QUIT:
        result = op_quit();
        break;
      case OP_NEW_LINE:
        result = op_new_line();
        break;
      case OP_SHOW_STATUS:
        result = op_show_status();
        break;
      case OP_VERIFY:
        result = op_verify();
        break;
      case OP_EXTENDED:
        result = op_extended();
        break;
      case OP_PIRACY:
        result = op_piracy();
        break;
      case OP_CALL:
        result = op_call();
        break;
      case OP_STOREW:
        result = op_storew();
        break;
      case OP_STOREB:
        result = op_storeb();
        break;
      case OP_PUT_PROP:
        result = op_put_prop();
        break;
      case OP_SREAD:
        result = op_sread();
        break;
      case OP_PRINT_CHAR:
        result = op_print_char();
        break;
      case OP_PRINT_NUM:
        result = op_print_num();
        break;
      case OP_RANDOM:
        result = op_random();
        break;
      case OP_PUSH:
        result = op_push();
        break;
      case OP_PULL:
        result = op_pull();
        break;
      case OP_SPLIT_WINDOW:
        result = op_split_window();
        break;
      case OP_SET_WINDOW:
        result = op_set_window();
        break;
      case OP_OUTPUT_STREAM:
        result = op_output_stream();
        break;
      case OP_INPUT_STREAM:
        result = op_input_stream();
        break;
      case OP_SOUND_EFFECT:
        result = op_sound_effect();
        break;
      default:
        result = op_illegal();
    }

    if (((opnum != OP_CALL) && isstore()) || isret()) {
      zm.set_variable(storevar, result);
    }

    if (isbranch()) {
      if ((result == 0) != branchtype) {
        /*
         * that is, if result is 0 and branchtype is false, or result is nonzero
         * and branchtype is true
         */
        switch (branchoffset) {
          case 0:
            z_ret();
            zm.set_variable(storevar, ZFALSE);
            break;
          case 1:
            z_ret();
            zm.set_variable(storevar, ZTRUE);
            break;
          default:
            zm.pc += branchoffset - 2;
        }
      }
    }
  }