static void append_final_pack_state(Branch* branch) { TermList inputs; get_list_of_state_outputs(branch, branch->length(), &inputs); Term* term = apply(branch, FUNCS.pack_state, inputs); term->setBoolProp("final", true); }
void branch_update_existing_pack_state_calls(Branch* branch) { if (branch->stateType == NULL) { // No state type, make sure there's no pack_state call. // TODO: Handle this case properly (should search and destroy an existing pack_state call) return; } int stateOutputIndex = branch->length() - 1 - find_state_output(branch)->index; for (int i=0; i < branch->length(); i++) { Term* term = branch->get(i); if (term == NULL) continue; if (term->function == FUNCS.pack_state) { // Update the inputs for this pack_state call TermList inputs; get_list_of_state_outputs(branch, i, &inputs); set_inputs(term, inputs); } if (term->function == FUNCS.exit_point) { // Check if we need to insert a pack_state call Term* existing = term->input(stateOutputIndex); if (existing == NULL || existing->function != FUNCS.pack_state) { TermList inputs; get_list_of_state_outputs(branch, i, &inputs); if (inputs.length() != 0) { Term* pack_state = apply(branch, FUNCS.pack_state, inputs); move_before(pack_state, term); set_input(term, stateOutputIndex + 1, pack_state); // Advance i to compensate for the term just added i++; } } } } }
Term* branch_add_pack_state(Branch* branch) { TermList inputs; get_list_of_state_outputs(branch, branch->length(), &inputs); // Don't create anything if there are no state outputs if (inputs.length() == 0) return NULL; return apply(branch, FUNCS.pack_state, inputs); }