MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / write_end

Method write_end

modules/gdscript/gdscript_byte_codegen.cpp:186–421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

184}
185
186GDScriptFunction *GDScriptByteCodeGenerator::write_end() {
187#ifdef DEBUG_ENABLED
188 if (!used_temporaries.is_empty()) {
189 ERR_PRINT("Non-zero temporary variables at end of function: " + itos(used_temporaries.size()));
190 }
191#endif
192 append_opcode(GDScriptFunction::OPCODE_END);
193
194 for (int i = 0; i < temporaries.size(); i++) {
195 int stack_index = i + max_locals + GDScriptFunction::FIXED_ADDRESSES_MAX;
196 for (int j = 0; j < temporaries[i].bytecode_indices.size(); j++) {
197 opcodes.write[temporaries[i].bytecode_indices[j]] = stack_index | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS);
198 }
199 if (temporaries[i].type != Variant::NIL) {
200 function->temporary_slots[stack_index] = temporaries[i].type;
201 }
202 }
203
204 if (constant_map.size()) {
205 function->_constant_count = constant_map.size();
206 function->constants.resize(constant_map.size());
207 function->_constants_ptr = function->constants.ptrw();
208 for (const KeyValue<Variant, int> &K : constant_map) {
209 function->constants.write[K.value] = K.key;
210 }
211 } else {
212 function->_constants_ptr = nullptr;
213 function->_constant_count = 0;
214 }
215
216 if (name_map.size()) {
217 function->global_names.resize(name_map.size());
218 function->_global_names_ptr = &function->global_names[0];
219 for (const KeyValue<StringName, int> &E : name_map) {
220 function->global_names.write[E.value] = E.key;
221 }
222 function->_global_names_count = function->global_names.size();
223
224 } else {
225 function->_global_names_ptr = nullptr;
226 function->_global_names_count = 0;
227 }
228
229 if (opcodes.size()) {
230 function->code = opcodes;
231 function->_code_ptr = &function->code.write[0];
232 function->_code_size = opcodes.size();
233
234 } else {
235 function->_code_ptr = nullptr;
236 function->_code_size = 0;
237 }
238
239 if (function->default_arguments.size()) {
240 function->_default_arg_count = function->default_arguments.size() - 1;
241 function->_default_arg_ptr = &function->default_arguments[0];
242 } else {
243 function->_default_arg_count = 0;

Callers 2

_parse_functionMethod · 0.45

Calls 7

itosFunction · 0.85
should_track_localsMethod · 0.80
sizeMethod · 0.65
is_emptyMethod · 0.45
resizeMethod · 0.45
ptrwMethod · 0.45
ptrMethod · 0.45

Tested by

no test coverage detected