diff options
Diffstat (limited to 'modules/gdscript/gdscript_byte_codegen.h')
-rw-r--r-- | modules/gdscript/gdscript_byte_codegen.h | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/modules/gdscript/gdscript_byte_codegen.h b/modules/gdscript/gdscript_byte_codegen.h index 52d631c430..4b196ed420 100644 --- a/modules/gdscript/gdscript_byte_codegen.h +++ b/modules/gdscript/gdscript_byte_codegen.h @@ -51,11 +51,11 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator { List<Map<StringName, int>> block_identifier_stack; Map<StringName, int> block_identifiers; - int current_stack_size = 0; + int current_stack_size = 3; // First 3 spots are reserved for self, class, and nil. int current_temporaries = 0; int current_locals = 0; int current_line = 0; - int stack_max = 0; + int stack_max = 3; int instr_args_max = 0; int ptrcall_max = 0; @@ -135,7 +135,7 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator { ERR_PRINT("Leaving block with non-zero temporary variables: " + itos(current_temporaries)); } #endif - current_stack_size = current_locals; + current_stack_size = current_locals + 3; // Keep the 3 reserved slots for self, class, and nil. if (debug_stack) { for (Map<StringName, int>::Element *E = block_identifiers.front(); E; E = E->next()) { @@ -163,64 +163,72 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator { } int get_constant_pos(const Variant &p_constant) { - if (constant_map.has(p_constant)) + if (constant_map.has(p_constant)) { return constant_map[p_constant]; + } int pos = constant_map.size(); constant_map[p_constant] = pos; return pos; } int get_operation_pos(const Variant::ValidatedOperatorEvaluator p_operation) { - if (operator_func_map.has(p_operation)) + if (operator_func_map.has(p_operation)) { return operator_func_map[p_operation]; + } int pos = operator_func_map.size(); operator_func_map[p_operation] = pos; return pos; } int get_setter_pos(const Variant::ValidatedSetter p_setter) { - if (setters_map.has(p_setter)) + if (setters_map.has(p_setter)) { return setters_map[p_setter]; + } int pos = setters_map.size(); setters_map[p_setter] = pos; return pos; } int get_getter_pos(const Variant::ValidatedGetter p_getter) { - if (getters_map.has(p_getter)) + if (getters_map.has(p_getter)) { return getters_map[p_getter]; + } int pos = getters_map.size(); getters_map[p_getter] = pos; return pos; } int get_keyed_setter_pos(const Variant::ValidatedKeyedSetter p_keyed_setter) { - if (keyed_setters_map.has(p_keyed_setter)) + if (keyed_setters_map.has(p_keyed_setter)) { return keyed_setters_map[p_keyed_setter]; + } int pos = keyed_setters_map.size(); keyed_setters_map[p_keyed_setter] = pos; return pos; } int get_keyed_getter_pos(const Variant::ValidatedKeyedGetter p_keyed_getter) { - if (keyed_getters_map.has(p_keyed_getter)) + if (keyed_getters_map.has(p_keyed_getter)) { return keyed_getters_map[p_keyed_getter]; + } int pos = keyed_getters_map.size(); keyed_getters_map[p_keyed_getter] = pos; return pos; } int get_indexed_setter_pos(const Variant::ValidatedIndexedSetter p_indexed_setter) { - if (indexed_setters_map.has(p_indexed_setter)) + if (indexed_setters_map.has(p_indexed_setter)) { return indexed_setters_map[p_indexed_setter]; + } int pos = indexed_setters_map.size(); indexed_setters_map[p_indexed_setter] = pos; return pos; } int get_indexed_getter_pos(const Variant::ValidatedIndexedGetter p_indexed_getter) { - if (indexed_getters_map.has(p_indexed_getter)) + if (indexed_getters_map.has(p_indexed_getter)) { return indexed_getters_map[p_indexed_getter]; + } int pos = indexed_getters_map.size(); indexed_getters_map[p_indexed_getter] = pos; return pos; @@ -272,8 +280,9 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator { } void alloc_stack(int p_level) { - if (p_level >= stack_max) + if (p_level >= stack_max) { stack_max = p_level + 1; + } } int increase_stack() { @@ -283,33 +292,27 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator { } void alloc_ptrcall(int p_params) { - if (p_params >= ptrcall_max) + if (p_params >= ptrcall_max) { ptrcall_max = p_params; + } } int address_of(const Address &p_address) { switch (p_address.mode) { case Address::SELF: - return GDScriptFunction::ADDR_TYPE_SELF << GDScriptFunction::ADDR_BITS; + return GDScriptFunction::ADDR_SELF; case Address::CLASS: - return GDScriptFunction::ADDR_TYPE_CLASS << GDScriptFunction::ADDR_BITS; + return GDScriptFunction::ADDR_CLASS; case Address::MEMBER: return p_address.address | (GDScriptFunction::ADDR_TYPE_MEMBER << GDScriptFunction::ADDR_BITS); - case Address::CLASS_CONSTANT: - return p_address.address | (GDScriptFunction::ADDR_TYPE_CLASS_CONSTANT << GDScriptFunction::ADDR_BITS); - case Address::LOCAL_CONSTANT: case Address::CONSTANT: - return p_address.address | (GDScriptFunction::ADDR_TYPE_LOCAL_CONSTANT << GDScriptFunction::ADDR_BITS); + return p_address.address | (GDScriptFunction::ADDR_TYPE_CONSTANT << GDScriptFunction::ADDR_BITS); case Address::LOCAL_VARIABLE: case Address::TEMPORARY: case Address::FUNCTION_PARAMETER: return p_address.address | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS); - case Address::GLOBAL: - return p_address.address | (GDScriptFunction::ADDR_TYPE_GLOBAL << GDScriptFunction::ADDR_BITS); - case Address::NAMED_GLOBAL: - return p_address.address | (GDScriptFunction::ADDR_TYPE_NAMED_GLOBAL << GDScriptFunction::ADDR_BITS); case Address::NIL: - return GDScriptFunction::ADDR_TYPE_NIL << GDScriptFunction::ADDR_BITS; + return GDScriptFunction::ADDR_NIL; } return -1; // Unreachable. } @@ -431,6 +434,7 @@ public: virtual void write_assign_true(const Address &p_target) override; virtual void write_assign_false(const Address &p_target) override; virtual void write_assign_default_parameter(const Address &p_dst, const Address &p_src) override; + virtual void write_store_named_global(const Address &p_dst, const StringName &p_global) override; virtual void write_cast(const Address &p_target, const Address &p_source, const GDScriptDataType &p_type) override; virtual void write_call(const Address &p_target, const Address &p_base, const StringName &p_function_name, const Vector<Address> &p_arguments) override; virtual void write_super_call(const Address &p_target, const StringName &p_function_name, const Vector<Address> &p_arguments) override; |