示例#1
0
void Block__owner(VM* vm)
{
    Block* block = as_block(vm->input(0));
    if (block == NULL) {
        set_term_ref(vm->output(), NULL);
        return;
    }

    set_term_ref(vm->output(), block->owningTerm);
}
示例#2
0
void Branch__owner(caStack* stack)
{
    Branch* branch = as_branch(circa_input(stack, 0));
    if (branch == NULL) {
        set_term_ref(circa_output(stack, 0), NULL);
        return;
    }

    set_term_ref(circa_output(stack, 0), branch->owningTerm);
}
示例#3
0
void Term__input(VM* vm)
{
    Term* t = as_term_ref(vm->input(0));
    if (t == NULL)
        return vm->throw_str("NULL term");
    int index = vm->input(1)->as_i();
    if (index >= t->numInputs())
        set_term_ref(vm->output(), NULL);
    else
        set_term_ref(vm->output(), t->input(index));
}
示例#4
0
void Term__input(caStack* stack)
{
    Term* t = as_term_ref(circa_input(stack, 0));
    if (t == NULL) {
        circa_output_error(stack, "NULL reference");
        return;
    }
    int index = circa_int_input(stack, 1);
    if (index >= t->numInputs())
        set_term_ref(circa_output(stack, 0), NULL);
    else
        set_term_ref(circa_output(stack, 0), t->input(index));
}
示例#5
0
void update_all_code_references_in_value(caValue* value, Branch* oldBranch, Branch* newBranch)
{
    for (ValueIterator it(value); it.unfinished(); it.advance()) {
        caValue* val = *it;
        if (is_ref(val)) {
            set_term_ref(val, translate_term_across_branches(as_term_ref(val),
                oldBranch, newBranch));
            
        } else if (is_branch(val)) {

            // If this is just a reference to 'oldBranch' then simply update it to 'newBranch'.
            if (as_branch(val) == oldBranch)
                set_branch(val, newBranch);

            // Noop on null branch.
            if (as_branch(val) == NULL)
                continue;

            // Noop if branch has no owner.
            Term* oldTerm = as_branch(val)->owningTerm;
            if (oldTerm == NULL)
                continue;

            Term* newTerm = translate_term_across_branches(oldTerm, oldBranch, newBranch);
            if (newTerm == NULL) {
                set_branch(val, NULL);
                continue;
            }

            set_branch(val, newTerm->nestedContents);
        }
    }
}
示例#6
0
void migrate_value(Value* value, Migration* migration)
{
    if (is_ref(value)) {
        set_term_ref(value, migrate_term_pointer(as_term_ref(value), migration));
        
    } else if (is_block(value)) {
        set_block(value, migrate_block_pointer(as_block(value), migration));
    } else if (is_list_based(value)) {
        migrate_list_value(value, migration);

    } else if (is_hashtable(value)) {
        Value oldHashtable;
        move(value, &oldHashtable);

        set_hashtable(value);
        Value* hashtable = value;

        for (int i=0; i < hashtable_slot_count(&oldHashtable); i++) {
            Value* oldKey = hashtable_key_by_index(&oldHashtable, i);
            if (oldKey == NULL || is_null(oldKey))
                continue;

            Value* oldValue = hashtable_value_by_index(&oldHashtable, i);

            Value key;
            copy(oldKey, &key);
            migrate_value(&key, migration);
            Value* newValue = hashtable_insert(hashtable, &key);
            copy(oldValue, newValue);
            migrate_value(newValue, migration);
        }
    }
}
示例#7
0
void Block__get_term(VM* vm)
{
    Block* block = as_block(vm->input(0));
    if (block == NULL)
        return vm->throw_str("NULL block");

    int index = vm->input(1)->as_i();
    set_term_ref(vm->output(), block->get(index));
}
示例#8
0
void Branch__get_term(caStack* stack)
{
    Branch* branch = as_branch(circa_input(stack, 0));
    if (branch == NULL)
        return circa_output_error(stack, "NULL branch");

    int index = circa_int_input(stack, 1);
    set_term_ref(circa_output(stack, 0), branch->get(index));
}
示例#9
0
void Branch__find_term(caStack* stack)
{
    Branch* branch = as_branch(circa_input(stack, 0));
    if (branch == NULL)
        return circa_output_error(stack, "NULL branch");

    Term* term = branch->get(circa_string_input(stack, 1));

    set_term_ref(circa_output(stack, 0), term);
}
示例#10
0
void Block__term_named(VM* vm)
{
    Block* block = as_block(vm->input(0));
    if (block == NULL)
        return vm->throw_str("NULL block");

    Value* name = vm->input(1);

    set_term_ref(vm->output(), find_local_name(block, name));
}
示例#11
0
void Block__find_term(VM* vm)
{
    Block* block = as_block(vm->input(0));
    if (block == NULL)
        return vm->throw_str("NULL block");

    Term* term = block->get(vm->input(1)->as_str());

    set_term_ref(vm->output(), term);
}
示例#12
0
void Block__walk_terms(VM* vm)
{
    Block* block = as_block(vm->input(0));
    if (block == NULL)
        return vm->throw_str("NULL block");

    Value* out = vm->output();
    set_list(out, 0);
    for (BlockIterator it(block); it; ++it)
        set_term_ref(list_append(out), *it);
}
示例#13
0
void Block__terms(VM* vm)
{
    Block* block = as_block(vm->input(0));
    if (block == NULL)
        return vm->throw_str("NULL block");

    Value* out = vm->output();
    set_list(out, block->length());

    for (int i=0; i < block->length(); i++)
        set_term_ref(circa_index(out, i), block->get(i));
}
示例#14
0
void Block__outputs(VM* vm)
{
    Block* block = as_block(vm->input(0));
    Value* output = vm->output();
    set_list(output, 0);
    for (int i=0;; i++) {
        Term* term = get_output_placeholder(block, i);
        if (term == NULL)
            break;
        set_term_ref(list_append(output), term);
    }
}
示例#15
0
void Term__inputs(VM* vm)
{
    Term* t = as_term_ref(vm->input(0));
    if (t == NULL)
        return vm->throw_str("NULL term");

    Value* output = vm->output();
    circa_set_list(output, t->numInputs());

    for (int i=0; i < t->numInputs(); i++)
        set_term_ref(circa_index(output, i), t->input(i));
}
示例#16
0
void Term__inputs(caStack* stack)
{
    Term* t = as_term_ref(circa_input(stack, 0));
    if (t == NULL)
        return circa_output_error(stack, "NULL reference");

    caValue* output = circa_output(stack, 0);
    circa_set_list(output, t->numInputs());

    for (int i=0; i < t->numInputs(); i++)
        set_term_ref(circa_index(output, i), t->input(i));
}
示例#17
0
void Branch__terms(caStack* stack)
{
    Branch* branch = as_branch(circa_input(stack, 0));
    if (branch == NULL)
        return circa_output_error(stack, "NULL branch");

    caValue* out = circa_output(stack, 0);
    set_list(out, branch->length());

    for (int i=0; i < branch->length(); i++)
        set_term_ref(circa_index(out, i), branch->get(i));
}
示例#18
0
void Branch__inputs(caStack* stack)
{
    Branch* branch = as_branch(circa_input(stack, 0));
    caValue* output = circa_output(stack, 0);
    set_list(output, 0);
    for (int i=0;; i++) {
        Term* term = get_input_placeholder(branch, i);
        if (term == NULL)
            break;
        set_term_ref(list_append(output), term);
    }
}
示例#19
0
void Term__trace_dependents(VM* vm)
{
    Term* term = as_term_ref(vm->input(0));
    Block* untilBlock = as_block(vm->input(1));

    Value* out = vm->output();
    set_list(out, 0);
    std::set<Term*> included;

    UpwardIterator upwardIterator(term);
    upwardIterator.stopAt(untilBlock);

    // Look at starting term, because UpwardIterator doesn't yield starting term.
    // TODO: Should fix UpwardIterator
    for (int i=0; i < term->numInputs(); i++) {
        Term* input = term->input(i);
        if (input != NULL) {
            set_term_ref(list_append(out), input);
            included.insert(input);
        }
    }

    for (; upwardIterator.unfinished(); upwardIterator.advance()) {
        Term* current = upwardIterator.current();
        if (current == term || included.find(current) != included.end()) {

            for (int i=0; i < current->numInputs(); i++) {
                Term* input = current->input(i);
                if (input != NULL) {
                    set_term_ref(list_append(out), input);
                    included.insert(input);
                }
            }
        }
    }

    // Order results in the same order as the code.
    list_reverse(out);
}
示例#20
0
void Block__list_configs(VM* vm)
{
    Block* block = as_block(vm->input(0));
    if (block == NULL)
        return vm->throw_str("NULL block");

    Value* output = vm->output();

    for (int i=0; i < block->length(); i++) {
        Term* term = block->get(i);
        if (is_considered_config(term))
            set_term_ref(circa_append(output), term);
    }
}
示例#21
0
void Branch__list_configs(caStack* stack)
{
    Branch* branch = as_branch(circa_input(stack, 0));
    if (branch == NULL)
        return circa_output_error(stack, "NULL branch");

    caValue* output = circa_output(stack, 0);

    for (int i=0; i < branch->length(); i++) {
        Term* term = branch->get(i);
        if (is_considered_config(term))
            set_term_ref(circa_append(output), term);
    }
}
示例#22
0
void Block__output_placeholder(VM* vm)
{
    Block* block = as_block(vm->input(0));
    Term* placeholder = get_output_placeholder(block, vm->input(1)->as_i());
    set_term_ref(vm->output(), placeholder);
}
示例#23
0
void term_ref(caStack* stack)
{
    caTerm* term = circa_caller_input_term(stack, 0);
    set_term_ref(circa_output(stack, 0), (Term*) term);
}
示例#24
0
void Block__input(VM* vm)
{
    Block* block = as_block(vm->input(0));
    set_term_ref(vm->output(),
        get_input_placeholder(block, vm->input(1)->as_i()));
}
示例#25
0
文件: kernel.cpp 项目: whunmr/circa
void Type__declaringTerm(caStack* stack)
{
    Type* type = as_type(circa_input(stack, 0));
    set_term_ref(circa_output(stack, 0), type->declaringTerm);
}
示例#26
0
void Branch__input(caStack* stack)
{
    Branch* branch = as_branch(circa_input(stack, 0));
    set_term_ref(circa_output(stack, 0),
        get_input_placeholder(branch, circa_int_input(stack, 1)));
}