예제 #1
0
static nezvm_string_ptr_t Loader_ReadString(ByteCodeLoader *loader) {
  uint32_t len = Loader_Read16(loader);
  nezvm_string_ptr_t str = (nezvm_string_ptr_t)__malloc(sizeof(*str) - 1 + len);
  str->len = len;
  for (uint32_t i = 0; i < len; i++) {
    str->text[i] = Loader_Read32(loader);
  }
  return str;
}
예제 #2
0
static struct nezvm_string* Loader_ReadString(ByteCodeLoader *loader) {
  uint32_t len = Loader_Read16(loader);
  struct nezvm_string* str = (struct nezvm_string*)malloc(sizeof(*str) - 1 + len);
  str->len = len;
  for (uint32_t i = 0; i < len; i++) {
    str->text[i] = loader->input[loader->info->pos++];
  }
  return str;
}
예제 #3
0
void nez_EmitInstruction(NezVMInstruction* ir, ByteCodeLoader *loader, ParsingContext context) {
  switch(ir->op) {
    case NEZVM_OP_JUMP:
    case NEZVM_OP_IFFAIL: {
      ir->arg = Loader_Read16(loader);
      break;
    }
    case NEZVM_OP_CALL: {
      ir->arg = loader->input[loader->info->pos++];
      context->call_table[ir->arg] = Loader_Read32(loader);
      // fprintf(stderr, "%d: %d\n", ir->arg, context->call_table[ir->arg]);
      break;
    }
    case NEZVM_OP_CHAR: {
      ir->arg = loader->input[loader->info->pos++];
      break;
    }
  }
}
예제 #4
0
void nez_EmitInstruction(NezVMInstruction* ir, ByteCodeLoader *loader, ParsingContext context) {
  switch(ir->op) {
    case NEZVM_OP_JUMP:
    case NEZVM_OP_IFFAIL: {
      ir->arg = Loader_Read16(loader);
      break;
    }
    case NEZVM_OP_CALL: {
      ir->arg = Loader_Read16(loader);
      context->call_table[ir->arg] = Loader_Read32(loader);
      break;
    }
    case NEZVM_OP_CHAR: {
      ir->arg = loader->input[loader->info->pos++];
      break;
    }
    case NEZVM_OP_NOTCHAR: {
      ir->arg = Loader_Read16(loader);
      context->str_table[ir->arg].c = loader->input[loader->info->pos++];
      context->str_table[ir->arg].jump = Loader_Read32(loader);
      context->str_table[ir->arg].type = 0;
      break;
    }
    case NEZVM_OP_CHARMAP: {
      ir->arg = Loader_Read16(loader);
      int len = Loader_Read16(loader);
      context->set_table[ir->arg].set = (bitset_t *)malloc(sizeof(bitset_t));
      bitset_init(context->set_table[ir->arg].set);
      for (int i = 0; i < len; i++) {
        unsigned char c = loader->input[loader->info->pos++];
        bitset_set(context->set_table[ir->arg].set, c);
      }
      context->set_table[ir->arg].jump = Loader_Read32(loader);
      break;
    }
    case NEZVM_OP_OPTIONALCHARMAP:
    case NEZVM_OP_ZEROMORECHARMAP: {
      ir->arg = Loader_Read16(loader);
      assert(ir->arg >= 0 && ir->arg < context->set_table_size);
      int len = Loader_Read16(loader);
      context->set_table[ir->arg].set = (bitset_t *)malloc(sizeof(bitset_t));
      bitset_init(context->set_table[ir->arg].set);
      for (int i = 0; i < len; i++) {
        char c = loader->input[loader->info->pos++];
        bitset_set(context->set_table[ir->arg].set, (unsigned int)c);
      }
      fprintf(stderr, "<%d> %d\n", ir->arg, context->set_table[ir->arg].jump);
      break;
    }
    case NEZVM_OP_STRING:
    case NEZVM_OP_NOTSTRING:
     {
      ir->arg = Loader_Read16(loader);
      context->str_table[ir->arg].str = Loader_ReadString(loader);
      context->str_table[ir->arg].jump = Loader_Read32(loader);
      context->str_table[ir->arg].type = 1;
      fprintf(stderr, "<%d> %s %d\n", ir->arg, context->str_table[ir->arg].str->text, context->str_table[ir->arg].jump);
      break;
    }
    // case NEZVM_OP_OPTIONALSTRING:
    //  {
    //   ir->arg = loader->input[loader->info->pos++];
    //   context->str_table[ir->arg].str = Loader_ReadString(loader);
    //   context->str_table[ir->arg].type = 1;
    //  }
    //  break;
  }
}