MCPcopy Create free account
hub / github.com/OpenMW/openmw / generateInstructionCode

Method generateInstructionCode

components/compiler/extensions.cpp:157–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {

Callers 1

parseKeywordMethod · 0.80

Calls 7

pushIntFunction · 0.85
segment3Function · 0.85
segment5Function · 0.85
addStringMethod · 0.80
findMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected