コード例 #1
0
ファイル: loops.cpp プロジェクト: andyfischer/circa
void start_building_for_loop(Block* contents, Term* listExpr, Value* indexName,
    Value* elementName, Type* iteratorType)
{
    Term* iterator = apply(contents, FUNCS.loop_iterator, TermList(listExpr));

    Term* done = apply_dynamic_method(contents, s_done, TermList(iterator));
    hide_from_source(done);

    Term* getKey = apply_dynamic_method(contents, s_key, TermList(iterator));
    hide_from_source(getKey);

    if (!is_null(indexName)) {
        Term* getIndex = apply_dynamic_method(contents, s_key, TermList(iterator), indexName);
        hide_from_source(getIndex);
    }

    Term* getCurrent = apply_dynamic_method(contents, s_current, TermList(iterator), elementName);
    getCurrent->setBoolProp(s_iterator_value, true);
    hide_from_source(getCurrent);

    if (iteratorType != NULL) {
        Term* castedValue = apply(contents, FUNCS.cast,
            TermList(getCurrent, iteratorType->declaringTerm), elementName);
    }
}
コード例 #2
0
ファイル: loops.cpp プロジェクト: mokerjoke/circa
Term* start_building_for_loop(Term* forTerm, const char* iteratorName, Type* iteratorType)
{
    Branch* contents = nested_contents(forTerm);

    // Add input placeholder for the list input
    Term* listInput = apply(contents, FUNCS.input, TermList());

    // Add loop_index()
    Term* index = apply(contents, FUNCS.loop_index, TermList(listInput));
    hide_from_source(index);

    // Add get_index to fetch the list's current element.
    Term* iterator = apply(contents, FUNCS.get_index, TermList(listInput, index),
        name_from_string(iteratorName));

    if (iteratorType == NULL)
        iteratorType = infer_type_of_get_index(forTerm->input(0));
    
    change_declared_type(iterator, iteratorType);
    hide_from_source(iterator);

    // Add the zero branch
    create_branch_unevaluated(contents, "#zero");

    // Add an loop output index
    Term* loopOutputIndex = apply(contents, FUNCS.loop_output_index, TermList());

    return iterator;
}
コード例 #3
0
ファイル: loops.cpp プロジェクト: levelplane/circa
Term* start_building_for_loop(Term* forTerm, const char* iteratorName)
{
    Branch* contents = nested_contents(forTerm);

    // Add input placeholder for the list input
    Term* listInput = apply(contents, FUNCS.input, TermList());

    // Add loop_index()
    Term* index = apply(contents, FUNCS.loop_index, TermList(listInput));
    hide_from_source(index);

    // Add loop_iterator()
    Term* iterator = apply(contents, FUNCS.get_index, TermList(listInput, index),
        iteratorName);
    change_declared_type(iterator, infer_type_of_get_index(forTerm->input(0)));
    hide_from_source(iterator);
    return iterator;
}
コード例 #4
0
ファイル: loops.cpp プロジェクト: andyfischer/circa
void finish_for_loop(Term* forTerm)
{
    Block* block = nested_contents(forTerm);

    // Need to finish here to prevent error
    block_finish_changes(block);

    Term* primaryResult = loop_get_primary_result(block);

    Term* iterator = loop_find_iterator(block);
    Term* nextCall = apply_dynamic_method(block, s_advance, TermList(iterator));
    hide_from_source(nextCall);

    // Add a a primary output
    Term* primaryOutput = apply(block, FUNCS.output, TermList(primaryResult));
    primaryOutput->setBoolProp(s_AccumulatingOutput, true); // TODO: can delete?
    respecialize_type(primaryOutput);

    insert_looped_placeholders(block);

    update_extra_outputs(forTerm, block);

    block_finish_changes(block);
}