Пример #1
0
// For the given field name
static Term* find_output_term_for_state_field(Branch* branch, const char* fieldName, int position)
{
    Term* result = find_from_unique_name(branch, fieldName);

    // For declared state, the result is the last term with the given name
    if (result->function == FUNCS.declared_state) {
        return find_local_name(branch, result->name.c_str(), position);
    }

    ca_assert(result != NULL);

    // This term might be the actual state result, or the state result might be
    // found in an extra output. Look around and see if this term has a stateful
    // extra output.
    for (int outputIndex=0;; outputIndex++) {
        Term* extraOutput = get_extra_output(result, outputIndex);
        if (extraOutput == NULL)
            break;

        if (is_state_output(extraOutput))
            return extraOutput;
    }

    return result;
}
Пример #2
0
Term* find_from_relative_name_list(Value* name, Block* relativeTo)
{
    if (is_null(name))
        return NULL;

    Term* term = NULL;
    for (int index=0; index < list_length(name); index++) {
        if (relativeTo == NULL)
            return NULL;

        term = find_from_unique_name(relativeTo, list_get(name, index));

        if (term == NULL)
            return NULL;

        relativeTo = term->nestedContents;

        // relativeTo may now be NULL. But if we reached the end of this match, that's ok.
    }
    return term;
}
Пример #3
0
void migrate_state_list(Value* list, Block* oldBlock, Block* newBlock, Migration* migration)
{
    if (is_null(list))
        return;
    if (newBlock == NULL) {
        set_null(list);
        return;
    }

    Value oldList;
    move(list, &oldList);
    touch(&oldList);
    set_list(list, newBlock->length());

    // Copy state values with matching names.
    for (int i=0; i < list_length(&oldList); i++) {
        Value* oldValue = list_get(&oldList, i);
        if (is_null(oldValue))
            continue;

        Term* oldTerm = oldBlock->get(i);
        Term* newTerm = find_from_unique_name(newBlock, unique_name(oldTerm));

#if 0
        printf("looking at unique name = %s for term %d, newTerm = %p\n",
            as_cstring(unique_name(oldTerm)), oldTerm->id, newTerm);
#endif

        if (newTerm != NULL) {
            Value* newSlot = list_get(list, newTerm->index);
            move(oldValue, newSlot);

#if 0
            printf("migrating state value, term name = %s\n", as_cstring(unique_name(oldTerm)));
#endif
        }
    }

    migrate_value(list, migration);
}