diff options
author | George Marques <george@gmarqu.es> | 2020-11-13 10:31:14 -0300 |
---|---|---|
committer | George Marques <george@gmarqu.es> | 2020-11-21 13:24:49 -0300 |
commit | c707d6fe717c43fecafa0aca53182f214268ec16 (patch) | |
tree | ea042ae9a1655dfc3ce0fcab17954bd33d2e4a88 /modules/gdscript/gdscript_byte_codegen.h | |
parent | b6519d0d03fa444ad39a41f295b25317926189fc (diff) | |
download | redot-engine-c707d6fe717c43fecafa0aca53182f214268ec16.tar.gz |
GDScript: Gather instructions arguments beforehand
Almost all instructions need variant arguments. With this change they
are loaded in an array before each instruction call. This makes the
addressing code be localized to less places, improving compilation
overhead and binary size by a small margin.
This should not affect performance.
Diffstat (limited to 'modules/gdscript/gdscript_byte_codegen.h')
-rw-r--r-- | modules/gdscript/gdscript_byte_codegen.h | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/modules/gdscript/gdscript_byte_codegen.h b/modules/gdscript/gdscript_byte_codegen.h index 62438b6dd2..e8d7de21c2 100644 --- a/modules/gdscript/gdscript_byte_codegen.h +++ b/modules/gdscript/gdscript_byte_codegen.h @@ -33,6 +33,8 @@ #include "gdscript_codegen.h" +#include "gdscript_function.h" + class GDScriptByteCodeGenerator : public GDScriptCodeGenerator { bool ended = false; GDScriptFunction *function = nullptr; @@ -57,7 +59,7 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator { #endif int current_line = 0; int stack_max = 0; - int call_max = 0; + int instr_args_max = 0; List<int> if_jmp_addrs; // List since this can be nested. List<int> for_jmp_addrs; @@ -139,11 +141,6 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator { stack_max = p_level + 1; } - void alloc_call(int p_params) { - if (p_params >= call_max) - call_max = p_params; - } - int increase_stack() { int top = current_stack_size++; alloc_stack(current_stack_size); @@ -177,8 +174,13 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator { return -1; // Unreachable. } - void append(int code) { - opcodes.push_back(code); + void append(GDScriptFunction::Opcode p_code, int p_argument_count) { + opcodes.push_back((p_code & GDScriptFunction::INSTR_MASK) | (p_argument_count << GDScriptFunction::INSTR_BITS)); + instr_args_max = MAX(instr_args_max, p_argument_count); + } + + void append(int p_code) { + opcodes.push_back(p_code); } void append(const Address &p_address) { |