Пример #1
0
void dynamic_method_call(caStack* stack)
{
    INCREMENT_STAT(DynamicMethodCall);

    caValue* args = circa_input(stack, 0);
    caValue* object = circa_index(args, 0);

    // Lookup method
    Term* term = (Term*) circa_caller_term(stack);
    std::string functionName = term->stringProp("syntax:functionName", "");

    // Find and dispatch method
    Term* method = find_method((Block*) circa_caller_block(stack),
        (Type*) circa_type_of(object), functionName.c_str());

    // copy(object, circa_output(stack, 1));

    if (method != NULL) {
        // Grab inputs before pop
        Value inputs;
        swap(args, &inputs);

        pop_frame(stack);
        push_frame_with_inputs(stack, function_contents(method), &inputs);
        return;
    }

    // Method not found. Raise error.
    std::string msg;
    msg += "Method ";
    msg += functionName;
    msg += " not found on type ";
    msg += as_cstring(&circa_type_of(object)->name);
    circa_output_error(stack, msg.c_str());
}
Пример #2
0
void evaluate_selector_reflect(caStack* stack)
{
    Term* accessor = ((Term*) circa_caller_term(stack))->input(0);

    Term* head = find_accessor_head_term(accessor);

    // FIXME
}
Пример #3
0
    void hosted_get_index(caStack* stack)
    {
        caValue* list = circa_input(stack, 0);
        int index = circa_int_input(stack, 1);

        if (index < 0) {
            char indexStr[40];
            sprintf(indexStr, "Negative index: %d", index);
            return circa_output_error(stack, indexStr);
        } else if (index >= list_length(list)) {
            char indexStr[40];
            sprintf(indexStr, "Index out of range: %d", index);
            return circa_output_error(stack, indexStr);
        }

        caValue* result = get_index(list, index);

        copy(result, circa_output(stack, 0));
        cast(circa_output(stack, 0), declared_type((Term*) circa_caller_term(stack)));
    }
Пример #4
0
// Pack a state value. Each input will correspond with a slot in the branch's state type.
void pack_state(caStack* stack)
{
    Term* caller = (Term*) circa_caller_term(stack);
    Branch* branch = caller->owningBranch;

    if (branch->stateType == NULL)
        return;

    caValue* args = circa_input(stack, 0);
    caValue* output = circa_output(stack, 0);
    create(branch->stateType, output);

    for (int i=0; i < circa_count(args); i++) {
        caValue* input = circa_index(args, i);
        caValue* dest = list_get(output, i);
        if (input == NULL)
            set_null(dest);
        else
            copy(input, dest);
    }
}
Пример #5
0
 void evaluate(caStack* stack)
 {
     Term* caller = (Term*) circa_caller_term(stack);
     push_frame(stack, nested_contents(caller));
 }
Пример #6
0
void static_type_func(caStack* stack)
{
    Term* caller = (Term*) circa_caller_term(stack);
    Term* input = caller->input(0);
    set_type(circa_output(stack, 0), input->type);
}
Пример #7
0
void dump_current_block(caStack* stack)
{
    Term* caller = (Term*) circa_caller_term(stack);
    dump(caller->owningBlock);
}