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

Method generateFunctionCode

components/compiler/extensions.cpp:112–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110 }
111
112 void Extensions::generateFunctionCode(int keyword, std::vector<Interpreter::Type_Code>& code, Literals& literals,
113 const std::string& id, int optionalArguments) const
114 {
115 assert(optionalArguments >= 0);
116
117 auto iter = mFunctions.find(keyword);
118 if (iter == mFunctions.end())
119 throw std::logic_error("unknown custom function keyword");
120
121 if (optionalArguments && iter->second.mSegment != 3)
122 throw std::logic_error("functions with optional arguments must be placed into segment 3");
123
124 if (!id.empty())
125 {
126 if (iter->second.mCodeExplicit == -1)
127 throw std::logic_error("explicit references not supported");
128
129 int index = literals.addString(id);
130 Generator::pushInt(code, literals, index);
131 }
132
133 switch (iter->second.mSegment)
134 {
135 case 3:
136
137 if (optionalArguments >= 256)
138 throw std::logic_error("number of optional arguments is too large for segment 3");
139
140 code.push_back(Generator::segment3(
141 id.empty() ? iter->second.mCode : iter->second.mCodeExplicit, optionalArguments));
142
143 break;
144
145 case 5:
146
147 code.push_back(Generator::segment5(id.empty() ? iter->second.mCode : iter->second.mCodeExplicit));
148
149 break;
150
151 default:
152
153 throw std::logic_error("unsupported code segment");
154 }
155 }
156
157 void Extensions::generateInstructionCode(int keyword, std::vector<Interpreter::Type_Code>& code, Literals& literals,
158 const std::string& id, int optionalArguments) const

Callers 2

parseKeywordMethod · 0.80
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