diff options
Diffstat (limited to 'modules/gdscript/gdscript_byte_codegen.h')
-rw-r--r-- | modules/gdscript/gdscript_byte_codegen.h | 54 |
1 files changed, 47 insertions, 7 deletions
diff --git a/modules/gdscript/gdscript_byte_codegen.h b/modules/gdscript/gdscript_byte_codegen.h index 171c505116..1d1b22e196 100644 --- a/modules/gdscript/gdscript_byte_codegen.h +++ b/modules/gdscript/gdscript_byte_codegen.h @@ -48,6 +48,33 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator { const static int RESERVED_STACK = 3; // For self, class, and nil. + struct CallTarget { + Address target; + bool is_new_temporary = false; + GDScriptByteCodeGenerator *codegen = nullptr; +#ifdef DEV_ENABLED + bool cleaned = false; +#endif + + void cleanup() { + DEV_ASSERT(!cleaned); + if (is_new_temporary) { + codegen->pop_temporary(); + } +#ifdef DEV_ENABLED + cleaned = true; +#endif + } + + CallTarget(Address p_target, bool p_is_new_temporary, GDScriptByteCodeGenerator *p_codegen) : + target(p_target), + is_new_temporary(p_is_new_temporary), + codegen(p_codegen) {} + ~CallTarget() { DEV_ASSERT(cleaned); } + CallTarget(const CallTarget &) = delete; + CallTarget &operator=(CallTarget &) = delete; + }; + bool ended = false; GDScriptFunction *function = nullptr; bool debug_stack = false; @@ -95,6 +122,24 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator { RBMap<MethodBind *, int> method_bind_map; RBMap<GDScriptFunction *, int> lambdas_map; +#if DEBUG_ENABLED + // Keep method and property names for pointer and validated operations. + // Used when disassembling the bytecode. + Vector<String> operator_names; + Vector<String> setter_names; + Vector<String> getter_names; + Vector<String> builtin_methods_names; + Vector<String> constructors_names; + Vector<String> utilities_names; + Vector<String> gds_utilities_names; + void add_debug_name(Vector<String> &vector, int index, const String &name) { + if (index >= vector.size()) { + vector.resize(index + 1); + } + vector.write[index] = name; + } +#endif + // Lists since these can be nested. List<int> if_jmp_addrs; List<int> for_jmp_addrs; @@ -113,7 +158,6 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator { List<int> ternary_jump_skip_pos; List<List<int>> current_breaks_to_patch; - List<List<int>> match_continues_to_patch; void add_stack_identifier(const StringName &p_id, int p_stackpos) { if (locals.size() > max_locals) { @@ -309,7 +353,7 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator { } } - Address get_call_target(const Address &p_target, Variant::Type p_type = Variant::NIL); + CallTarget get_call_target(const Address &p_target, Variant::Type p_type = Variant::NIL); int address_of(const Address &p_address) { switch (p_address.mode) { @@ -468,8 +512,8 @@ public: virtual void write_super_call(const Address &p_target, const StringName &p_function_name, const Vector<Address> &p_arguments) override; virtual void write_call_async(const Address &p_target, const Address &p_base, const StringName &p_function_name, const Vector<Address> &p_arguments) override; virtual void write_call_utility(const Address &p_target, const StringName &p_function, const Vector<Address> &p_arguments) override; - virtual void write_call_gdscript_utility(const Address &p_target, GDScriptUtilityFunctions::FunctionPtr p_function, const Vector<Address> &p_arguments) override; void write_call_builtin_type(const Address &p_target, const Address &p_base, Variant::Type p_type, const StringName &p_method, bool p_is_static, const Vector<Address> &p_arguments); + virtual void write_call_gdscript_utility(const Address &p_target, const StringName &p_function, const Vector<Address> &p_arguments) override; virtual void write_call_builtin_type(const Address &p_target, const Address &p_base, Variant::Type p_type, const StringName &p_method, const Vector<Address> &p_arguments) override; virtual void write_call_builtin_type_static(const Address &p_target, Variant::Type p_type, const StringName &p_method, const Vector<Address> &p_arguments) override; virtual void write_call_native_static(const Address &p_target, const StringName &p_class, const StringName &p_method, const Vector<Address> &p_arguments) override; @@ -496,12 +540,8 @@ public: virtual void start_while_condition() override; virtual void write_while(const Address &p_condition) override; virtual void write_endwhile() override; - virtual void start_match() override; - virtual void start_match_branch() override; - virtual void end_match() override; virtual void write_break() override; virtual void write_continue() override; - virtual void write_continue_match() override; virtual void write_breakpoint() override; virtual void write_newline(int p_line) override; virtual void write_return(const Address &p_return_value) override; |