| 1687 | */ |
| 1688 | |
| 1689 | void init_agent_memory(agent* thisAgent) |
| 1690 | { |
| 1691 | |
| 1692 | /* The following code was taken from the do_one_top_level_phase function |
| 1693 | near the top of this file */ |
| 1694 | // If there is already a top goal this function should probably not be called |
| 1695 | assert(thisAgent->top_goal == 0 && |
| 1696 | "There should be no top goal when init_agent_memory is called!"); |
| 1697 | if (thisAgent->top_goal) |
| 1698 | { |
| 1699 | return; |
| 1700 | } |
| 1701 | |
| 1702 | thisAgent->io_header = get_new_io_identifier(thisAgent, 'I'); |
| 1703 | thisAgent->io_header_input = get_new_io_identifier(thisAgent, 'I'); |
| 1704 | thisAgent->io_header_output = get_new_io_identifier(thisAgent, 'I'); |
| 1705 | |
| 1706 | create_top_goal(thisAgent); |
| 1707 | if (thisAgent->sysparams[TRACE_CONTEXT_DECISIONS_SYSPARAM]) |
| 1708 | { |
| 1709 | print_string(thisAgent, "\n"); |
| 1710 | print_lowest_slot_in_context_stack(thisAgent); |
| 1711 | } |
| 1712 | thisAgent->current_phase = INPUT_PHASE; |
| 1713 | thisAgent->d_cycle_count++; |
| 1714 | thisAgent->wma_d_cycle_count++; |
| 1715 | |
| 1716 | /* The following code was taken from the do_input_cycle function of io.cpp */ |
| 1717 | // Creating the io_header and adding the top state io header wme |
| 1718 | thisAgent->io_header_link = add_input_wme(thisAgent, |
| 1719 | thisAgent->top_state, |
| 1720 | thisAgent->io_symbol, |
| 1721 | thisAgent->io_header); |
| 1722 | // Creating the input and output header symbols and wmes |
| 1723 | // RPM 9/06 changed to use thisAgent->input/output_link_symbol |
| 1724 | // Note we don't have to save these wmes for later release since their parent |
| 1725 | // is already being saved (above), and when we release it they will automatically be released |
| 1726 | add_input_wme(thisAgent, thisAgent->io_header, |
| 1727 | thisAgent->input_link_symbol, |
| 1728 | thisAgent->io_header_input); |
| 1729 | add_input_wme(thisAgent, thisAgent->io_header, |
| 1730 | thisAgent->output_link_symbol, |
| 1731 | thisAgent->io_header_output); |
| 1732 | |
| 1733 | // KJC & RPM 10/06 |
| 1734 | // A lot of stuff isn't initialized properly until the input and output cycles are run the first time. |
| 1735 | // Because of this, SW had to put in a hack to work around changes made to the output-link in the first |
| 1736 | // dc not being visible. (see comment near end of update_for_top_state_wme_addition). This change added |
| 1737 | // an item to the associated_output_links list. |
| 1738 | // But the ol->ids_in_tc is still not initialized until the first output phase, so if we exit before that, |
| 1739 | // remove_output_link_tc_info doesn't see it and doesn't clean up the associated_output_links list. |
| 1740 | // If we do run an output phase, though, the same item is added to the associated_output_links list twice. |
| 1741 | // ol->ids_in_tc gets initialized, so remove_output_link_tc_info -- but it only cleans up the first copy |
| 1742 | // of the item. |
| 1743 | // All of these problems come back to things not being initialized properly, so we run the input and output |
| 1744 | // phases here to force proper initialization (and have commented out SW's changes to |
| 1745 | // update_for_top_state_wme_addition). This will cause somecallbacks to be triggered, but we don't think |
| 1746 | // this is a problem for two reasons: |
no test coverage detected