mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
GDScript: Don't use the NIL address to hold return value of functions
This prevents that the NIL address is filled with another value, which causes problems for some instructions that read from NIL.
This commit is contained in:
parent
b14f7aa9f9
commit
a3816434a6
5 changed files with 104 additions and 43 deletions
|
@ -920,13 +920,23 @@ void GDScriptByteCodeGenerator::write_cast(const Address &p_target, const Addres
|
|||
append(index);
|
||||
}
|
||||
|
||||
GDScriptCodeGenerator::Address GDScriptByteCodeGenerator::get_call_target(const GDScriptCodeGenerator::Address &p_target) {
|
||||
if (p_target.mode == Address::NIL) {
|
||||
uint32_t addr = add_temporary(p_target.type);
|
||||
pop_temporary();
|
||||
return Address(Address::TEMPORARY, addr, p_target.type);
|
||||
} else {
|
||||
return p_target;
|
||||
}
|
||||
}
|
||||
|
||||
void GDScriptByteCodeGenerator::write_call(const Address &p_target, const Address &p_base, const StringName &p_function_name, const Vector<Address> &p_arguments) {
|
||||
append_opcode_and_argcount(p_target.mode == Address::NIL ? GDScriptFunction::OPCODE_CALL : GDScriptFunction::OPCODE_CALL_RETURN, 2 + p_arguments.size());
|
||||
for (int i = 0; i < p_arguments.size(); i++) {
|
||||
append(p_arguments[i]);
|
||||
}
|
||||
append(p_base);
|
||||
append(p_target);
|
||||
append(get_call_target(p_target));
|
||||
append(p_arguments.size());
|
||||
append(p_function_name);
|
||||
}
|
||||
|
@ -936,7 +946,7 @@ void GDScriptByteCodeGenerator::write_super_call(const Address &p_target, const
|
|||
for (int i = 0; i < p_arguments.size(); i++) {
|
||||
append(p_arguments[i]);
|
||||
}
|
||||
append(p_target);
|
||||
append(get_call_target(p_target));
|
||||
append(p_arguments.size());
|
||||
append(p_function_name);
|
||||
}
|
||||
|
@ -947,7 +957,7 @@ void GDScriptByteCodeGenerator::write_call_async(const Address &p_target, const
|
|||
append(p_arguments[i]);
|
||||
}
|
||||
append(p_base);
|
||||
append(p_target);
|
||||
append(get_call_target(p_target));
|
||||
append(p_arguments.size());
|
||||
append(p_function_name);
|
||||
}
|
||||
|
@ -957,7 +967,7 @@ void GDScriptByteCodeGenerator::write_call_gdscript_utility(const Address &p_tar
|
|||
for (int i = 0; i < p_arguments.size(); i++) {
|
||||
append(p_arguments[i]);
|
||||
}
|
||||
append(p_target);
|
||||
append(get_call_target(p_target));
|
||||
append(p_arguments.size());
|
||||
append(p_function);
|
||||
}
|
||||
|
@ -983,7 +993,7 @@ void GDScriptByteCodeGenerator::write_call_utility(const Address &p_target, cons
|
|||
for (int i = 0; i < p_arguments.size(); i++) {
|
||||
append(p_arguments[i]);
|
||||
}
|
||||
append(p_target);
|
||||
append(get_call_target(p_target));
|
||||
append(p_arguments.size());
|
||||
append(Variant::get_validated_utility_function(p_function));
|
||||
} else {
|
||||
|
@ -991,7 +1001,7 @@ void GDScriptByteCodeGenerator::write_call_utility(const Address &p_target, cons
|
|||
for (int i = 0; i < p_arguments.size(); i++) {
|
||||
append(p_arguments[i]);
|
||||
}
|
||||
append(p_target);
|
||||
append(get_call_target(p_target));
|
||||
append(p_arguments.size());
|
||||
append(p_function);
|
||||
}
|
||||
|
@ -1035,7 +1045,7 @@ void GDScriptByteCodeGenerator::write_call_builtin_type(const Address &p_target,
|
|||
append(p_arguments[i]);
|
||||
}
|
||||
append(p_base);
|
||||
append(p_target);
|
||||
append(get_call_target(p_target));
|
||||
append(p_arguments.size());
|
||||
append(Variant::get_validated_builtin_method(p_type, p_method));
|
||||
}
|
||||
|
@ -1064,7 +1074,7 @@ void GDScriptByteCodeGenerator::write_call_builtin_type_static(const Address &p_
|
|||
for (int i = 0; i < p_arguments.size(); i++) {
|
||||
append(p_arguments[i]);
|
||||
}
|
||||
append(p_target);
|
||||
append(get_call_target(p_target));
|
||||
append(p_type);
|
||||
append(p_method);
|
||||
append(p_arguments.size());
|
||||
|
@ -1085,7 +1095,7 @@ void GDScriptByteCodeGenerator::write_call_builtin_type_static(const Address &p_
|
|||
append(p_arguments[i]);
|
||||
}
|
||||
append(Address()); // No base since it's static.
|
||||
append(p_target);
|
||||
append(get_call_target(p_target));
|
||||
append(p_arguments.size());
|
||||
append(Variant::get_validated_builtin_method(p_type, p_method));
|
||||
}
|
||||
|
@ -1101,7 +1111,7 @@ void GDScriptByteCodeGenerator::write_call_native_static(const Address &p_target
|
|||
for (int i = 0; i < p_arguments.size(); i++) {
|
||||
append(p_arguments[i]);
|
||||
}
|
||||
append(p_target);
|
||||
append(get_call_target(p_target));
|
||||
append(method);
|
||||
append(p_arguments.size());
|
||||
return;
|
||||
|
@ -1114,7 +1124,7 @@ void GDScriptByteCodeGenerator::write_call_method_bind(const Address &p_target,
|
|||
append(p_arguments[i]);
|
||||
}
|
||||
append(p_base);
|
||||
append(p_target);
|
||||
append(get_call_target(p_target));
|
||||
append(p_arguments.size());
|
||||
append(p_method);
|
||||
}
|
||||
|
@ -1178,7 +1188,7 @@ void GDScriptByteCodeGenerator::write_call_ptrcall(const Address &p_target, cons
|
|||
append(p_arguments[i]);
|
||||
}
|
||||
append(p_base);
|
||||
append(p_target);
|
||||
append(get_call_target(p_target));
|
||||
append(p_arguments.size());
|
||||
append(p_method);
|
||||
if (is_ptrcall) {
|
||||
|
@ -1194,7 +1204,7 @@ void GDScriptByteCodeGenerator::write_call_self(const Address &p_target, const S
|
|||
append(p_arguments[i]);
|
||||
}
|
||||
append(GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS);
|
||||
append(p_target);
|
||||
append(get_call_target(p_target));
|
||||
append(p_arguments.size());
|
||||
append(p_function_name);
|
||||
}
|
||||
|
@ -1205,7 +1215,7 @@ void GDScriptByteCodeGenerator::write_call_self_async(const Address &p_target, c
|
|||
append(p_arguments[i]);
|
||||
}
|
||||
append(GDScriptFunction::ADDR_SELF);
|
||||
append(p_target);
|
||||
append(get_call_target(p_target));
|
||||
append(p_arguments.size());
|
||||
append(p_function_name);
|
||||
}
|
||||
|
@ -1216,7 +1226,7 @@ void GDScriptByteCodeGenerator::write_call_script_function(const Address &p_targ
|
|||
append(p_arguments[i]);
|
||||
}
|
||||
append(p_base);
|
||||
append(p_target);
|
||||
append(get_call_target(p_target));
|
||||
append(p_arguments.size());
|
||||
append(p_function_name);
|
||||
}
|
||||
|
@ -1227,7 +1237,7 @@ void GDScriptByteCodeGenerator::write_lambda(const Address &p_target, GDScriptFu
|
|||
append(p_captures[i]);
|
||||
}
|
||||
|
||||
append(p_target);
|
||||
append(get_call_target(p_target));
|
||||
append(p_captures.size());
|
||||
append(p_function);
|
||||
}
|
||||
|
@ -1266,7 +1276,7 @@ void GDScriptByteCodeGenerator::write_construct(const Address &p_target, Variant
|
|||
for (int i = 0; i < p_arguments.size(); i++) {
|
||||
append(p_arguments[i]);
|
||||
}
|
||||
append(p_target);
|
||||
append(get_call_target(p_target));
|
||||
append(p_arguments.size());
|
||||
append(Variant::get_validated_constructor(p_type, valid_constructor));
|
||||
return;
|
||||
|
@ -1277,7 +1287,7 @@ void GDScriptByteCodeGenerator::write_construct(const Address &p_target, Variant
|
|||
for (int i = 0; i < p_arguments.size(); i++) {
|
||||
append(p_arguments[i]);
|
||||
}
|
||||
append(p_target);
|
||||
append(get_call_target(p_target));
|
||||
append(p_arguments.size());
|
||||
append(p_type);
|
||||
}
|
||||
|
@ -1287,7 +1297,7 @@ void GDScriptByteCodeGenerator::write_construct_array(const Address &p_target, c
|
|||
for (int i = 0; i < p_arguments.size(); i++) {
|
||||
append(p_arguments[i]);
|
||||
}
|
||||
append(p_target);
|
||||
append(get_call_target(p_target));
|
||||
append(p_arguments.size());
|
||||
}
|
||||
|
||||
|
@ -1296,7 +1306,7 @@ void GDScriptByteCodeGenerator::write_construct_typed_array(const Address &p_tar
|
|||
for (int i = 0; i < p_arguments.size(); i++) {
|
||||
append(p_arguments[i]);
|
||||
}
|
||||
append(p_target);
|
||||
append(get_call_target(p_target));
|
||||
if (p_element_type.script_type) {
|
||||
Variant script_type = Ref<Script>(p_element_type.script_type);
|
||||
int addr = get_constant_pos(script_type);
|
||||
|
@ -1315,7 +1325,7 @@ void GDScriptByteCodeGenerator::write_construct_dictionary(const Address &p_targ
|
|||
for (int i = 0; i < p_arguments.size(); i++) {
|
||||
append(p_arguments[i]);
|
||||
}
|
||||
append(p_target);
|
||||
append(get_call_target(p_target));
|
||||
append(p_arguments.size() / 2); // This is number of key-value pairs, so only half of actual arguments.
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue