void finish_for_loop(Term* forTerm) { Branch* contents = nested_contents(forTerm); // Need to finish here to prevent error branch_finish_changes(contents); // Add a a primary output Term* primaryOutput = apply(contents, FUNCS.output, TermList(loop_get_primary_result(contents))); primaryOutput->setBoolProp("accumulatingOutput", true); respecialize_type(primaryOutput); // pack_any_open_state_vars(contents); for_loop_fix_state_input(contents); check_to_add_state_output_placeholder(contents); add_implicit_placeholders(forTerm); repoint_terms_to_use_input_placeholders(contents); check_to_insert_implicit_inputs(forTerm); update_extra_outputs(forTerm); branch_finish_changes(contents); }
Term* if_block_add_output_for_name(Term* ifCall, const char* name) { // Fix the new output placeholders to have the correct name and input. Branch* mainBranch = nested_contents(ifCall); int outputCount = count_output_placeholders(mainBranch); Term* outputPlaceholder = if_block_append_output(ifCall); rename(outputPlaceholder, name); for (CaseIterator it(mainBranch); it.unfinished(); it.advance()) { Branch* caseContents = nested_contents(it.current()); Term* casePlaceholder = get_output_placeholder(caseContents, outputCount); ca_assert(casePlaceholder != NULL); ca_assert(casePlaceholder->name == ""); rename(casePlaceholder, name); set_input(casePlaceholder, 0, find_name_at(casePlaceholder, name)); respecialize_type(casePlaceholder); } return outputPlaceholder; }
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); }