GDScript: Fix setter being called in chains for shared types

When a type is shared (i.e. passed by reference) it doesn't need to be
called in a setter chain (e.g. `a.b.c = 0`) since it will be updated in
place.

This commit adds an instruction that jumps when the value is shared so
it can be used to skip those cases and avoid redundant calls of setters.
It also solves issues when assigning to sub-properties of read-only
properties.
This commit is contained in:
George Marques 2022-06-27 12:09:51 -03:00
parent 307dfa9fe9
commit 511a4b761c
No known key found for this signature in database
GPG key ID: 046BD46A3201E43D
9 changed files with 104 additions and 23 deletions

View file

@ -1336,6 +1336,18 @@ void GDScriptByteCodeGenerator::write_endif() {
if_jmp_addrs.pop_back();
}
void GDScriptByteCodeGenerator::write_jump_if_shared(const Address &p_value) {
append(GDScriptFunction::OPCODE_JUMP_IF_SHARED, 1);
append(p_value);
if_jmp_addrs.push_back(opcodes.size());
append(0); // Jump destination, will be patched.
}
void GDScriptByteCodeGenerator::write_end_jump_if_shared() {
patch_jump(if_jmp_addrs.back()->get());
if_jmp_addrs.pop_back();
}
void GDScriptByteCodeGenerator::start_for(const GDScriptDataType &p_iterator_type, const GDScriptDataType &p_list_type) {
Address counter(Address::LOCAL_VARIABLE, add_local("@counter_pos", p_iterator_type), p_iterator_type);
Address container(Address::LOCAL_VARIABLE, add_local("@container_pos", p_list_type), p_list_type);