示例#1
0
void Term__type(caStack* stack)
{
    Term* t = as_term_ref(circa_input(stack, 0));
    if (t == NULL)
        return circa_output_error(stack, "NULL reference");
    set_type(circa_output(stack, 0), t->type);
}
示例#2
0
void Term__tweak(caStack* stack)
{
    Term* t = as_term_ref(circa_input(stack, 0));
    if (t == NULL)
        return circa_output_error(stack, "NULL reference");

    int steps = tweak_round(to_float(circa_input(stack, 1)));

    caValue* val = term_value(t);

    if (steps == 0)
        return;

    if (is_float(val)) {
        float step = get_step(t);

        // Do the math like this so that rounding errors are not accumulated
        float new_value = (tweak_round(as_float(val) / step) + steps) * step;
        set_float(val, new_value);

    } else if (is_int(val))
        set_int(val, as_int(val) + steps);
    else
        circa_output_error(stack, "Ref is not an int or number");
}
示例#3
0
void Term__function(caStack* stack)
{
    Term* t = as_term_ref(circa_input(stack, 0));
    if (t == NULL)
        return circa_output_error(stack, "NULL reference");
    set_branch(circa_output(stack, 0), function_contents(as_function(t->function)));
}
示例#4
0
void Term__to_string(VM* vm)
{
    Term* t = as_term_ref(vm->input(0));
    if (t == NULL)
        return vm->throw_str("NULL term");
    circa::to_string(term_value(t), vm->output());
}
示例#5
0
void Term__to_string(caStack* stack)
{
    Term* t = as_term_ref(circa_input(stack, 0));
    if (t == NULL)
        return circa_output_error(stack, "NULL reference");
    set_string(circa_output(stack, 0), circa::to_string(term_value(t)));
}
示例#6
0
void Term__unique_name(VM* vm)
{
    Term* t = as_term_ref(vm->input(0));
    if (t == NULL)
        return vm->throw_str("NULL term");
    set_value(vm->output(), unique_name(t));
}
示例#7
0
void Term__function(VM* vm)
{
    Term* t = as_term_ref(vm->input(0));
    if (t == NULL)
        return vm->throw_str("NULL term");
    set_block(vm->output(), term_function(t));
}
示例#8
0
void Term__parent(VM* vm)
{
    Term* t = as_term_ref(vm->input(0));
    if (t == NULL)
        return vm->throw_str("NULL term");
    set_block(vm->output(), t->owningBlock);
}
示例#9
0
void Term__type(VM* vm)
{
    Term* t = as_term_ref(vm->input(0));
    if (t == NULL)
        return vm->throw_str("NULL term");
    set_type(vm->output(), t->type);
}
示例#10
0
void Term__is_value(VM* vm)
{
    Term* t = as_term_ref(vm->input(0));

    bool consideredValue = is_value(t) || t->function == FUNCS.require;
    set_bool(vm->output(), consideredValue);
}
示例#11
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);
        }
    }
}
示例#12
0
void Term__properties(VM* vm)
{
    Term* t = as_term_ref(vm->input(0));
    if (t == NULL)
        return vm->throw_str("NULL reference");
    copy(&t->properties, vm->output());
}
示例#13
0
void Term__to_source_string(caStack* stack)
{
    Term* t = as_term_ref(circa_input(stack, 0));
    if (t == NULL)
        return circa_output_error(stack, "NULL reference");
    set_string(circa_output(stack, 0), get_term_source_text(t));
}
示例#14
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);
        }
    }
}
示例#15
0
文件: kernel.cpp 项目: whunmr/circa
int term_hashFunc(caValue* val)
{
    Term* term = as_term_ref(val);
    if (term == NULL)
        return 0;
    return term->id;
}
示例#16
0
void Term__properties(caStack* stack)
{
    Term* t = as_term_ref(circa_input(stack, 0));
    if (t == NULL)
        return circa_output_error(stack, "NULL reference");
    circa::copy(&t->properties, circa_output(stack, 0));
}
示例#17
0
void Term__num_inputs(VM* vm)
{
    Term* t = as_term_ref(vm->input(0));
    if (t == NULL)
        return vm->throw_str("NULL term");
    set_int(vm->output(), t->numInputs());
}
示例#18
0
void Term__contents(VM* vm)
{
    Term* t = as_term_ref(vm->input(0));
    if (t == NULL)
        return vm->throw_str("NULL term");
    set_block(vm->output(), t->nestedContents);
}
示例#19
0
void Term__asfloat(VM* vm)
{
    Term* t = as_term_ref(vm->input(0));
    if (t == NULL)
        return vm->throw_str("NULL term");
    
    set_float(vm->output(), to_float(term_value(t)));
}
示例#20
0
void Term__set_value(VM* vm)
{
    Term* target = as_term_ref(vm->input(0));
    if (target == NULL)
        return vm->throw_str("NULL term");

    copy(vm->input(1), term_value(target));
}
示例#21
0
void Term__global_id(caStack* stack)
{
    Term* t = as_term_ref(circa_input(stack, 0));
    if (t == NULL)
        return circa_output_error(stack, "NULL reference");

    set_int(circa_output(stack, 0), t->id);
}
示例#22
0
void Term__location_string(caStack* stack)
{
    Term* t = as_term_ref(circa_input(stack, 0));
    if (t == NULL)
        return circa_output_error(stack, "NULL reference");

    set_string(circa_output(stack, 0), get_short_location(t).c_str());
}
示例#23
0
void Term__global_id(VM* vm)
{
    Term* t = as_term_ref(vm->input(0));
    if (t == NULL)
        return vm->throw_str("NULL reference");

    set_int(vm->output(), t->id);
}
示例#24
0
void Term__location_string(VM* vm)
{
    Term* t = as_term_ref(vm->input(0));
    if (t == NULL)
        return vm->throw_str("NULL reference");

    get_short_location(t, vm->output());
}
示例#25
0
void Term__asint(VM* vm)
{
    Term* t = as_term_ref(vm->input(0));
    if (t == NULL)
        return vm->throw_str("NULL term");
    if (!is_int(term_value(t)))
        return vm->throw_str("Not an int");
    set_int(vm->output(), as_int(term_value(t)));
}
示例#26
0
void Term__parent(caStack* stack)
{
    Term* t = as_term_ref(circa_input(stack, 0));
    if (t == NULL) {
        circa_output_error(stack, "NULL reference");
        return;
    }
    set_branch(circa_output(stack, 0), t->owningBranch);
}
示例#27
0
void Term__contents(caStack* stack)
{
    Term* t = as_term_ref(circa_input(stack, 0));
    if (t == NULL) {
        circa_output_error(stack, "NULL reference");
        return;
    }
    set_branch(circa_output(stack, 0), t->nestedContents);
}
示例#28
0
void Term__has_property(VM* vm)
{
    Term* t = as_term_ref(vm->input(0));
    if (t == NULL)
        return vm->throw_str("NULL reference");
    Symbol key = as_symbol(vm->input(1));
    Value* value = term_get_property(t, key);
    set_bool(vm->output(), value != NULL);
}
示例#29
0
void Term__num_inputs(caStack* stack)
{
    Term* t = as_term_ref(circa_input(stack, 0));
    if (t == NULL) {
        circa_output_error(stack, "NULL reference");
        return;
    }
    set_int(circa_output(stack, 0), t->numInputs());
}
示例#30
0
void Term__name(VM* vm)
{
    Term* t = as_term_ref(vm->input(0));
    if (t == NULL)
        return vm->throw_str("NULL term");
    if (has_empty_name(t))
        set_string(vm->output(), "");
    else
        copy(term_name(t), vm->output());
}