| 155 | } |
| 156 | |
| 157 | void Extensions::generateInstructionCode(int keyword, std::vector<Interpreter::Type_Code>& code, Literals& literals, |
| 158 | const std::string& id, int optionalArguments) const |
| 159 | { |
| 160 | assert(optionalArguments >= 0); |
| 161 | |
| 162 | auto iter = mInstructions.find(keyword); |
| 163 | if (iter == mInstructions.end()) |
| 164 | throw std::logic_error("unknown custom instruction keyword"); |
| 165 | |
| 166 | if (optionalArguments && iter->second.mSegment != 3) |
| 167 | throw std::logic_error("instructions with optional arguments must be placed into segment 3"); |
| 168 | |
| 169 | if (!id.empty()) |
| 170 | { |
| 171 | if (iter->second.mCodeExplicit == -1) |
| 172 | throw std::logic_error("explicit references not supported"); |
| 173 | |
| 174 | int index = literals.addString(id); |
| 175 | Generator::pushInt(code, literals, index); |
| 176 | } |
| 177 | |
| 178 | switch (iter->second.mSegment) |
| 179 | { |
| 180 | case 3: |
| 181 | |
| 182 | if (optionalArguments >= 256) |
| 183 | throw std::logic_error("number of optional arguments is too large for segment 3"); |
| 184 | |
| 185 | code.push_back(Generator::segment3( |
| 186 | id.empty() ? iter->second.mCode : iter->second.mCodeExplicit, optionalArguments)); |
| 187 | |
| 188 | break; |
| 189 | |
| 190 | case 5: |
| 191 | |
| 192 | code.push_back(Generator::segment5(id.empty() ? iter->second.mCode : iter->second.mCodeExplicit)); |
| 193 | |
| 194 | break; |
| 195 | |
| 196 | default: |
| 197 | |
| 198 | throw std::logic_error("unsupported code segment"); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | void Extensions::listKeywords(std::vector<std::string>& keywords) const |
| 203 | { |