示例#1
0
文件: vm.c 项目: smorimura/filagree
// FOR who IN what WHERE where DO how
static bool iterate(struct context *context,
                    enum Opcode op,
                    struct program_state *state,
                    struct byte_array *program)
{
    struct byte_array *who = serial_decode_string(program);
    struct byte_array *where = serial_decode_string(program);
    struct byte_array *how = serial_decode_string(program);

#ifdef DEBUG
    DEBUGPRINT("%s %s\n",
               NUM_TO_STRING(opcodes, op),
               byte_array_to_string(who));
    if (!context->runtime) {
        if (where && where->length) {
            DEBUGPRINT("%s\tWHERE\n", indentation(context));
            display_code(context, where);
        }
        DEBUGPRINT("%s\tDO\n", indentation(context));
        display_code(context, how);
        return false;
    }
#endif

    bool comprehending = (op == VM_COM);
    struct variable *result = comprehending ? variable_new_list(context, NULL) : NULL;

    struct variable *what = variable_pop(context);
    uint32_t len = variable_length(context, what);
    for (int i=0; i<len; i++) {

        struct variable *that = list_get_int(context, what, i);
        set_named_variable(context, state, who, that);

        byte_array_reset(where);
        byte_array_reset(how);
        if (where && where->length)
            run(context, where, NULL, true);
        if (!where || !where->length || test_operand(context)) {

            if (run(context, how, NULL, true)) // true if run hit VM_RET
                return true;

            if (comprehending) {
                struct variable *item = (struct variable*)stack_pop(context->operand_stack);
                array_add(result->list, item);
            }
        }
    }

    if (comprehending)
        stack_push(context->operand_stack, result);
    return false;
}
示例#2
0
ErrorCode MeshTag::get_data(const SequenceManager*,
                            Error* /* error */,
                            const Range& r,
                            void*) const
{
  if (variable_length()) {
    MB_SET_ERR(MB_VARIABLE_DATA_LENGTH, "No length specified for variable-length tag " << get_name() << " value");
  }
  else if (r.empty())
    return MB_SUCCESS;
  else
    return not_root_set(get_name(), r.front());
}
示例#3
0
ErrorCode MeshTag::set_data(SequenceManager*,
                            Error* /* error */,
                            const EntityHandle* entities,
                            size_t num_entities,
                            const void* data)
{
  if (variable_length()) {
    MB_SET_ERR(MB_VARIABLE_DATA_LENGTH, "No length specified for variable-length tag " << get_name() << " value");
  }
  if (!all_root_set(get_name(), entities, num_entities))
    return MB_TAG_NOT_FOUND;

  if (num_entities > 0) {
    mValue.resize(get_size());
    const unsigned char* bytes = reinterpret_cast<const unsigned char*>(data);
    memcpy(&mValue[0], bytes + get_size() * (num_entities - 1), get_size());
  }

  return MB_SUCCESS;
}