| 150 | } |
| 151 | |
| 152 | bool cInstSet::LoadWithStringList(const cStringList& sl, cUserFeedback* feedback) |
| 153 | { |
| 154 | cArgSchema schema(':'); |
| 155 | |
| 156 | // Integer |
| 157 | schema.AddEntry("cost", 0, 0); |
| 158 | schema.AddEntry("initial_cost", 1, 0); |
| 159 | schema.AddEntry("energy_cost", 2, 0); |
| 160 | schema.AddEntry("addl_time_cost", 3, 0); |
| 161 | schema.AddEntry("female_cost", 4, 0); //@CHC |
| 162 | schema.AddEntry("choosy_female_cost", 5, 0); //@CHC |
| 163 | schema.AddEntry("post_cost", 6, 0); |
| 164 | |
| 165 | // Double |
| 166 | schema.AddEntry("prob_fail", 0, 0.0); |
| 167 | schema.AddEntry("res_cost", 1, 0.0); |
| 168 | schema.AddEntry("redundancy", 2, 1.0); |
| 169 | schema.AddEntry("fem_res_cost", 3, 0.0); |
| 170 | schema.AddEntry("bonus_cost", 4, 0.0); |
| 171 | |
| 172 | // String |
| 173 | schema.AddEntry("inst_code", 0, ""); |
| 174 | |
| 175 | |
| 176 | // Ensure that the instruction code length is in the range of bits supported by the int type |
| 177 | int inst_code_len = m_world->GetConfig().INST_CODE_LENGTH.Get(); |
| 178 | if ((unsigned)inst_code_len > (sizeof(int) * 8)) inst_code_len = sizeof(int) * 8; |
| 179 | else if (inst_code_len <= 0) inst_code_len = 1; |
| 180 | |
| 181 | bool success = true; |
| 182 | for (int line_id = 0; line_id < sl.GetSize(); line_id++) { |
| 183 | cString cur_line = sl.GetLine(line_id); |
| 184 | |
| 185 | // Look for the INST keyword at the beginning of each line, and ignore if not found. |
| 186 | cString inst_name = cur_line.PopWord(); |
| 187 | if (inst_name != "INST") continue; |
| 188 | |
| 189 | // Lookup the instruction name in the library |
| 190 | inst_name = cur_line.Pop(':'); |
| 191 | int fun_id = m_inst_lib->GetIndex(inst_name); |
| 192 | if (fun_id == -1) { |
| 193 | // Oh oh! Didn't find an instruction! |
| 194 | Apto::String a_inst_name((const char*)inst_name); |
| 195 | if (feedback) feedback->Error("unknown instruction '%s' (Best match = '%s')", |
| 196 | (const char*)inst_name, (const char*)m_inst_lib->GetNearMatch(a_inst_name)); |
| 197 | success = false; |
| 198 | continue; |
| 199 | } |
| 200 | |
| 201 | // Load the arguments for this instruction |
| 202 | cArgContainer* args = cArgContainer::Load(cur_line, schema, *feedback); |
| 203 | if (!args) { |
| 204 | success = false; |
| 205 | continue; |
| 206 | } |
| 207 | |
| 208 | // Check to make sure we are not inserting the special NULL instruction |
| 209 | if (fun_id == m_inst_lib->GetInstNull()) { |
no test coverage detected