コード例 #1
0
ファイル: stateful_code.cpp プロジェクト: mokerjoke/circa
// 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
ファイル: loops.cpp プロジェクト: andyfischer/circa
void insert_looped_placeholders(Block* contents)
{
    Value names;
    list_names_that_must_be_looped(contents, &names);

    for (ListIterator it(&names); it; ++it) {
        Term* inputPlaceholder = append_input_placeholder(contents);
        Value* name = it.value();
        rename(inputPlaceholder, name);
        Value owningTermVal;
        owningTermVal.set_term(contents->owningTerm);
        Term* outsideTerm = find_name_at(&owningTermVal, name);
        Term* innerResult = find_local_name(contents, name);
        Term* outputPlaceholder = append_output_placeholder(contents, innerResult);
        rename(outputPlaceholder, name);

        set_inputs(inputPlaceholder, TermList(outsideTerm, outputPlaceholder));

        for (BlockInputIterator it(contents); it; ++it) {
            Term* term = it.currentTerm();
            if (it.currentInput() == outsideTerm && term != inputPlaceholder)
                set_input(term, it.currentInputIndex(), inputPlaceholder);
        }
    }
}
コード例 #3
0
ファイル: loops.cpp プロジェクト: mokerjoke/circa
void for_loop_remake_zero_branch(Branch* forContents)
{
    Branch* zero = for_loop_get_zero_branch(forContents);
    clear_branch(zero);

    // Clone inputs
    for (int i=0;; i++) {
        Term* placeholder = get_input_placeholder(forContents, i);
        if (placeholder == NULL)
            break;
        Term* clone = append_input_placeholder(zero);
        rename(clone, placeholder->nameSymbol);
    }

    Term* loopOutput = create_list(zero);

    // Clone outputs
    for (int i=0;; i++) {
        Term* placeholder = get_output_placeholder(forContents, i);
        if (placeholder == NULL)
            break;

        // Find the appropriate connection
        Term* result = find_local_name(zero, placeholder->name.c_str());

        if (i == 0)
            result = loopOutput;

        Term* clone = append_output_placeholder(zero, result);
        rename(clone, placeholder->nameSymbol);
    }

    branch_finish_changes(zero);
}
コード例 #4
0
ファイル: reflection.cpp プロジェクト: ShenTensen/circa
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));
}
コード例 #5
0
ファイル: native_patch.cpp プロジェクト: RickMoynihan/circa
void native_patch_apply_patch(NativePatch* module, Block* block)
{
    // Walk through list of patches, and try to find any functions to apply them to.
    std::map<std::string, EvaluateFunc>::const_iterator it;
    for (it = module->patches.begin(); it != module->patches.end(); ++it) {
        std::string const& name = it->first;
        EvaluateFunc evaluateFunc = it->second;

        Term* term = find_local_name(block, name.c_str());

        if (term == NULL)
            continue;
        if (!is_function(term))
            continue;

        install_function(term, evaluateFunc);
    }
}
コード例 #6
0
ファイル: block.cpp プロジェクト: ShenTensen/circa
void block_link_missing_functions(Block* block, Block* source)
{
    for (BlockIterator it(block); it; ++it) {
        Term* term = *it;
        if (term->function == NULL
                || term->function == FUNCS.unknown_function
                || term->function == FUNCS.unknown_function_prelude) {
            std::string funcName = term->stringProp(s_Syntax_FunctionName, "");
            
            if (funcName == "")
                continue;

            // try to find this function
            Term* func = find_local_name(source, funcName.c_str(), s_LookupFunction);

            if (func != NULL)
                change_function(term, func);
        }
    }
}
コード例 #7
0
ファイル: block.cpp プロジェクト: ShenTensen/circa
Term* Block::operator[](std::string const& name)
{
    return find_local_name(this, name.c_str());
}
コード例 #8
0
ファイル: block.cpp プロジェクト: ShenTensen/circa
Term* Block::getNamed(const char* name)
{
    return find_local_name(this, name);
}