summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/gdscript/gdscript_byte_codegen.cpp274
-rw-r--r--modules/gdscript/gdscript_byte_codegen.h9
-rw-r--r--modules/gdscript/gdscript_disassembler.cpp33
-rw-r--r--modules/gdscript/gdscript_function.h8
-rw-r--r--modules/gdscript/gdscript_vm.cpp441
5 files changed, 405 insertions, 360 deletions
diff --git a/modules/gdscript/gdscript_byte_codegen.cpp b/modules/gdscript/gdscript_byte_codegen.cpp
index 1bc83fbbb5..89d16e679f 100644
--- a/modules/gdscript/gdscript_byte_codegen.cpp
+++ b/modules/gdscript/gdscript_byte_codegen.cpp
@@ -183,7 +183,7 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() {
ERR_PRINT("Non-zero temporary variables at end of function: " + itos(used_temporaries.size()));
}
#endif
- append(GDScriptFunction::OPCODE_END, 0);
+ append_opcode(GDScriptFunction::OPCODE_END);
for (int i = 0; i < temporaries.size(); i++) {
int stack_index = i + max_locals + RESERVED_STACK;
@@ -424,115 +424,115 @@ void GDScriptByteCodeGenerator::set_initial_line(int p_line) {
void GDScriptByteCodeGenerator::write_type_adjust(const Address &p_target, Variant::Type p_new_type) {
switch (p_new_type) {
case Variant::BOOL:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_BOOL, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_BOOL);
break;
case Variant::INT:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_INT, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_INT);
break;
case Variant::FLOAT:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_FLOAT, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_FLOAT);
break;
case Variant::STRING:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_STRING, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_STRING);
break;
case Variant::VECTOR2:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_VECTOR2, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_VECTOR2);
break;
case Variant::VECTOR2I:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_VECTOR2I, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_VECTOR2I);
break;
case Variant::RECT2:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_RECT2, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_RECT2);
break;
case Variant::RECT2I:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_RECT2I, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_RECT2I);
break;
case Variant::VECTOR3:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_VECTOR3, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_VECTOR3);
break;
case Variant::VECTOR3I:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_VECTOR3I, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_VECTOR3I);
break;
case Variant::TRANSFORM2D:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_TRANSFORM2D, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_TRANSFORM2D);
break;
case Variant::VECTOR4:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_VECTOR3, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_VECTOR3);
break;
case Variant::VECTOR4I:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_VECTOR3I, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_VECTOR3I);
break;
case Variant::PLANE:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_PLANE, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_PLANE);
break;
case Variant::QUATERNION:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_QUATERNION, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_QUATERNION);
break;
case Variant::AABB:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_AABB, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_AABB);
break;
case Variant::BASIS:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_BASIS, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_BASIS);
break;
case Variant::TRANSFORM3D:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_TRANSFORM3D, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_TRANSFORM3D);
break;
case Variant::PROJECTION:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_PROJECTION, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_PROJECTION);
break;
case Variant::COLOR:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_COLOR, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_COLOR);
break;
case Variant::STRING_NAME:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_STRING_NAME, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_STRING_NAME);
break;
case Variant::NODE_PATH:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_NODE_PATH, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_NODE_PATH);
break;
case Variant::RID:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_RID, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_RID);
break;
case Variant::OBJECT:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_OBJECT, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_OBJECT);
break;
case Variant::CALLABLE:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_CALLABLE, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_CALLABLE);
break;
case Variant::SIGNAL:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_SIGNAL, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_SIGNAL);
break;
case Variant::DICTIONARY:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_DICTIONARY, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_DICTIONARY);
break;
case Variant::ARRAY:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_ARRAY, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_ARRAY);
break;
case Variant::PACKED_BYTE_ARRAY:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_PACKED_BYTE_ARRAY, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_PACKED_BYTE_ARRAY);
break;
case Variant::PACKED_INT32_ARRAY:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_PACKED_INT32_ARRAY, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_PACKED_INT32_ARRAY);
break;
case Variant::PACKED_INT64_ARRAY:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_PACKED_INT64_ARRAY, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_PACKED_INT64_ARRAY);
break;
case Variant::PACKED_FLOAT32_ARRAY:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_PACKED_FLOAT32_ARRAY, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_PACKED_FLOAT32_ARRAY);
break;
case Variant::PACKED_FLOAT64_ARRAY:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_PACKED_FLOAT64_ARRAY, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_PACKED_FLOAT64_ARRAY);
break;
case Variant::PACKED_STRING_ARRAY:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_PACKED_STRING_ARRAY, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_PACKED_STRING_ARRAY);
break;
case Variant::PACKED_VECTOR2_ARRAY:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_PACKED_VECTOR2_ARRAY, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_PACKED_VECTOR2_ARRAY);
break;
case Variant::PACKED_VECTOR3_ARRAY:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_PACKED_VECTOR3_ARRAY, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_PACKED_VECTOR3_ARRAY);
break;
case Variant::PACKED_COLOR_ARRAY:
- append(GDScriptFunction::OPCODE_TYPE_ADJUST_PACKED_COLOR_ARRAY, 1);
+ append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_PACKED_COLOR_ARRAY);
break;
case Variant::NIL:
case Variant::VARIANT_MAX:
@@ -546,7 +546,7 @@ void GDScriptByteCodeGenerator::write_unary_operator(const Address &p_target, Va
// Gather specific operator.
Variant::ValidatedOperatorEvaluator op_func = Variant::get_validated_operator_evaluator(p_operator, p_left_operand.type.builtin_type, Variant::NIL);
- append(GDScriptFunction::OPCODE_OPERATOR_VALIDATED, 3);
+ append_opcode(GDScriptFunction::OPCODE_OPERATOR_VALIDATED);
append(p_left_operand);
append(Address());
append(p_target);
@@ -555,7 +555,7 @@ void GDScriptByteCodeGenerator::write_unary_operator(const Address &p_target, Va
}
// No specific types, perform variant evaluation.
- append(GDScriptFunction::OPCODE_OPERATOR, 3);
+ append_opcode(GDScriptFunction::OPCODE_OPERATOR);
append(p_left_operand);
append(Address());
append(p_target);
@@ -575,7 +575,7 @@ void GDScriptByteCodeGenerator::write_binary_operator(const Address &p_target, V
// Gather specific operator.
Variant::ValidatedOperatorEvaluator op_func = Variant::get_validated_operator_evaluator(p_operator, p_left_operand.type.builtin_type, p_right_operand.type.builtin_type);
- append(GDScriptFunction::OPCODE_OPERATOR_VALIDATED, 3);
+ append_opcode(GDScriptFunction::OPCODE_OPERATOR_VALIDATED);
append(p_left_operand);
append(p_right_operand);
append(p_target);
@@ -584,7 +584,7 @@ void GDScriptByteCodeGenerator::write_binary_operator(const Address &p_target, V
}
// No specific types, perform variant evaluation.
- append(GDScriptFunction::OPCODE_OPERATOR, 3);
+ append_opcode(GDScriptFunction::OPCODE_OPERATOR);
append(p_left_operand);
append(p_right_operand);
append(p_target);
@@ -592,28 +592,28 @@ void GDScriptByteCodeGenerator::write_binary_operator(const Address &p_target, V
}
void GDScriptByteCodeGenerator::write_type_test(const Address &p_target, const Address &p_source, const Address &p_type) {
- append(GDScriptFunction::OPCODE_EXTENDS_TEST, 3);
+ append_opcode(GDScriptFunction::OPCODE_EXTENDS_TEST);
append(p_source);
append(p_type);
append(p_target);
}
void GDScriptByteCodeGenerator::write_type_test_builtin(const Address &p_target, const Address &p_source, Variant::Type p_type) {
- append(GDScriptFunction::OPCODE_IS_BUILTIN, 2);
+ append_opcode(GDScriptFunction::OPCODE_IS_BUILTIN);
append(p_source);
append(p_target);
append(p_type);
}
void GDScriptByteCodeGenerator::write_and_left_operand(const Address &p_left_operand) {
- append(GDScriptFunction::OPCODE_JUMP_IF_NOT, 1);
+ append_opcode(GDScriptFunction::OPCODE_JUMP_IF_NOT);
append(p_left_operand);
logic_op_jump_pos1.push_back(opcodes.size());
append(0); // Jump target, will be patched.
}
void GDScriptByteCodeGenerator::write_and_right_operand(const Address &p_right_operand) {
- append(GDScriptFunction::OPCODE_JUMP_IF_NOT, 1);
+ append_opcode(GDScriptFunction::OPCODE_JUMP_IF_NOT);
append(p_right_operand);
logic_op_jump_pos2.push_back(opcodes.size());
append(0); // Jump target, will be patched.
@@ -621,29 +621,29 @@ void GDScriptByteCodeGenerator::write_and_right_operand(const Address &p_right_o
void GDScriptByteCodeGenerator::write_end_and(const Address &p_target) {
// If here means both operands are true.
- append(GDScriptFunction::OPCODE_ASSIGN_TRUE, 1);
+ append_opcode(GDScriptFunction::OPCODE_ASSIGN_TRUE);
append(p_target);
// Jump away from the fail condition.
- append(GDScriptFunction::OPCODE_JUMP, 0);
+ append_opcode(GDScriptFunction::OPCODE_JUMP);
append(opcodes.size() + 3);
// Here it means one of operands is false.
patch_jump(logic_op_jump_pos1.back()->get());
patch_jump(logic_op_jump_pos2.back()->get());
logic_op_jump_pos1.pop_back();
logic_op_jump_pos2.pop_back();
- append(GDScriptFunction::OPCODE_ASSIGN_FALSE, 1);
+ append_opcode(GDScriptFunction::OPCODE_ASSIGN_FALSE);
append(p_target);
}
void GDScriptByteCodeGenerator::write_or_left_operand(const Address &p_left_operand) {
- append(GDScriptFunction::OPCODE_JUMP_IF, 1);
+ append_opcode(GDScriptFunction::OPCODE_JUMP_IF);
append(p_left_operand);
logic_op_jump_pos1.push_back(opcodes.size());
append(0); // Jump target, will be patched.
}
void GDScriptByteCodeGenerator::write_or_right_operand(const Address &p_right_operand) {
- append(GDScriptFunction::OPCODE_JUMP_IF, 1);
+ append_opcode(GDScriptFunction::OPCODE_JUMP_IF);
append(p_right_operand);
logic_op_jump_pos2.push_back(opcodes.size());
append(0); // Jump target, will be patched.
@@ -651,17 +651,17 @@ void GDScriptByteCodeGenerator::write_or_right_operand(const Address &p_right_op
void GDScriptByteCodeGenerator::write_end_or(const Address &p_target) {
// If here means both operands are false.
- append(GDScriptFunction::OPCODE_ASSIGN_FALSE, 1);
+ append_opcode(GDScriptFunction::OPCODE_ASSIGN_FALSE);
append(p_target);
// Jump away from the success condition.
- append(GDScriptFunction::OPCODE_JUMP, 0);
+ append_opcode(GDScriptFunction::OPCODE_JUMP);
append(opcodes.size() + 3);
// Here it means one of operands is true.
patch_jump(logic_op_jump_pos1.back()->get());
patch_jump(logic_op_jump_pos2.back()->get());
logic_op_jump_pos1.pop_back();
logic_op_jump_pos2.pop_back();
- append(GDScriptFunction::OPCODE_ASSIGN_TRUE, 1);
+ append_opcode(GDScriptFunction::OPCODE_ASSIGN_TRUE);
append(p_target);
}
@@ -670,18 +670,18 @@ void GDScriptByteCodeGenerator::write_start_ternary(const Address &p_target) {
}
void GDScriptByteCodeGenerator::write_ternary_condition(const Address &p_condition) {
- append(GDScriptFunction::OPCODE_JUMP_IF_NOT, 1);
+ append_opcode(GDScriptFunction::OPCODE_JUMP_IF_NOT);
append(p_condition);
ternary_jump_fail_pos.push_back(opcodes.size());
append(0); // Jump target, will be patched.
}
void GDScriptByteCodeGenerator::write_ternary_true_expr(const Address &p_expr) {
- append(GDScriptFunction::OPCODE_ASSIGN, 2);
+ append_opcode(GDScriptFunction::OPCODE_ASSIGN);
append(ternary_result.back()->get());
append(p_expr);
// Jump away from the false path.
- append(GDScriptFunction::OPCODE_JUMP, 0);
+ append_opcode(GDScriptFunction::OPCODE_JUMP);
ternary_jump_skip_pos.push_back(opcodes.size());
append(0);
// Fail must jump here.
@@ -690,7 +690,7 @@ void GDScriptByteCodeGenerator::write_ternary_true_expr(const Address &p_expr) {
}
void GDScriptByteCodeGenerator::write_ternary_false_expr(const Address &p_expr) {
- append(GDScriptFunction::OPCODE_ASSIGN, 2);
+ append_opcode(GDScriptFunction::OPCODE_ASSIGN);
append(ternary_result.back()->get());
append(p_expr);
}
@@ -707,7 +707,7 @@ void GDScriptByteCodeGenerator::write_set(const Address &p_target, const Address
IS_BUILTIN_TYPE(p_source, Variant::get_indexed_element_type(p_target.type.builtin_type))) {
// Use indexed setter instead.
Variant::ValidatedIndexedSetter setter = Variant::get_member_validated_indexed_setter(p_target.type.builtin_type);
- append(GDScriptFunction::OPCODE_SET_INDEXED_VALIDATED, 3);
+ append_opcode(GDScriptFunction::OPCODE_SET_INDEXED_VALIDATED);
append(p_target);
append(p_index);
append(p_source);
@@ -715,7 +715,7 @@ void GDScriptByteCodeGenerator::write_set(const Address &p_target, const Address
return;
} else if (Variant::get_member_validated_keyed_setter(p_target.type.builtin_type)) {
Variant::ValidatedKeyedSetter setter = Variant::get_member_validated_keyed_setter(p_target.type.builtin_type);
- append(GDScriptFunction::OPCODE_SET_KEYED_VALIDATED, 3);
+ append_opcode(GDScriptFunction::OPCODE_SET_KEYED_VALIDATED);
append(p_target);
append(p_index);
append(p_source);
@@ -724,7 +724,7 @@ void GDScriptByteCodeGenerator::write_set(const Address &p_target, const Address
}
}
- append(GDScriptFunction::OPCODE_SET_KEYED, 3);
+ append_opcode(GDScriptFunction::OPCODE_SET_KEYED);
append(p_target);
append(p_index);
append(p_source);
@@ -735,7 +735,7 @@ void GDScriptByteCodeGenerator::write_get(const Address &p_target, const Address
if (IS_BUILTIN_TYPE(p_index, Variant::INT) && Variant::get_member_validated_indexed_getter(p_source.type.builtin_type)) {
// Use indexed getter instead.
Variant::ValidatedIndexedGetter getter = Variant::get_member_validated_indexed_getter(p_source.type.builtin_type);
- append(GDScriptFunction::OPCODE_GET_INDEXED_VALIDATED, 3);
+ append_opcode(GDScriptFunction::OPCODE_GET_INDEXED_VALIDATED);
append(p_source);
append(p_index);
append(p_target);
@@ -743,7 +743,7 @@ void GDScriptByteCodeGenerator::write_get(const Address &p_target, const Address
return;
} else if (Variant::get_member_validated_keyed_getter(p_source.type.builtin_type)) {
Variant::ValidatedKeyedGetter getter = Variant::get_member_validated_keyed_getter(p_source.type.builtin_type);
- append(GDScriptFunction::OPCODE_GET_KEYED_VALIDATED, 3);
+ append_opcode(GDScriptFunction::OPCODE_GET_KEYED_VALIDATED);
append(p_source);
append(p_index);
append(p_target);
@@ -751,7 +751,7 @@ void GDScriptByteCodeGenerator::write_get(const Address &p_target, const Address
return;
}
}
- append(GDScriptFunction::OPCODE_GET_KEYED, 3);
+ append_opcode(GDScriptFunction::OPCODE_GET_KEYED);
append(p_source);
append(p_index);
append(p_target);
@@ -761,13 +761,13 @@ void GDScriptByteCodeGenerator::write_set_named(const Address &p_target, const S
if (HAS_BUILTIN_TYPE(p_target) && Variant::get_member_validated_setter(p_target.type.builtin_type, p_name) &&
IS_BUILTIN_TYPE(p_source, Variant::get_member_type(p_target.type.builtin_type, p_name))) {
Variant::ValidatedSetter setter = Variant::get_member_validated_setter(p_target.type.builtin_type, p_name);
- append(GDScriptFunction::OPCODE_SET_NAMED_VALIDATED, 2);
+ append_opcode(GDScriptFunction::OPCODE_SET_NAMED_VALIDATED);
append(p_target);
append(p_source);
append(setter);
return;
}
- append(GDScriptFunction::OPCODE_SET_NAMED, 2);
+ append_opcode(GDScriptFunction::OPCODE_SET_NAMED);
append(p_target);
append(p_source);
append(p_name);
@@ -776,26 +776,26 @@ void GDScriptByteCodeGenerator::write_set_named(const Address &p_target, const S
void GDScriptByteCodeGenerator::write_get_named(const Address &p_target, const StringName &p_name, const Address &p_source) {
if (HAS_BUILTIN_TYPE(p_source) && Variant::get_member_validated_getter(p_source.type.builtin_type, p_name)) {
Variant::ValidatedGetter getter = Variant::get_member_validated_getter(p_source.type.builtin_type, p_name);
- append(GDScriptFunction::OPCODE_GET_NAMED_VALIDATED, 2);
+ append_opcode(GDScriptFunction::OPCODE_GET_NAMED_VALIDATED);
append(p_source);
append(p_target);
append(getter);
return;
}
- append(GDScriptFunction::OPCODE_GET_NAMED, 2);
+ append_opcode(GDScriptFunction::OPCODE_GET_NAMED);
append(p_source);
append(p_target);
append(p_name);
}
void GDScriptByteCodeGenerator::write_set_member(const Address &p_value, const StringName &p_name) {
- append(GDScriptFunction::OPCODE_SET_MEMBER, 1);
+ append_opcode(GDScriptFunction::OPCODE_SET_MEMBER);
append(p_value);
append(p_name);
}
void GDScriptByteCodeGenerator::write_get_member(const Address &p_target, const StringName &p_name) {
- append(GDScriptFunction::OPCODE_GET_MEMBER, 1);
+ append_opcode(GDScriptFunction::OPCODE_GET_MEMBER);
append(p_target);
append(p_name);
}
@@ -804,11 +804,11 @@ void GDScriptByteCodeGenerator::write_assign_with_conversion(const Address &p_ta
switch (p_target.type.kind) {
case GDScriptDataType::BUILTIN: {
if (p_target.type.builtin_type == Variant::ARRAY && p_target.type.has_container_element_type()) {
- append(GDScriptFunction::OPCODE_ASSIGN_TYPED_ARRAY, 2);
+ append_opcode(GDScriptFunction::OPCODE_ASSIGN_TYPED_ARRAY);
append(p_target);
append(p_source);
} else {
- append(GDScriptFunction::OPCODE_ASSIGN_TYPED_BUILTIN, 2);
+ append_opcode(GDScriptFunction::OPCODE_ASSIGN_TYPED_BUILTIN);
append(p_target);
append(p_source);
append(p_target.type.builtin_type);
@@ -818,7 +818,7 @@ void GDScriptByteCodeGenerator::write_assign_with_conversion(const Address &p_ta
int class_idx = GDScriptLanguage::get_singleton()->get_global_map()[p_target.type.native_type];
Variant nc = GDScriptLanguage::get_singleton()->get_global_array()[class_idx];
class_idx = get_constant_pos(nc) | (GDScriptFunction::ADDR_TYPE_CONSTANT << GDScriptFunction::ADDR_BITS);
- append(GDScriptFunction::OPCODE_ASSIGN_TYPED_NATIVE, 3);
+ append_opcode(GDScriptFunction::OPCODE_ASSIGN_TYPED_NATIVE);
append(p_target);
append(p_source);
append(class_idx);
@@ -828,7 +828,7 @@ void GDScriptByteCodeGenerator::write_assign_with_conversion(const Address &p_ta
Variant script = p_target.type.script_type;
int idx = get_constant_pos(script) | (GDScriptFunction::ADDR_TYPE_CONSTANT << GDScriptFunction::ADDR_BITS);
- append(GDScriptFunction::OPCODE_ASSIGN_TYPED_SCRIPT, 3);
+ append_opcode(GDScriptFunction::OPCODE_ASSIGN_TYPED_SCRIPT);
append(p_target);
append(p_source);
append(idx);
@@ -837,7 +837,7 @@ void GDScriptByteCodeGenerator::write_assign_with_conversion(const Address &p_ta
ERR_PRINT("Compiler bug: unresolved assign.");
// Shouldn't get here, but fail-safe to a regular assignment
- append(GDScriptFunction::OPCODE_ASSIGN, 2);
+ append_opcode(GDScriptFunction::OPCODE_ASSIGN);
append(p_target);
append(p_source);
}
@@ -846,29 +846,29 @@ void GDScriptByteCodeGenerator::write_assign_with_conversion(const Address &p_ta
void GDScriptByteCodeGenerator::write_assign(const Address &p_target, const Address &p_source) {
if (p_target.type.kind == GDScriptDataType::BUILTIN && p_target.type.builtin_type == Variant::ARRAY && p_target.type.has_container_element_type()) {
- append(GDScriptFunction::OPCODE_ASSIGN_TYPED_ARRAY, 2);
+ append_opcode(GDScriptFunction::OPCODE_ASSIGN_TYPED_ARRAY);
append(p_target);
append(p_source);
} else if (p_target.type.kind == GDScriptDataType::BUILTIN && p_source.type.kind == GDScriptDataType::BUILTIN && p_target.type.builtin_type != p_source.type.builtin_type) {
// Need conversion.
- append(GDScriptFunction::OPCODE_ASSIGN_TYPED_BUILTIN, 2);
+ append_opcode(GDScriptFunction::OPCODE_ASSIGN_TYPED_BUILTIN);
append(p_target);
append(p_source);
append(p_target.type.builtin_type);
} else {
- append(GDScriptFunction::OPCODE_ASSIGN, 2);
+ append_opcode(GDScriptFunction::OPCODE_ASSIGN);
append(p_target);
append(p_source);
}
}
void GDScriptByteCodeGenerator::write_assign_true(const Address &p_target) {
- append(GDScriptFunction::OPCODE_ASSIGN_TRUE, 1);
+ append_opcode(GDScriptFunction::OPCODE_ASSIGN_TRUE);
append(p_target);
}
void GDScriptByteCodeGenerator::write_assign_false(const Address &p_target) {
- append(GDScriptFunction::OPCODE_ASSIGN_FALSE, 1);
+ append_opcode(GDScriptFunction::OPCODE_ASSIGN_FALSE);
append(p_target);
}
@@ -878,13 +878,13 @@ void GDScriptByteCodeGenerator::write_assign_default_parameter(const Address &p_
}
void GDScriptByteCodeGenerator::write_store_global(const Address &p_dst, int p_global_index) {
- append(GDScriptFunction::OPCODE_STORE_GLOBAL, 1);
+ append_opcode(GDScriptFunction::OPCODE_STORE_GLOBAL);
append(p_dst);
append(p_global_index);
}
void GDScriptByteCodeGenerator::write_store_named_global(const Address &p_dst, const StringName &p_global) {
- append(GDScriptFunction::OPCODE_STORE_NAMED_GLOBAL, 1);
+ append_opcode(GDScriptFunction::OPCODE_STORE_NAMED_GLOBAL);
append(p_dst);
append(p_global);
}
@@ -894,20 +894,20 @@ void GDScriptByteCodeGenerator::write_cast(const Address &p_target, const Addres
switch (p_type.kind) {
case GDScriptDataType::BUILTIN: {
- append(GDScriptFunction::OPCODE_CAST_TO_BUILTIN, 2);
+ append_opcode(GDScriptFunction::OPCODE_CAST_TO_BUILTIN);
index = p_type.builtin_type;
} break;
case GDScriptDataType::NATIVE: {
int class_idx = GDScriptLanguage::get_singleton()->get_global_map()[p_type.native_type];
Variant nc = GDScriptLanguage::get_singleton()->get_global_array()[class_idx];
- append(GDScriptFunction::OPCODE_CAST_TO_NATIVE, 3);
+ append_opcode(GDScriptFunction::OPCODE_CAST_TO_NATIVE);
index = get_constant_pos(nc) | (GDScriptFunction::ADDR_TYPE_CONSTANT << GDScriptFunction::ADDR_BITS);
} break;
case GDScriptDataType::SCRIPT:
case GDScriptDataType::GDSCRIPT: {
Variant script = p_type.script_type;
int idx = get_constant_pos(script) | (GDScriptFunction::ADDR_TYPE_CONSTANT << GDScriptFunction::ADDR_BITS);
- append(GDScriptFunction::OPCODE_CAST_TO_SCRIPT, 3);
+ append_opcode(GDScriptFunction::OPCODE_CAST_TO_SCRIPT);
index = idx;
} break;
default: {
@@ -921,7 +921,7 @@ void GDScriptByteCodeGenerator::write_cast(const Address &p_target, const Addres
}
void GDScriptByteCodeGenerator::write_call(const Address &p_target, const Address &p_base, const StringName &p_function_name, const Vector<Address> &p_arguments) {
- append(p_target.mode == Address::NIL ? GDScriptFunction::OPCODE_CALL : GDScriptFunction::OPCODE_CALL_RETURN, 2 + p_arguments.size());
+ 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]);
}
@@ -932,7 +932,7 @@ void GDScriptByteCodeGenerator::write_call(const Address &p_target, const Addres
}
void GDScriptByteCodeGenerator::write_super_call(const Address &p_target, const StringName &p_function_name, const Vector<Address> &p_arguments) {
- append(GDScriptFunction::OPCODE_CALL_SELF_BASE, 1 + p_arguments.size());
+ append_opcode_and_argcount(GDScriptFunction::OPCODE_CALL_SELF_BASE, 1 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
@@ -942,7 +942,7 @@ void GDScriptByteCodeGenerator::write_super_call(const Address &p_target, const
}
void GDScriptByteCodeGenerator::write_call_async(const Address &p_target, const Address &p_base, const StringName &p_function_name, const Vector<Address> &p_arguments) {
- append(GDScriptFunction::OPCODE_CALL_ASYNC, 2 + p_arguments.size());
+ append_opcode_and_argcount(GDScriptFunction::OPCODE_CALL_ASYNC, 2 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
@@ -953,7 +953,7 @@ void GDScriptByteCodeGenerator::write_call_async(const Address &p_target, const
}
void GDScriptByteCodeGenerator::write_call_gdscript_utility(const Address &p_target, GDScriptUtilityFunctions::FunctionPtr p_function, const Vector<Address> &p_arguments) {
- append(GDScriptFunction::OPCODE_CALL_GDSCRIPT_UTILITY, 1 + p_arguments.size());
+ append_opcode_and_argcount(GDScriptFunction::OPCODE_CALL_GDSCRIPT_UTILITY, 1 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
@@ -979,7 +979,7 @@ void GDScriptByteCodeGenerator::write_call_utility(const Address &p_target, cons
}
if (is_validated) {
- append(GDScriptFunction::OPCODE_CALL_UTILITY_VALIDATED, 1 + p_arguments.size());
+ append_opcode_and_argcount(GDScriptFunction::OPCODE_CALL_UTILITY_VALIDATED, 1 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
@@ -987,7 +987,7 @@ void GDScriptByteCodeGenerator::write_call_utility(const Address &p_target, cons
append(p_arguments.size());
append(Variant::get_validated_utility_function(p_function));
} else {
- append(GDScriptFunction::OPCODE_CALL_UTILITY, 1 + p_arguments.size());
+ append_opcode_and_argcount(GDScriptFunction::OPCODE_CALL_UTILITY, 1 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
@@ -1029,7 +1029,7 @@ void GDScriptByteCodeGenerator::write_call_builtin_type(const Address &p_target,
}
}
- append(GDScriptFunction::OPCODE_CALL_BUILTIN_TYPE_VALIDATED, 2 + p_arguments.size());
+ append_opcode_and_argcount(GDScriptFunction::OPCODE_CALL_BUILTIN_TYPE_VALIDATED, 2 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
@@ -1060,7 +1060,7 @@ void GDScriptByteCodeGenerator::write_call_builtin_type_static(const Address &p_
if (!is_validated) {
// Perform regular call.
- append(GDScriptFunction::OPCODE_CALL_BUILTIN_STATIC, p_arguments.size() + 1);
+ append_opcode_and_argcount(GDScriptFunction::OPCODE_CALL_BUILTIN_STATIC, p_arguments.size() + 1);
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
@@ -1079,7 +1079,7 @@ void GDScriptByteCodeGenerator::write_call_builtin_type_static(const Address &p_
}
}
- append(GDScriptFunction::OPCODE_CALL_BUILTIN_TYPE_VALIDATED, 2 + p_arguments.size());
+ append_opcode_and_argcount(GDScriptFunction::OPCODE_CALL_BUILTIN_TYPE_VALIDATED, 2 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
@@ -1097,7 +1097,7 @@ void GDScriptByteCodeGenerator::write_call_native_static(const Address &p_target
if (!is_validated) {
// Perform regular call.
- append(GDScriptFunction::OPCODE_CALL_NATIVE_STATIC, p_arguments.size() + 1);
+ append_opcode_and_argcount(GDScriptFunction::OPCODE_CALL_NATIVE_STATIC, p_arguments.size() + 1);
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
@@ -1109,7 +1109,7 @@ void GDScriptByteCodeGenerator::write_call_native_static(const Address &p_target
}
void GDScriptByteCodeGenerator::write_call_method_bind(const Address &p_target, const Address &p_base, MethodBind *p_method, const Vector<Address> &p_arguments) {
- append(p_target.mode == Address::NIL ? GDScriptFunction::OPCODE_CALL_METHOD_BIND : GDScriptFunction::OPCODE_CALL_METHOD_BIND_RET, 2 + p_arguments.size());
+ append_opcode_and_argcount(p_target.mode == Address::NIL ? GDScriptFunction::OPCODE_CALL_METHOD_BIND : GDScriptFunction::OPCODE_CALL_METHOD_BIND_RET, 2 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
@@ -1120,9 +1120,9 @@ void GDScriptByteCodeGenerator::write_call_method_bind(const Address &p_target,
}
void GDScriptByteCodeGenerator::write_call_ptrcall(const Address &p_target, const Address &p_base, MethodBind *p_method, const Vector<Address> &p_arguments) {
-#define CASE_TYPE(m_type) \
- case Variant::m_type: \
- append(GDScriptFunction::OPCODE_CALL_PTRCALL_##m_type, 2 + p_arguments.size()); \
+#define CASE_TYPE(m_type) \
+ case Variant::m_type: \
+ append_opcode_and_argcount(GDScriptFunction::OPCODE_CALL_PTRCALL_##m_type, 2 + p_arguments.size()); \
break
bool is_ptrcall = true;
@@ -1166,12 +1166,12 @@ void GDScriptByteCodeGenerator::write_call_ptrcall(const Address &p_target, cons
CASE_TYPE(PACKED_VECTOR3_ARRAY);
CASE_TYPE(PACKED_COLOR_ARRAY);
default:
- append(p_target.mode == Address::NIL ? GDScriptFunction::OPCODE_CALL_METHOD_BIND : GDScriptFunction::OPCODE_CALL_METHOD_BIND_RET, 2 + p_arguments.size());
+ append_opcode_and_argcount(p_target.mode == Address::NIL ? GDScriptFunction::OPCODE_CALL_METHOD_BIND : GDScriptFunction::OPCODE_CALL_METHOD_BIND_RET, 2 + p_arguments.size());
is_ptrcall = false;
break;
}
} else {
- append(GDScriptFunction::OPCODE_CALL_PTRCALL_NO_RETURN, 2 + p_arguments.size());
+ append_opcode_and_argcount(GDScriptFunction::OPCODE_CALL_PTRCALL_NO_RETURN, 2 + p_arguments.size());
}
for (int i = 0; i < p_arguments.size(); i++) {
@@ -1189,7 +1189,7 @@ void GDScriptByteCodeGenerator::write_call_ptrcall(const Address &p_target, cons
}
void GDScriptByteCodeGenerator::write_call_self(const Address &p_target, const StringName &p_function_name, const Vector<Address> &p_arguments) {
- append(p_target.mode == Address::NIL ? GDScriptFunction::OPCODE_CALL : GDScriptFunction::OPCODE_CALL_RETURN, 2 + p_arguments.size());
+ 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]);
}
@@ -1200,7 +1200,7 @@ void GDScriptByteCodeGenerator::write_call_self(const Address &p_target, const S
}
void GDScriptByteCodeGenerator::write_call_self_async(const Address &p_target, const StringName &p_function_name, const Vector<Address> &p_arguments) {
- append(GDScriptFunction::OPCODE_CALL_ASYNC, 2 + p_arguments.size());
+ append_opcode_and_argcount(GDScriptFunction::OPCODE_CALL_ASYNC, 2 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
@@ -1211,7 +1211,7 @@ void GDScriptByteCodeGenerator::write_call_self_async(const Address &p_target, c
}
void GDScriptByteCodeGenerator::write_call_script_function(const Address &p_target, const Address &p_base, const StringName &p_function_name, const Vector<Address> &p_arguments) {
- append(p_target.mode == Address::NIL ? GDScriptFunction::OPCODE_CALL : GDScriptFunction::OPCODE_CALL_RETURN, 2 + p_arguments.size());
+ 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]);
}
@@ -1222,7 +1222,7 @@ void GDScriptByteCodeGenerator::write_call_script_function(const Address &p_targ
}
void GDScriptByteCodeGenerator::write_lambda(const Address &p_target, GDScriptFunction *p_function, const Vector<Address> &p_captures, bool p_use_self) {
- append(p_use_self ? GDScriptFunction::OPCODE_CREATE_SELF_LAMBDA : GDScriptFunction::OPCODE_CREATE_LAMBDA, 1 + p_captures.size());
+ append_opcode_and_argcount(p_use_self ? GDScriptFunction::OPCODE_CREATE_SELF_LAMBDA : GDScriptFunction::OPCODE_CREATE_LAMBDA, 1 + p_captures.size());
for (int i = 0; i < p_captures.size(); i++) {
append(p_captures[i]);
}
@@ -1262,7 +1262,7 @@ void GDScriptByteCodeGenerator::write_construct(const Address &p_target, Variant
}
}
if (valid_constructor >= 0) {
- append(GDScriptFunction::OPCODE_CONSTRUCT_VALIDATED, 1 + p_arguments.size());
+ append_opcode_and_argcount(GDScriptFunction::OPCODE_CONSTRUCT_VALIDATED, 1 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
@@ -1273,7 +1273,7 @@ void GDScriptByteCodeGenerator::write_construct(const Address &p_target, Variant
}
}
- append(GDScriptFunction::OPCODE_CONSTRUCT, 1 + p_arguments.size());
+ append_opcode_and_argcount(GDScriptFunction::OPCODE_CONSTRUCT, 1 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
@@ -1283,7 +1283,7 @@ void GDScriptByteCodeGenerator::write_construct(const Address &p_target, Variant
}
void GDScriptByteCodeGenerator::write_construct_array(const Address &p_target, const Vector<Address> &p_arguments) {
- append(GDScriptFunction::OPCODE_CONSTRUCT_ARRAY, 1 + p_arguments.size());
+ append_opcode_and_argcount(GDScriptFunction::OPCODE_CONSTRUCT_ARRAY, 1 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
@@ -1292,7 +1292,7 @@ void GDScriptByteCodeGenerator::write_construct_array(const Address &p_target, c
}
void GDScriptByteCodeGenerator::write_construct_typed_array(const Address &p_target, const GDScriptDataType &p_element_type, const Vector<Address> &p_arguments) {
- append(GDScriptFunction::OPCODE_CONSTRUCT_TYPED_ARRAY, 2 + p_arguments.size());
+ append_opcode_and_argcount(GDScriptFunction::OPCODE_CONSTRUCT_TYPED_ARRAY, 2 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
@@ -1311,7 +1311,7 @@ void GDScriptByteCodeGenerator::write_construct_typed_array(const Address &p_tar
}
void GDScriptByteCodeGenerator::write_construct_dictionary(const Address &p_target, const Vector<Address> &p_arguments) {
- append(GDScriptFunction::OPCODE_CONSTRUCT_DICTIONARY, 1 + p_arguments.size());
+ append_opcode_and_argcount(GDScriptFunction::OPCODE_CONSTRUCT_DICTIONARY, 1 + p_arguments.size());
for (int i = 0; i < p_arguments.size(); i++) {
append(p_arguments[i]);
}
@@ -1320,21 +1320,21 @@ void GDScriptByteCodeGenerator::write_construct_dictionary(const Address &p_targ
}
void GDScriptByteCodeGenerator::write_await(const Address &p_target, const Address &p_operand) {
- append(GDScriptFunction::OPCODE_AWAIT, 1);
+ append_opcode(GDScriptFunction::OPCODE_AWAIT);
append(p_operand);
- append(GDScriptFunction::OPCODE_AWAIT_RESUME, 1);
+ append_opcode(GDScriptFunction::OPCODE_AWAIT_RESUME);
append(p_target);
}
void GDScriptByteCodeGenerator::write_if(const Address &p_condition) {
- append(GDScriptFunction::OPCODE_JUMP_IF_NOT, 1);
+ append_opcode(GDScriptFunction::OPCODE_JUMP_IF_NOT);
append(p_condition);
if_jmp_addrs.push_back(opcodes.size());
append(0); // Jump destination, will be patched.
}
void GDScriptByteCodeGenerator::write_else() {
- append(GDScriptFunction::OPCODE_JUMP, 0); // Jump from true if block;
+ append_opcode(GDScriptFunction::OPCODE_JUMP); // Jump from true if block;
int else_jmp_addr = opcodes.size();
append(0); // Jump destination, will be patched.
@@ -1349,7 +1349,7 @@ void GDScriptByteCodeGenerator::write_endif() {
}
void GDScriptByteCodeGenerator::write_jump_if_shared(const Address &p_value) {
- append(GDScriptFunction::OPCODE_JUMP_IF_SHARED, 1);
+ append_opcode(GDScriptFunction::OPCODE_JUMP_IF_SHARED);
append(p_value);
if_jmp_addrs.push_back(opcodes.size());
append(0); // Jump destination, will be patched.
@@ -1373,7 +1373,7 @@ void GDScriptByteCodeGenerator::write_for_assignment(const Address &p_variable,
const Address &container = for_container_variables.back()->get();
// Assign container.
- append(GDScriptFunction::OPCODE_ASSIGN, 2);
+ append_opcode(GDScriptFunction::OPCODE_ASSIGN);
append(container);
append(p_list);
@@ -1475,19 +1475,19 @@ void GDScriptByteCodeGenerator::write_for() {
}
// Begin loop.
- append(begin_opcode, 3);
+ append_opcode(begin_opcode);
append(counter);
append(container);
append(iterator);
for_jmp_addrs.push_back(opcodes.size());
append(0); // End of loop address, will be patched.
- append(GDScriptFunction::OPCODE_JUMP, 0);
+ append_opcode(GDScriptFunction::OPCODE_JUMP);
append(opcodes.size() + 6); // Skip over 'continue' code.
// Next iteration.
int continue_addr = opcodes.size();
continue_addrs.push_back(continue_addr);
- append(iterate_opcode, 3);
+ append_opcode(iterate_opcode);
append(counter);
append(container);
append(iterator);
@@ -1497,7 +1497,7 @@ void GDScriptByteCodeGenerator::write_for() {
void GDScriptByteCodeGenerator::write_endfor() {
// Jump back to loop check.
- append(GDScriptFunction::OPCODE_JUMP, 0);
+ append_opcode(GDScriptFunction::OPCODE_JUMP);
append(continue_addrs.back()->get());
continue_addrs.pop_back();
@@ -1526,7 +1526,7 @@ void GDScriptByteCodeGenerator::start_while_condition() {
void GDScriptByteCodeGenerator::write_while(const Address &p_condition) {
// Condition check.
- append(GDScriptFunction::OPCODE_JUMP_IF_NOT, 1);
+ append_opcode(GDScriptFunction::OPCODE_JUMP_IF_NOT);
append(p_condition);
while_jmp_addrs.push_back(opcodes.size());
append(0); // End of loop address, will be patched.
@@ -1534,7 +1534,7 @@ void GDScriptByteCodeGenerator::write_while(const Address &p_condition) {
void GDScriptByteCodeGenerator::write_endwhile() {
// Jump back to loop check.
- append(GDScriptFunction::OPCODE_JUMP, 0);
+ append_opcode(GDScriptFunction::OPCODE_JUMP);
append(continue_addrs.back()->get());
continue_addrs.pop_back();
@@ -1572,28 +1572,28 @@ void GDScriptByteCodeGenerator::end_match() {
}
void GDScriptByteCodeGenerator::write_break() {
- append(GDScriptFunction::OPCODE_JUMP, 0);
+ append_opcode(GDScriptFunction::OPCODE_JUMP);
current_breaks_to_patch.back()->get().push_back(opcodes.size());
append(0);
}
void GDScriptByteCodeGenerator::write_continue() {
- append(GDScriptFunction::OPCODE_JUMP, 0);
+ append_opcode(GDScriptFunction::OPCODE_JUMP);
append(continue_addrs.back()->get());
}
void GDScriptByteCodeGenerator::write_continue_match() {
- append(GDScriptFunction::OPCODE_JUMP, 0);
+ append_opcode(GDScriptFunction::OPCODE_JUMP);
match_continues_to_patch.back()->get().push_back(opcodes.size());
append(0);
}
void GDScriptByteCodeGenerator::write_breakpoint() {
- append(GDScriptFunction::OPCODE_BREAKPOINT, 0);
+ append_opcode(GDScriptFunction::OPCODE_BREAKPOINT);
}
void GDScriptByteCodeGenerator::write_newline(int p_line) {
- append(GDScriptFunction::OPCODE_LINE, 0);
+ append_opcode(GDScriptFunction::OPCODE_LINE);
append(p_line);
current_line = p_line;
}
@@ -1611,23 +1611,23 @@ void GDScriptByteCodeGenerator::write_return(const Address &p_return_value) {
Variant script = element_type.script_type;
int script_idx = get_constant_pos(script) | (GDScriptFunction::ADDR_TYPE_CONSTANT << GDScriptFunction::ADDR_BITS);
- append(GDScriptFunction::OPCODE_RETURN_TYPED_ARRAY, 2);
+ append_opcode(GDScriptFunction::OPCODE_RETURN_TYPED_ARRAY);
append(p_return_value);
append(script_idx);
append(element_type.kind == GDScriptDataType::BUILTIN ? element_type.builtin_type : Variant::OBJECT);
append(element_type.native_type);
} else if (function->return_type.kind == GDScriptDataType::BUILTIN && p_return_value.type.kind == GDScriptDataType::BUILTIN && function->return_type.builtin_type != p_return_value.type.builtin_type) {
// Add conversion.
- append(GDScriptFunction::OPCODE_RETURN_TYPED_BUILTIN, 1);
+ append_opcode(GDScriptFunction::OPCODE_RETURN_TYPED_BUILTIN);
append(p_return_value);
append(function->return_type.builtin_type);
} else {
// Just assign.
- append(GDScriptFunction::OPCODE_RETURN, 1);
+ append_opcode(GDScriptFunction::OPCODE_RETURN);
append(p_return_value);
}
} else {
- append(GDScriptFunction::OPCODE_RETURN, 1);
+ append_opcode(GDScriptFunction::OPCODE_RETURN);
append(p_return_value);
}
} else {
@@ -1640,19 +1640,19 @@ void GDScriptByteCodeGenerator::write_return(const Address &p_return_value) {
int script_idx = get_constant_pos(script);
script_idx |= (GDScriptFunction::ADDR_TYPE_CONSTANT << GDScriptFunction::ADDR_BITS);
- append(GDScriptFunction::OPCODE_RETURN_TYPED_ARRAY, 2);
+ append_opcode(GDScriptFunction::OPCODE_RETURN_TYPED_ARRAY);
append(p_return_value);
append(script_idx);
append(element_type.kind == GDScriptDataType::BUILTIN ? element_type.builtin_type : Variant::OBJECT);
append(element_type.native_type);
} else {
- append(GDScriptFunction::OPCODE_RETURN_TYPED_BUILTIN, 1);
+ append_opcode(GDScriptFunction::OPCODE_RETURN_TYPED_BUILTIN);
append(p_return_value);
append(function->return_type.builtin_type);
}
} break;
case GDScriptDataType::NATIVE: {
- append(GDScriptFunction::OPCODE_RETURN_TYPED_NATIVE, 2);
+ append_opcode(GDScriptFunction::OPCODE_RETURN_TYPED_NATIVE);
append(p_return_value);
int class_idx = GDScriptLanguage::get_singleton()->get_global_map()[function->return_type.native_type];
Variant nc = GDScriptLanguage::get_singleton()->get_global_array()[class_idx];
@@ -1664,7 +1664,7 @@ void GDScriptByteCodeGenerator::write_return(const Address &p_return_value) {
Variant script = function->return_type.script_type;
int script_idx = get_constant_pos(script) | (GDScriptFunction::ADDR_TYPE_CONSTANT << GDScriptFunction::ADDR_BITS);
- append(GDScriptFunction::OPCODE_RETURN_TYPED_SCRIPT, 2);
+ append_opcode(GDScriptFunction::OPCODE_RETURN_TYPED_SCRIPT);
append(p_return_value);
append(script_idx);
} break;
@@ -1672,7 +1672,7 @@ void GDScriptByteCodeGenerator::write_return(const Address &p_return_value) {
ERR_PRINT("Compiler bug: unresolved return.");
// Shouldn't get here, but fail-safe to a regular return;
- append(GDScriptFunction::OPCODE_RETURN, 1);
+ append_opcode(GDScriptFunction::OPCODE_RETURN);
append(p_return_value);
} break;
}
@@ -1680,7 +1680,7 @@ void GDScriptByteCodeGenerator::write_return(const Address &p_return_value) {
}
void GDScriptByteCodeGenerator::write_assert(const Address &p_test, const Address &p_message) {
- append(GDScriptFunction::OPCODE_ASSERT, 2);
+ append_opcode(GDScriptFunction::OPCODE_ASSERT);
append(p_test);
append(p_message);
}
diff --git a/modules/gdscript/gdscript_byte_codegen.h b/modules/gdscript/gdscript_byte_codegen.h
index 7dd51845df..87772824f6 100644
--- a/modules/gdscript/gdscript_byte_codegen.h
+++ b/modules/gdscript/gdscript_byte_codegen.h
@@ -331,8 +331,13 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator {
return -1; // Unreachable.
}
- void append(GDScriptFunction::Opcode p_code, int p_argument_count) {
- opcodes.push_back((p_code & GDScriptFunction::INSTR_MASK) | (p_argument_count << GDScriptFunction::INSTR_BITS));
+ void append_opcode(GDScriptFunction::Opcode p_code) {
+ opcodes.push_back(p_code);
+ }
+
+ void append_opcode_and_argcount(GDScriptFunction::Opcode p_code, int p_argument_count) {
+ opcodes.push_back(p_code);
+ opcodes.push_back(p_argument_count);
instr_args_max = MAX(instr_args_max, p_argument_count);
}
diff --git a/modules/gdscript/gdscript_disassembler.cpp b/modules/gdscript/gdscript_disassembler.cpp
index b5a209c805..5881adcd5b 100644
--- a/modules/gdscript/gdscript_disassembler.cpp
+++ b/modules/gdscript/gdscript_disassembler.cpp
@@ -104,8 +104,7 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
text += ": ";
// This makes the compiler complain if some opcode is unchecked in the switch.
- Opcode opcode = Opcode(_code_ptr[ip] & INSTR_MASK);
- int instr_var_args = (_code_ptr[ip] & INSTR_ARGS_MASK) >> INSTR_BITS;
+ Opcode opcode = Opcode(_code_ptr[ip]);
switch (opcode) {
case OPCODE_OPERATOR: {
@@ -372,6 +371,7 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
incr += 4;
} break;
case OPCODE_CONSTRUCT: {
+ int instr_var_args = _code_ptr[++ip];
Variant::Type t = Variant::Type(_code_ptr[ip + 3 + instr_var_args]);
int argc = _code_ptr[ip + 1 + instr_var_args];
@@ -391,6 +391,7 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
incr = 3 + instr_var_args;
} break;
case OPCODE_CONSTRUCT_VALIDATED: {
+ int instr_var_args = _code_ptr[++ip];
int argc = _code_ptr[ip + 1 + instr_var_args];
text += "construct validated ";
@@ -409,6 +410,7 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
incr = 3 + instr_var_args;
} break;
case OPCODE_CONSTRUCT_ARRAY: {
+ int instr_var_args = _code_ptr[++ip];
int argc = _code_ptr[ip + 1 + instr_var_args];
text += " make_array ";
text += DADDR(1 + argc);
@@ -426,6 +428,7 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
incr += 3 + argc;
} break;
case OPCODE_CONSTRUCT_TYPED_ARRAY: {
+ int instr_var_args = _code_ptr[++ip];
int argc = _code_ptr[ip + 1 + instr_var_args];
Ref<Script> script_type = get_constant(_code_ptr[ip + argc + 2]);
@@ -460,6 +463,7 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
incr += 3 + argc;
} break;
case OPCODE_CONSTRUCT_DICTIONARY: {
+ int instr_var_args = _code_ptr[++ip];
int argc = _code_ptr[ip + 1 + instr_var_args];
text += "make_dict ";
text += DADDR(1 + argc * 2);
@@ -481,8 +485,10 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
case OPCODE_CALL:
case OPCODE_CALL_RETURN:
case OPCODE_CALL_ASYNC: {
- bool ret = (_code_ptr[ip] & INSTR_MASK) == OPCODE_CALL_RETURN;
- bool async = (_code_ptr[ip] & INSTR_MASK) == OPCODE_CALL_ASYNC;
+ bool ret = (_code_ptr[ip]) == OPCODE_CALL_RETURN;
+ bool async = (_code_ptr[ip]) == OPCODE_CALL_ASYNC;
+
+ int instr_var_args = _code_ptr[++ip];
if (ret) {
text += "call-ret ";
@@ -513,7 +519,8 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
} break;
case OPCODE_CALL_METHOD_BIND:
case OPCODE_CALL_METHOD_BIND_RET: {
- bool ret = (_code_ptr[ip] & INSTR_MASK) == OPCODE_CALL_METHOD_BIND_RET;
+ bool ret = (_code_ptr[ip]) == OPCODE_CALL_METHOD_BIND_RET;
+ int instr_var_args = _code_ptr[++ip];
if (ret) {
text += "call-method_bind-ret ";
@@ -543,6 +550,7 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
incr = 5 + argc;
} break;
case OPCODE_CALL_BUILTIN_STATIC: {
+ int instr_var_args = _code_ptr[++ip];
Variant::Type type = (Variant::Type)_code_ptr[ip + 1 + instr_var_args];
int argc = _code_ptr[ip + 3 + instr_var_args];
@@ -565,6 +573,7 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
incr += 5 + argc;
} break;
case OPCODE_CALL_NATIVE_STATIC: {
+ int instr_var_args = _code_ptr[++ip];
MethodBind *method = _methods_ptr[_code_ptr[ip + 1 + instr_var_args]];
int argc = _code_ptr[ip + 2 + instr_var_args];
@@ -587,6 +596,8 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
incr += 4 + argc;
} break;
case OPCODE_CALL_PTRCALL_NO_RETURN: {
+ int instr_var_args = _code_ptr[++ip];
+
text += "call-ptrcall (no return) ";
MethodBind *method = _methods_ptr[_code_ptr[ip + 2 + instr_var_args]];
@@ -610,6 +621,7 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
#define DISASSEMBLE_PTRCALL(m_type) \
case OPCODE_CALL_PTRCALL_##m_type: { \
+ int instr_var_args = _code_ptr[++ip]; \
text += "call-ptrcall (return "; \
text += #m_type; \
text += ") "; \
@@ -667,6 +679,7 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
DISASSEMBLE_PTRCALL(PACKED_COLOR_ARRAY);
case OPCODE_CALL_BUILTIN_TYPE_VALIDATED: {
+ int instr_var_args = _code_ptr[++ip];
int argc = _code_ptr[ip + 1 + instr_var_args];
text += "call-builtin-method validated ";
@@ -689,6 +702,8 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
incr = 5 + argc;
} break;
case OPCODE_CALL_UTILITY: {
+ int instr_var_args = _code_ptr[++ip];
+
text += "call-utility ";
int argc = _code_ptr[ip + 1 + instr_var_args];
@@ -708,6 +723,8 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
incr = 4 + argc;
} break;
case OPCODE_CALL_UTILITY_VALIDATED: {
+ int instr_var_args = _code_ptr[++ip];
+
text += "call-utility ";
int argc = _code_ptr[ip + 1 + instr_var_args];
@@ -727,6 +744,8 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
incr = 4 + argc;
} break;
case OPCODE_CALL_GDSCRIPT_UTILITY: {
+ int instr_var_args = _code_ptr[++ip];
+
text += "call-gscript-utility ";
int argc = _code_ptr[ip + 1 + instr_var_args];
@@ -746,6 +765,8 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
incr = 4 + argc;
} break;
case OPCODE_CALL_SELF_BASE: {
+ int instr_var_args = _code_ptr[++ip];
+
text += "call-self-base ";
int argc = _code_ptr[ip + 1 + instr_var_args];
@@ -777,6 +798,7 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
incr = 2;
} break;
case OPCODE_CREATE_LAMBDA: {
+ int instr_var_args = _code_ptr[++ip];
int captures_count = _code_ptr[ip + 1 + instr_var_args];
GDScriptFunction *lambda = _lambdas_ptr[_code_ptr[ip + 2 + instr_var_args]];
@@ -796,6 +818,7 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
incr = 3 + captures_count;
} break;
case OPCODE_CREATE_SELF_LAMBDA: {
+ int instr_var_args = _code_ptr[++ip];
int captures_count = _code_ptr[ip + 1 + instr_var_args];
GDScriptFunction *lambda = _lambdas_ptr[_code_ptr[ip + 2 + instr_var_args]];
diff --git a/modules/gdscript/gdscript_function.h b/modules/gdscript/gdscript_function.h
index 6e5f7a8520..25f771d698 100644
--- a/modules/gdscript/gdscript_function.h
+++ b/modules/gdscript/gdscript_function.h
@@ -405,6 +405,7 @@ public:
ADDR_TYPE_STACK = 0,
ADDR_TYPE_CONSTANT = 1,
ADDR_TYPE_MEMBER = 2,
+ ADDR_TYPE_MAX = 3,
};
enum FixedAddresses {
@@ -416,12 +417,6 @@ public:
ADDR_NIL = ADDR_STACK_NIL | (ADDR_TYPE_STACK << ADDR_BITS),
};
- enum Instruction {
- INSTR_BITS = 20,
- INSTR_MASK = ((1 << INSTR_BITS) - 1),
- INSTR_ARGS_MASK = ~INSTR_MASK,
- };
-
struct StackDebug {
int line;
int pos;
@@ -514,7 +509,6 @@ private:
Variant _get_default_variant_for_data_type(const GDScriptDataType &p_data_type);
- _FORCE_INLINE_ Variant *_get_variant(int p_address, GDScriptInstance *p_instance, Variant *p_stack, String &r_error) const;
_FORCE_INLINE_ String _get_call_error(const Callable::CallError &p_err, const String &p_where, const Variant **argptrs) const;
friend class GDScriptLanguage;
diff --git a/modules/gdscript/gdscript_vm.cpp b/modules/gdscript/gdscript_vm.cpp
index fdcc0625d7..c8dcb531fa 100644
--- a/modules/gdscript/gdscript_vm.cpp
+++ b/modules/gdscript/gdscript_vm.cpp
@@ -35,39 +35,6 @@
#include "gdscript.h"
#include "gdscript_lambda_callable.h"
-Variant *GDScriptFunction::_get_variant(int p_address, GDScriptInstance *p_instance, Variant *p_stack, String &r_error) const {
- int address = p_address & ADDR_MASK;
-
- //sequential table (jump table generated by compiler)
- switch ((p_address & ADDR_TYPE_MASK) >> ADDR_BITS) {
- case ADDR_TYPE_STACK: {
-#ifdef DEBUG_ENABLED
- ERR_FAIL_INDEX_V(address, _stack_size, nullptr);
-#endif
- return &p_stack[address];
- } break;
- case ADDR_TYPE_CONSTANT: {
-#ifdef DEBUG_ENABLED
- ERR_FAIL_INDEX_V(address, _constant_count, nullptr);
-#endif
- return &_constants_ptr[address];
- } break;
- case ADDR_TYPE_MEMBER: {
-#ifdef DEBUG_ENABLED
- if (unlikely(!p_instance)) {
- r_error = "Cannot access member without instance.";
- return nullptr;
- }
-#endif
- //member indexing is O(1)
- return &p_instance->members.write[address];
- } break;
- }
-
- ERR_FAIL_V_MSG(nullptr, "Bad code! (unknown addressing mode).");
- return nullptr;
-}
-
#ifdef DEBUG_ENABLED
static String _get_script_name(const Ref<Script> p_script) {
Ref<GDScript> gdscript = p_script;
@@ -413,14 +380,19 @@ void (*type_init_function_table[])(Variant *) = {
#define OPCODE(m_op) \
m_op:
-#define OPCODE_WHILE(m_test) \
- OPSWHILE:
+#define OPCODE_WHILE(m_test)
#define OPCODES_END \
OPSEXIT:
#define OPCODES_OUT \
OPSOUT:
-#define DISPATCH_OPCODE goto OPSWHILE
#define OPCODE_SWITCH(m_test) goto *switch_table_ops[m_test];
+#ifdef DEBUG_ENABLED
+#define DISPATCH_OPCODE \
+ last_opcode = _code_ptr[ip]; \
+ goto *switch_table_ops[last_opcode]
+#else
+#define DISPATCH_OPCODE goto *switch_table_ops[_code_ptr[ip]]
+#endif
#define OPCODE_BREAK goto OPSEXIT
#define OPCODE_OUT goto OPSOUT
#else
@@ -607,21 +579,52 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
#define CHECK_SPACE(m_space) \
GD_ERR_BREAK((ip + m_space) > _code_size)
-#define GET_VARIANT_PTR(m_v, m_code_ofs) \
- Variant *m_v; \
- m_v = _get_variant(_code_ptr[ip + m_code_ofs], p_instance, stack, err_text); \
- if (unlikely(!m_v)) \
- OPCODE_BREAK;
+#define GET_VARIANT_PTR(m_v, m_code_ofs) \
+ Variant *m_v; \
+ { \
+ int address = _code_ptr[ip + 1 + (m_code_ofs)]; \
+ int address_type = (address & ADDR_TYPE_MASK) >> ADDR_BITS; \
+ if (unlikely(address_type < 0 || address_type >= ADDR_TYPE_MAX)) { \
+ err_text = "Bad address type."; \
+ OPCODE_BREAK; \
+ } \
+ int address_index = address & ADDR_MASK; \
+ if (unlikely(address_index < 0 || address_index >= variant_address_limits[address_type])) { \
+ if (address_type == ADDR_TYPE_MEMBER && !p_instance) { \
+ err_text = "Cannot access member without instance."; \
+ } else { \
+ err_text = "Bad address index."; \
+ } \
+ OPCODE_BREAK; \
+ } \
+ m_v = &variant_addresses[address_type][address_index]; \
+ if (unlikely(!m_v)) \
+ OPCODE_BREAK; \
+ }
#else
#define GD_ERR_BREAK(m_cond)
#define CHECK_SPACE(m_space)
-#define GET_VARIANT_PTR(m_v, m_code_ofs) \
- Variant *m_v; \
- m_v = _get_variant(_code_ptr[ip + m_code_ofs], p_instance, stack, err_text);
+
+#define GET_VARIANT_PTR(m_v, m_code_ofs) \
+ Variant *m_v; \
+ { \
+ int address = _code_ptr[ip + 1 + (m_code_ofs)]; \
+ m_v = &variant_addresses[(address & ADDR_TYPE_MASK) >> ADDR_BITS][address & ADDR_MASK]; \
+ if (unlikely(!m_v)) \
+ OPCODE_BREAK; \
+ }
#endif
+#define LOAD_INSTRUCTION_ARGS \
+ int instr_arg_count = _code_ptr[ip + 1]; \
+ for (int i = 0; i < instr_arg_count; i++) { \
+ GET_VARIANT_PTR(v, i + 1); \
+ instruction_args[i] = v; \
+ } \
+ ip += 1; // Offset to skip instruction argcount.
+
#define GET_INSTRUCTION_ARG(m_v, m_idx) \
Variant *m_v = instruction_args[m_idx]
@@ -639,21 +642,20 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
bool exit_ok = false;
bool awaited = false;
#endif
+#ifdef DEBUG_ENABLED
+ int variant_address_limits[ADDR_TYPE_MAX] = { _stack_size, _constant_count, p_instance ? p_instance->members.size() : 0 };
+#endif
+
+ Variant *variant_addresses[ADDR_TYPE_MAX] = { stack, _constants_ptr, p_instance ? p_instance->members.ptrw() : nullptr };
#ifdef DEBUG_ENABLED
OPCODE_WHILE(ip < _code_size) {
- int last_opcode = _code_ptr[ip] & INSTR_MASK;
+ int last_opcode = _code_ptr[ip];
#else
OPCODE_WHILE(true) {
#endif
- // Load arguments for the instruction before each instruction.
- int instr_arg_count = ((_code_ptr[ip]) & INSTR_ARGS_MASK) >> INSTR_BITS;
- for (int i = 0; i < instr_arg_count; i++) {
- GET_VARIANT_PTR(v, i + 1);
- instruction_args[i] = v;
- }
- OPCODE_SWITCH(_code_ptr[ip] & INSTR_MASK) {
+ OPCODE_SWITCH(_code_ptr[ip]) {
OPCODE(OPCODE_OPERATOR) {
CHECK_SPACE(5);
@@ -661,9 +663,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
Variant::Operator op = (Variant::Operator)_code_ptr[ip + 4];
GD_ERR_BREAK(op >= Variant::OP_MAX);
- GET_INSTRUCTION_ARG(a, 0);
- GET_INSTRUCTION_ARG(b, 1);
- GET_INSTRUCTION_ARG(dst, 2);
+ GET_VARIANT_PTR(a, 0);
+ GET_VARIANT_PTR(b, 1);
+ GET_VARIANT_PTR(dst, 2);
#ifdef DEBUG_ENABLED
@@ -696,9 +698,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
GD_ERR_BREAK(operator_idx < 0 || operator_idx >= _operator_funcs_count);
Variant::ValidatedOperatorEvaluator operator_func = _operator_funcs_ptr[operator_idx];
- GET_INSTRUCTION_ARG(a, 0);
- GET_INSTRUCTION_ARG(b, 1);
- GET_INSTRUCTION_ARG(dst, 2);
+ GET_VARIANT_PTR(a, 0);
+ GET_VARIANT_PTR(b, 1);
+ GET_VARIANT_PTR(dst, 2);
operator_func(a, b, dst);
@@ -709,9 +711,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_EXTENDS_TEST) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(a, 0);
- GET_INSTRUCTION_ARG(b, 1);
- GET_INSTRUCTION_ARG(dst, 2);
+ GET_VARIANT_PTR(a, 0);
+ GET_VARIANT_PTR(b, 1);
+ GET_VARIANT_PTR(dst, 2);
#ifdef DEBUG_ENABLED
if (b->get_type() != Variant::OBJECT || b->operator Object *() == nullptr) {
@@ -784,8 +786,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_IS_BUILTIN) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(value, 0);
- GET_INSTRUCTION_ARG(dst, 1);
+ GET_VARIANT_PTR(value, 0);
+ GET_VARIANT_PTR(dst, 1);
Variant::Type var_type = (Variant::Type)_code_ptr[ip + 3];
GD_ERR_BREAK(var_type < 0 || var_type >= Variant::VARIANT_MAX);
@@ -798,9 +800,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_SET_KEYED) {
CHECK_SPACE(3);
- GET_INSTRUCTION_ARG(dst, 0);
- GET_INSTRUCTION_ARG(index, 1);
- GET_INSTRUCTION_ARG(value, 2);
+ GET_VARIANT_PTR(dst, 0);
+ GET_VARIANT_PTR(index, 1);
+ GET_VARIANT_PTR(value, 2);
bool valid;
dst->set(*index, *value, &valid);
@@ -824,9 +826,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_SET_KEYED_VALIDATED) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(dst, 0);
- GET_INSTRUCTION_ARG(index, 1);
- GET_INSTRUCTION_ARG(value, 2);
+ GET_VARIANT_PTR(dst, 0);
+ GET_VARIANT_PTR(index, 1);
+ GET_VARIANT_PTR(value, 2);
int index_setter = _code_ptr[ip + 4];
GD_ERR_BREAK(index_setter < 0 || index_setter >= _keyed_setters_count);
@@ -854,9 +856,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_SET_INDEXED_VALIDATED) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(dst, 0);
- GET_INSTRUCTION_ARG(index, 1);
- GET_INSTRUCTION_ARG(value, 2);
+ GET_VARIANT_PTR(dst, 0);
+ GET_VARIANT_PTR(index, 1);
+ GET_VARIANT_PTR(value, 2);
int index_setter = _code_ptr[ip + 4];
GD_ERR_BREAK(index_setter < 0 || index_setter >= _indexed_setters_count);
@@ -886,9 +888,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_GET_KEYED) {
CHECK_SPACE(3);
- GET_INSTRUCTION_ARG(src, 0);
- GET_INSTRUCTION_ARG(index, 1);
- GET_INSTRUCTION_ARG(dst, 2);
+ GET_VARIANT_PTR(src, 0);
+ GET_VARIANT_PTR(index, 1);
+ GET_VARIANT_PTR(dst, 2);
bool valid;
#ifdef DEBUG_ENABLED
@@ -918,9 +920,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_GET_KEYED_VALIDATED) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(src, 0);
- GET_INSTRUCTION_ARG(key, 1);
- GET_INSTRUCTION_ARG(dst, 2);
+ GET_VARIANT_PTR(src, 0);
+ GET_VARIANT_PTR(key, 1);
+ GET_VARIANT_PTR(dst, 2);
int index_getter = _code_ptr[ip + 4];
GD_ERR_BREAK(index_getter < 0 || index_getter >= _keyed_getters_count);
@@ -954,9 +956,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_GET_INDEXED_VALIDATED) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(src, 0);
- GET_INSTRUCTION_ARG(index, 1);
- GET_INSTRUCTION_ARG(dst, 2);
+ GET_VARIANT_PTR(src, 0);
+ GET_VARIANT_PTR(index, 1);
+ GET_VARIANT_PTR(dst, 2);
int index_getter = _code_ptr[ip + 4];
GD_ERR_BREAK(index_getter < 0 || index_getter >= _indexed_getters_count);
@@ -986,8 +988,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_SET_NAMED) {
CHECK_SPACE(3);
- GET_INSTRUCTION_ARG(dst, 0);
- GET_INSTRUCTION_ARG(value, 1);
+ GET_VARIANT_PTR(dst, 0);
+ GET_VARIANT_PTR(value, 1);
int indexname = _code_ptr[ip + 3];
@@ -1011,8 +1013,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_SET_NAMED_VALIDATED) {
CHECK_SPACE(3);
- GET_INSTRUCTION_ARG(dst, 0);
- GET_INSTRUCTION_ARG(value, 1);
+ GET_VARIANT_PTR(dst, 0);
+ GET_VARIANT_PTR(value, 1);
int index_setter = _code_ptr[ip + 3];
GD_ERR_BREAK(index_setter < 0 || index_setter >= _setters_count);
@@ -1026,8 +1028,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_GET_NAMED) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(src, 0);
- GET_INSTRUCTION_ARG(dst, 1);
+ GET_VARIANT_PTR(src, 0);
+ GET_VARIANT_PTR(dst, 1);
int indexname = _code_ptr[ip + 3];
@@ -1056,8 +1058,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_GET_NAMED_VALIDATED) {
CHECK_SPACE(3);
- GET_INSTRUCTION_ARG(src, 0);
- GET_INSTRUCTION_ARG(dst, 1);
+ GET_VARIANT_PTR(src, 0);
+ GET_VARIANT_PTR(dst, 1);
int index_getter = _code_ptr[ip + 3];
GD_ERR_BREAK(index_getter < 0 || index_getter >= _getters_count);
@@ -1070,7 +1072,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_SET_MEMBER) {
CHECK_SPACE(3);
- GET_INSTRUCTION_ARG(src, 0);
+ GET_VARIANT_PTR(src, 0);
int indexname = _code_ptr[ip + 2];
GD_ERR_BREAK(indexname < 0 || indexname >= _global_names_count);
const StringName *index = &_global_names_ptr[indexname];
@@ -1094,7 +1096,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_GET_MEMBER) {
CHECK_SPACE(3);
- GET_INSTRUCTION_ARG(dst, 0);
+ GET_VARIANT_PTR(dst, 0);
int indexname = _code_ptr[ip + 2];
GD_ERR_BREAK(indexname < 0 || indexname >= _global_names_count);
const StringName *index = &_global_names_ptr[indexname];
@@ -1113,8 +1115,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ASSIGN) {
CHECK_SPACE(3);
- GET_INSTRUCTION_ARG(dst, 0);
- GET_INSTRUCTION_ARG(src, 1);
+ GET_VARIANT_PTR(dst, 0);
+ GET_VARIANT_PTR(src, 1);
*dst = *src;
@@ -1124,7 +1126,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ASSIGN_TRUE) {
CHECK_SPACE(2);
- GET_INSTRUCTION_ARG(dst, 0);
+ GET_VARIANT_PTR(dst, 0);
*dst = true;
@@ -1134,7 +1136,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ASSIGN_FALSE) {
CHECK_SPACE(2);
- GET_INSTRUCTION_ARG(dst, 0);
+ GET_VARIANT_PTR(dst, 0);
*dst = false;
@@ -1144,8 +1146,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ASSIGN_TYPED_BUILTIN) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(dst, 0);
- GET_INSTRUCTION_ARG(src, 1);
+ GET_VARIANT_PTR(dst, 0);
+ GET_VARIANT_PTR(src, 1);
Variant::Type var_type = (Variant::Type)_code_ptr[ip + 3];
GD_ERR_BREAK(var_type < 0 || var_type >= Variant::VARIANT_MAX);
@@ -1173,8 +1175,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ASSIGN_TYPED_ARRAY) {
CHECK_SPACE(3);
- GET_INSTRUCTION_ARG(dst, 0);
- GET_INSTRUCTION_ARG(src, 1);
+ GET_VARIANT_PTR(dst, 0);
+ GET_VARIANT_PTR(src, 1);
Array *dst_arr = VariantInternal::get_array(dst);
@@ -1198,11 +1200,11 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ASSIGN_TYPED_NATIVE) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(dst, 0);
- GET_INSTRUCTION_ARG(src, 1);
+ GET_VARIANT_PTR(dst, 0);
+ GET_VARIANT_PTR(src, 1);
#ifdef DEBUG_ENABLED
- GET_INSTRUCTION_ARG(type, 2);
+ GET_VARIANT_PTR(type, 2);
GDScriptNativeClass *nc = Object::cast_to<GDScriptNativeClass>(type->operator Object *());
GD_ERR_BREAK(!nc);
if (src->get_type() != Variant::OBJECT && src->get_type() != Variant::NIL) {
@@ -1226,11 +1228,11 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ASSIGN_TYPED_SCRIPT) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(dst, 0);
- GET_INSTRUCTION_ARG(src, 1);
+ GET_VARIANT_PTR(dst, 0);
+ GET_VARIANT_PTR(src, 1);
#ifdef DEBUG_ENABLED
- GET_INSTRUCTION_ARG(type, 2);
+ GET_VARIANT_PTR(type, 2);
Script *base_type = Object::cast_to<Script>(type->operator Object *());
GD_ERR_BREAK(!base_type);
@@ -1275,8 +1277,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_CAST_TO_BUILTIN) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(src, 0);
- GET_INSTRUCTION_ARG(dst, 1);
+ GET_VARIANT_PTR(src, 0);
+ GET_VARIANT_PTR(dst, 1);
Variant::Type to_type = (Variant::Type)_code_ptr[ip + 3];
GD_ERR_BREAK(to_type < 0 || to_type >= Variant::VARIANT_MAX);
@@ -1304,9 +1306,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_CAST_TO_NATIVE) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(src, 0);
- GET_INSTRUCTION_ARG(dst, 1);
- GET_INSTRUCTION_ARG(to_type, 2);
+ GET_VARIANT_PTR(src, 0);
+ GET_VARIANT_PTR(dst, 1);
+ GET_VARIANT_PTR(to_type, 2);
GDScriptNativeClass *nc = Object::cast_to<GDScriptNativeClass>(to_type->operator Object *());
GD_ERR_BREAK(!nc);
@@ -1335,9 +1337,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_CAST_TO_SCRIPT) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(src, 0);
- GET_INSTRUCTION_ARG(dst, 1);
- GET_INSTRUCTION_ARG(to_type, 2);
+ GET_VARIANT_PTR(src, 0);
+ GET_VARIANT_PTR(dst, 1);
+ GET_VARIANT_PTR(to_type, 2);
Script *base_type = Object::cast_to<Script>(to_type->operator Object *());
@@ -1383,6 +1385,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
DISPATCH_OPCODE;
OPCODE(OPCODE_CONSTRUCT) {
+ LOAD_INSTRUCTION_ARGS
CHECK_SPACE(2 + instr_arg_count);
ip += instr_arg_count;
@@ -1390,6 +1393,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
int argc = _code_ptr[ip + 1];
Variant::Type t = Variant::Type(_code_ptr[ip + 2]);
+
Variant **argptrs = instruction_args;
GET_INSTRUCTION_ARG(dst, argc);
@@ -1409,8 +1413,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
DISPATCH_OPCODE;
OPCODE(OPCODE_CONSTRUCT_VALIDATED) {
+ LOAD_INSTRUCTION_ARGS
CHECK_SPACE(2 + instr_arg_count);
-
ip += instr_arg_count;
int argc = _code_ptr[ip + 1];
@@ -1430,6 +1434,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
DISPATCH_OPCODE;
OPCODE(OPCODE_CONSTRUCT_ARRAY) {
+ LOAD_INSTRUCTION_ARGS
CHECK_SPACE(1 + instr_arg_count);
ip += instr_arg_count;
@@ -1451,6 +1456,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
DISPATCH_OPCODE;
OPCODE(OPCODE_CONSTRUCT_TYPED_ARRAY) {
+ LOAD_INSTRUCTION_ARGS
CHECK_SPACE(3 + instr_arg_count);
ip += instr_arg_count;
@@ -1480,6 +1486,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
DISPATCH_OPCODE;
OPCODE(OPCODE_CONSTRUCT_DICTIONARY) {
+ LOAD_INSTRUCTION_ARGS
CHECK_SPACE(2 + instr_arg_count);
ip += instr_arg_count;
@@ -1504,11 +1511,12 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_CALL_ASYNC)
OPCODE(OPCODE_CALL_RETURN)
OPCODE(OPCODE_CALL) {
- CHECK_SPACE(3 + instr_arg_count);
- bool call_ret = (_code_ptr[ip] & INSTR_MASK) != OPCODE_CALL;
+ bool call_ret = (_code_ptr[ip]) != OPCODE_CALL;
#ifdef DEBUG_ENABLED
- bool call_async = (_code_ptr[ip] & INSTR_MASK) == OPCODE_CALL_ASYNC;
+ bool call_async = (_code_ptr[ip]) == OPCODE_CALL_ASYNC;
#endif
+ LOAD_INSTRUCTION_ARGS
+ CHECK_SPACE(3 + instr_arg_count);
ip += instr_arg_count;
@@ -1603,8 +1611,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_CALL_METHOD_BIND)
OPCODE(OPCODE_CALL_METHOD_BIND_RET) {
+ bool call_ret = (_code_ptr[ip]) == OPCODE_CALL_METHOD_BIND_RET;
+ LOAD_INSTRUCTION_ARGS
CHECK_SPACE(3 + instr_arg_count);
- bool call_ret = (_code_ptr[ip] & INSTR_MASK) == OPCODE_CALL_METHOD_BIND_RET;
ip += instr_arg_count;
@@ -1682,6 +1691,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
DISPATCH_OPCODE;
OPCODE(OPCODE_CALL_BUILTIN_STATIC) {
+ LOAD_INSTRUCTION_ARGS
CHECK_SPACE(4 + instr_arg_count);
ip += instr_arg_count;
@@ -1727,6 +1737,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
DISPATCH_OPCODE;
OPCODE(OPCODE_CALL_NATIVE_STATIC) {
+ LOAD_INSTRUCTION_ARGS
CHECK_SPACE(3 + instr_arg_count);
ip += instr_arg_count;
@@ -1770,6 +1781,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
#ifdef DEBUG_ENABLED
#define OPCODE_CALL_PTR(m_type) \
OPCODE(OPCODE_CALL_PTRCALL_##m_type) { \
+ LOAD_INSTRUCTION_ARGS \
CHECK_SPACE(3 + instr_arg_count); \
ip += instr_arg_count; \
int argc = _code_ptr[ip + 1]; \
@@ -1808,6 +1820,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
#else
#define OPCODE_CALL_PTR(m_type) \
OPCODE(OPCODE_CALL_PTRCALL_##m_type) { \
+ LOAD_INSTRUCTION_ARGS \
CHECK_SPACE(3 + instr_arg_count); \
ip += instr_arg_count; \
int argc = _code_ptr[ip + 1]; \
@@ -1865,6 +1878,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE_CALL_PTR(PACKED_VECTOR3_ARRAY);
OPCODE_CALL_PTR(PACKED_COLOR_ARRAY);
OPCODE(OPCODE_CALL_PTRCALL_OBJECT) {
+ LOAD_INSTRUCTION_ARGS
CHECK_SPACE(3 + instr_arg_count);
ip += instr_arg_count;
@@ -1919,6 +1933,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
}
DISPATCH_OPCODE;
OPCODE(OPCODE_CALL_PTRCALL_NO_RETURN) {
+ LOAD_INSTRUCTION_ARGS
CHECK_SPACE(3 + instr_arg_count);
ip += instr_arg_count;
@@ -1971,6 +1986,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
DISPATCH_OPCODE;
OPCODE(OPCODE_CALL_BUILTIN_TYPE_VALIDATED) {
+ LOAD_INSTRUCTION_ARGS
+
CHECK_SPACE(3 + instr_arg_count);
ip += instr_arg_count;
@@ -2005,6 +2022,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
DISPATCH_OPCODE;
OPCODE(OPCODE_CALL_UTILITY) {
+ LOAD_INSTRUCTION_ARGS
CHECK_SPACE(3 + instr_arg_count);
ip += instr_arg_count;
@@ -2039,6 +2057,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
DISPATCH_OPCODE;
OPCODE(OPCODE_CALL_UTILITY_VALIDATED) {
+ LOAD_INSTRUCTION_ARGS
CHECK_SPACE(3 + instr_arg_count);
ip += instr_arg_count;
@@ -2060,6 +2079,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
DISPATCH_OPCODE;
OPCODE(OPCODE_CALL_GDSCRIPT_UTILITY) {
+ LOAD_INSTRUCTION_ARGS
CHECK_SPACE(3 + instr_arg_count);
ip += instr_arg_count;
@@ -2095,6 +2115,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
DISPATCH_OPCODE;
OPCODE(OPCODE_CALL_SELF_BASE) {
+ LOAD_INSTRUCTION_ARGS
CHECK_SPACE(3 + instr_arg_count);
ip += instr_arg_count;
@@ -2164,7 +2185,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
CHECK_SPACE(2);
// Do the one-shot connect.
- GET_INSTRUCTION_ARG(argobj, 0);
+ GET_VARIANT_PTR(argobj, 0);
Signal sig;
bool is_signal = true;
@@ -2191,7 +2212,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
if (result.get_type() != Variant::SIGNAL) {
// Not async, return immediately using the target from OPCODE_AWAIT_RESUME.
- GET_VARIANT_PTR(target, 3);
+ GET_VARIANT_PTR(target, 2);
*target = result;
ip += 4; // Skip OPCODE_AWAIT_RESUME and its data.
is_signal = false;
@@ -2257,13 +2278,14 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE_BREAK;
}
#endif
- GET_INSTRUCTION_ARG(result, 0);
+ GET_VARIANT_PTR(result, 0);
*result = p_state->result;
ip += 2;
}
DISPATCH_OPCODE;
OPCODE(OPCODE_CREATE_LAMBDA) {
+ LOAD_INSTRUCTION_ARGS
CHECK_SPACE(2 + instr_arg_count);
ip += instr_arg_count;
@@ -2292,6 +2314,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
DISPATCH_OPCODE;
OPCODE(OPCODE_CREATE_SELF_LAMBDA) {
+ LOAD_INSTRUCTION_ARGS
CHECK_SPACE(2 + instr_arg_count);
GD_ERR_BREAK(p_instance == nullptr);
@@ -2338,7 +2361,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_JUMP_IF) {
CHECK_SPACE(3);
- GET_INSTRUCTION_ARG(test, 0);
+ GET_VARIANT_PTR(test, 0);
bool result = test->booleanize();
@@ -2355,7 +2378,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_JUMP_IF_NOT) {
CHECK_SPACE(3);
- GET_INSTRUCTION_ARG(test, 0);
+ GET_VARIANT_PTR(test, 0);
bool result = test->booleanize();
@@ -2378,7 +2401,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_JUMP_IF_SHARED) {
CHECK_SPACE(3);
- GET_INSTRUCTION_ARG(val, 0);
+ GET_VARIANT_PTR(val, 0);
if (val->is_shared()) {
int to = _code_ptr[ip + 2];
@@ -2392,7 +2415,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_RETURN) {
CHECK_SPACE(2);
- GET_INSTRUCTION_ARG(r, 0);
+ GET_VARIANT_PTR(r, 0);
retvalue = *r;
#ifdef DEBUG_ENABLED
exit_ok = true;
@@ -2402,7 +2425,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_RETURN_TYPED_BUILTIN) {
CHECK_SPACE(3);
- GET_INSTRUCTION_ARG(r, 0);
+ GET_VARIANT_PTR(r, 0);
Variant::Type ret_type = (Variant::Type)_code_ptr[ip + 2];
GD_ERR_BREAK(ret_type < 0 || ret_type >= Variant::VARIANT_MAX);
@@ -2433,9 +2456,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_RETURN_TYPED_ARRAY) {
CHECK_SPACE(5);
- GET_INSTRUCTION_ARG(r, 0);
+ GET_VARIANT_PTR(r, 0);
- GET_INSTRUCTION_ARG(script_type, 1);
+ GET_VARIANT_PTR(script_type, 1);
Variant::Type builtin_type = (Variant::Type)_code_ptr[ip + 3];
int native_type_idx = _code_ptr[ip + 4];
GD_ERR_BREAK(native_type_idx < 0 || native_type_idx >= _global_names_count);
@@ -2474,9 +2497,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_RETURN_TYPED_NATIVE) {
CHECK_SPACE(3);
- GET_INSTRUCTION_ARG(r, 0);
+ GET_VARIANT_PTR(r, 0);
- GET_INSTRUCTION_ARG(type, 1);
+ GET_VARIANT_PTR(type, 1);
GDScriptNativeClass *nc = Object::cast_to<GDScriptNativeClass>(type->operator Object *());
GD_ERR_BREAK(!nc);
@@ -2514,9 +2537,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_RETURN_TYPED_SCRIPT) {
CHECK_SPACE(3);
- GET_INSTRUCTION_ARG(r, 0);
+ GET_VARIANT_PTR(r, 0);
- GET_INSTRUCTION_ARG(type, 1);
+ GET_VARIANT_PTR(type, 1);
Script *base_type = Object::cast_to<Script>(type->operator Object *());
GD_ERR_BREAK(!base_type);
@@ -2580,8 +2603,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ITERATE_BEGIN) {
CHECK_SPACE(8); // Space for this and a regular iterate.
- GET_INSTRUCTION_ARG(counter, 0);
- GET_INSTRUCTION_ARG(container, 1);
+ GET_VARIANT_PTR(counter, 0);
+ GET_VARIANT_PTR(container, 1);
bool valid;
if (!container->iter_init(*counter, valid)) {
@@ -2595,7 +2618,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
ip = jumpto;
} else {
- GET_INSTRUCTION_ARG(iterator, 2);
+ GET_VARIANT_PTR(iterator, 2);
*iterator = container->iter_get(*counter, valid);
#ifdef DEBUG_ENABLED
@@ -2612,8 +2635,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ITERATE_BEGIN_INT) {
CHECK_SPACE(8); // Check space for iterate instruction too.
- GET_INSTRUCTION_ARG(counter, 0);
- GET_INSTRUCTION_ARG(container, 1);
+ GET_VARIANT_PTR(counter, 0);
+ GET_VARIANT_PTR(container, 1);
int64_t size = *VariantInternal::get_int(container);
@@ -2621,7 +2644,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
*VariantInternal::get_int(counter) = 0;
if (size > 0) {
- GET_INSTRUCTION_ARG(iterator, 2);
+ GET_VARIANT_PTR(iterator, 2);
VariantInternal::initialize(iterator, Variant::INT);
*VariantInternal::get_int(iterator) = 0;
@@ -2639,8 +2662,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ITERATE_BEGIN_FLOAT) {
CHECK_SPACE(8); // Check space for iterate instruction too.
- GET_INSTRUCTION_ARG(counter, 0);
- GET_INSTRUCTION_ARG(container, 1);
+ GET_VARIANT_PTR(counter, 0);
+ GET_VARIANT_PTR(container, 1);
double size = *VariantInternal::get_float(container);
@@ -2648,7 +2671,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
*VariantInternal::get_float(counter) = 0.0;
if (size > 0) {
- GET_INSTRUCTION_ARG(iterator, 2);
+ GET_VARIANT_PTR(iterator, 2);
VariantInternal::initialize(iterator, Variant::FLOAT);
*VariantInternal::get_float(iterator) = 0;
@@ -2666,8 +2689,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ITERATE_BEGIN_VECTOR2) {
CHECK_SPACE(8); // Check space for iterate instruction too.
- GET_INSTRUCTION_ARG(counter, 0);
- GET_INSTRUCTION_ARG(container, 1);
+ GET_VARIANT_PTR(counter, 0);
+ GET_VARIANT_PTR(container, 1);
Vector2 *bounds = VariantInternal::get_vector2(container);
@@ -2675,7 +2698,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
*VariantInternal::get_float(counter) = bounds->x;
if (bounds->x < bounds->y) {
- GET_INSTRUCTION_ARG(iterator, 2);
+ GET_VARIANT_PTR(iterator, 2);
VariantInternal::initialize(iterator, Variant::FLOAT);
*VariantInternal::get_float(iterator) = bounds->x;
@@ -2693,8 +2716,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ITERATE_BEGIN_VECTOR2I) {
CHECK_SPACE(8); // Check space for iterate instruction too.
- GET_INSTRUCTION_ARG(counter, 0);
- GET_INSTRUCTION_ARG(container, 1);
+ GET_VARIANT_PTR(counter, 0);
+ GET_VARIANT_PTR(container, 1);
Vector2i *bounds = VariantInternal::get_vector2i(container);
@@ -2702,7 +2725,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
*VariantInternal::get_int(counter) = bounds->x;
if (bounds->x < bounds->y) {
- GET_INSTRUCTION_ARG(iterator, 2);
+ GET_VARIANT_PTR(iterator, 2);
VariantInternal::initialize(iterator, Variant::INT);
*VariantInternal::get_int(iterator) = bounds->x;
@@ -2720,8 +2743,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ITERATE_BEGIN_VECTOR3) {
CHECK_SPACE(8); // Check space for iterate instruction too.
- GET_INSTRUCTION_ARG(counter, 0);
- GET_INSTRUCTION_ARG(container, 1);
+ GET_VARIANT_PTR(counter, 0);
+ GET_VARIANT_PTR(container, 1);
Vector3 *bounds = VariantInternal::get_vector3(container);
double from = bounds->x;
@@ -2734,7 +2757,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
bool do_continue = from == to ? false : (from < to ? step > 0 : step < 0);
if (do_continue) {
- GET_INSTRUCTION_ARG(iterator, 2);
+ GET_VARIANT_PTR(iterator, 2);
VariantInternal::initialize(iterator, Variant::FLOAT);
*VariantInternal::get_float(iterator) = from;
@@ -2752,8 +2775,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ITERATE_BEGIN_VECTOR3I) {
CHECK_SPACE(8); // Check space for iterate instruction too.
- GET_INSTRUCTION_ARG(counter, 0);
- GET_INSTRUCTION_ARG(container, 1);
+ GET_VARIANT_PTR(counter, 0);
+ GET_VARIANT_PTR(container, 1);
Vector3i *bounds = VariantInternal::get_vector3i(container);
int64_t from = bounds->x;
@@ -2766,7 +2789,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
bool do_continue = from == to ? false : (from < to ? step > 0 : step < 0);
if (do_continue) {
- GET_INSTRUCTION_ARG(iterator, 2);
+ GET_VARIANT_PTR(iterator, 2);
VariantInternal::initialize(iterator, Variant::INT);
*VariantInternal::get_int(iterator) = from;
@@ -2784,8 +2807,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ITERATE_BEGIN_STRING) {
CHECK_SPACE(8); // Check space for iterate instruction too.
- GET_INSTRUCTION_ARG(counter, 0);
- GET_INSTRUCTION_ARG(container, 1);
+ GET_VARIANT_PTR(counter, 0);
+ GET_VARIANT_PTR(container, 1);
String *str = VariantInternal::get_string(container);
@@ -2793,7 +2816,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
*VariantInternal::get_int(counter) = 0;
if (!str->is_empty()) {
- GET_INSTRUCTION_ARG(iterator, 2);
+ GET_VARIANT_PTR(iterator, 2);
VariantInternal::initialize(iterator, Variant::STRING);
*VariantInternal::get_string(iterator) = str->substr(0, 1);
@@ -2811,14 +2834,14 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ITERATE_BEGIN_DICTIONARY) {
CHECK_SPACE(8); // Check space for iterate instruction too.
- GET_INSTRUCTION_ARG(counter, 0);
- GET_INSTRUCTION_ARG(container, 1);
+ GET_VARIANT_PTR(counter, 0);
+ GET_VARIANT_PTR(container, 1);
Dictionary *dict = VariantInternal::get_dictionary(container);
const Variant *next = dict->next(nullptr);
if (!dict->is_empty()) {
- GET_INSTRUCTION_ARG(iterator, 2);
+ GET_VARIANT_PTR(iterator, 2);
*counter = *next;
*iterator = *next;
@@ -2836,8 +2859,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ITERATE_BEGIN_ARRAY) {
CHECK_SPACE(8); // Check space for iterate instruction too.
- GET_INSTRUCTION_ARG(counter, 0);
- GET_INSTRUCTION_ARG(container, 1);
+ GET_VARIANT_PTR(counter, 0);
+ GET_VARIANT_PTR(container, 1);
Array *array = VariantInternal::get_array(container);
@@ -2845,7 +2868,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
*VariantInternal::get_int(counter) = 0;
if (!array->is_empty()) {
- GET_INSTRUCTION_ARG(iterator, 2);
+ GET_VARIANT_PTR(iterator, 2);
*iterator = array->get(0);
// Skip regular iterate.
@@ -2862,13 +2885,13 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
#define OPCODE_ITERATE_BEGIN_PACKED_ARRAY(m_var_type, m_elem_type, m_get_func, m_var_ret_type, m_ret_type, m_ret_get_func) \
OPCODE(OPCODE_ITERATE_BEGIN_PACKED_##m_var_type##_ARRAY) { \
CHECK_SPACE(8); \
- GET_INSTRUCTION_ARG(counter, 0); \
- GET_INSTRUCTION_ARG(container, 1); \
+ GET_VARIANT_PTR(counter, 0); \
+ GET_VARIANT_PTR(container, 1); \
Vector<m_elem_type> *array = VariantInternal::m_get_func(container); \
VariantInternal::initialize(counter, Variant::INT); \
*VariantInternal::get_int(counter) = 0; \
if (!array->is_empty()) { \
- GET_INSTRUCTION_ARG(iterator, 2); \
+ GET_VARIANT_PTR(iterator, 2); \
VariantInternal::initialize(iterator, Variant::m_var_ret_type); \
m_ret_type *it = VariantInternal::m_ret_get_func(iterator); \
*it = array->get(0); \
@@ -2894,8 +2917,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ITERATE_BEGIN_OBJECT) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(counter, 0);
- GET_INSTRUCTION_ARG(container, 1);
+ GET_VARIANT_PTR(counter, 0);
+ GET_VARIANT_PTR(container, 1);
#ifdef DEBUG_ENABLED
bool freed = false;
@@ -2933,7 +2956,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
ip = jumpto;
} else {
- GET_INSTRUCTION_ARG(iterator, 2);
+ GET_VARIANT_PTR(iterator, 2);
*iterator = obj->callp(CoreStringNames::get_singleton()->_iter_get, (const Variant **)args, 1, ce);
#ifdef DEBUG_ENABLED
if (ce.error != Callable::CallError::CALL_OK) {
@@ -2950,8 +2973,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ITERATE) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(counter, 0);
- GET_INSTRUCTION_ARG(container, 1);
+ GET_VARIANT_PTR(counter, 0);
+ GET_VARIANT_PTR(container, 1);
bool valid;
if (!container->iter_next(*counter, valid)) {
@@ -2965,7 +2988,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
ip = jumpto;
} else {
- GET_INSTRUCTION_ARG(iterator, 2);
+ GET_VARIANT_PTR(iterator, 2);
*iterator = container->iter_get(*counter, valid);
#ifdef DEBUG_ENABLED
@@ -2982,8 +3005,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ITERATE_INT) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(counter, 0);
- GET_INSTRUCTION_ARG(container, 1);
+ GET_VARIANT_PTR(counter, 0);
+ GET_VARIANT_PTR(container, 1);
int64_t size = *VariantInternal::get_int(container);
int64_t *count = VariantInternal::get_int(counter);
@@ -2995,7 +3018,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
ip = jumpto;
} else {
- GET_INSTRUCTION_ARG(iterator, 2);
+ GET_VARIANT_PTR(iterator, 2);
*VariantInternal::get_int(iterator) = *count;
ip += 5; // Loop again.
@@ -3006,8 +3029,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ITERATE_FLOAT) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(counter, 0);
- GET_INSTRUCTION_ARG(container, 1);
+ GET_VARIANT_PTR(counter, 0);
+ GET_VARIANT_PTR(container, 1);
double size = *VariantInternal::get_float(container);
double *count = VariantInternal::get_float(counter);
@@ -3019,7 +3042,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
ip = jumpto;
} else {
- GET_INSTRUCTION_ARG(iterator, 2);
+ GET_VARIANT_PTR(iterator, 2);
*VariantInternal::get_float(iterator) = *count;
ip += 5; // Loop again.
@@ -3030,8 +3053,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ITERATE_VECTOR2) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(counter, 0);
- GET_INSTRUCTION_ARG(container, 1);
+ GET_VARIANT_PTR(counter, 0);
+ GET_VARIANT_PTR(container, 1);
const Vector2 *bounds = VariantInternal::get_vector2((const Variant *)container);
double *count = VariantInternal::get_float(counter);
@@ -3043,7 +3066,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
ip = jumpto;
} else {
- GET_INSTRUCTION_ARG(iterator, 2);
+ GET_VARIANT_PTR(iterator, 2);
*VariantInternal::get_float(iterator) = *count;
ip += 5; // Loop again.
@@ -3054,8 +3077,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ITERATE_VECTOR2I) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(counter, 0);
- GET_INSTRUCTION_ARG(container, 1);
+ GET_VARIANT_PTR(counter, 0);
+ GET_VARIANT_PTR(container, 1);
const Vector2i *bounds = VariantInternal::get_vector2i((const Variant *)container);
int64_t *count = VariantInternal::get_int(counter);
@@ -3067,7 +3090,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
ip = jumpto;
} else {
- GET_INSTRUCTION_ARG(iterator, 2);
+ GET_VARIANT_PTR(iterator, 2);
*VariantInternal::get_int(iterator) = *count;
ip += 5; // Loop again.
@@ -3078,8 +3101,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ITERATE_VECTOR3) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(counter, 0);
- GET_INSTRUCTION_ARG(container, 1);
+ GET_VARIANT_PTR(counter, 0);
+ GET_VARIANT_PTR(container, 1);
const Vector3 *bounds = VariantInternal::get_vector3((const Variant *)container);
double *count = VariantInternal::get_float(counter);
@@ -3091,7 +3114,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
ip = jumpto;
} else {
- GET_INSTRUCTION_ARG(iterator, 2);
+ GET_VARIANT_PTR(iterator, 2);
*VariantInternal::get_float(iterator) = *count;
ip += 5; // Loop again.
@@ -3102,8 +3125,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ITERATE_VECTOR3I) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(counter, 0);
- GET_INSTRUCTION_ARG(container, 1);
+ GET_VARIANT_PTR(counter, 0);
+ GET_VARIANT_PTR(container, 1);
const Vector3i *bounds = VariantInternal::get_vector3i((const Variant *)container);
int64_t *count = VariantInternal::get_int(counter);
@@ -3115,7 +3138,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
ip = jumpto;
} else {
- GET_INSTRUCTION_ARG(iterator, 2);
+ GET_VARIANT_PTR(iterator, 2);
*VariantInternal::get_int(iterator) = *count;
ip += 5; // Loop again.
@@ -3126,8 +3149,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ITERATE_STRING) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(counter, 0);
- GET_INSTRUCTION_ARG(container, 1);
+ GET_VARIANT_PTR(counter, 0);
+ GET_VARIANT_PTR(container, 1);
const String *str = VariantInternal::get_string((const Variant *)container);
int64_t *idx = VariantInternal::get_int(counter);
@@ -3138,7 +3161,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
ip = jumpto;
} else {
- GET_INSTRUCTION_ARG(iterator, 2);
+ GET_VARIANT_PTR(iterator, 2);
*VariantInternal::get_string(iterator) = str->substr(*idx, 1);
ip += 5; // Loop again.
@@ -3149,8 +3172,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ITERATE_DICTIONARY) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(counter, 0);
- GET_INSTRUCTION_ARG(container, 1);
+ GET_VARIANT_PTR(counter, 0);
+ GET_VARIANT_PTR(container, 1);
const Dictionary *dict = VariantInternal::get_dictionary((const Variant *)container);
const Variant *next = dict->next(counter);
@@ -3160,7 +3183,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
ip = jumpto;
} else {
- GET_INSTRUCTION_ARG(iterator, 2);
+ GET_VARIANT_PTR(iterator, 2);
*counter = *next;
*iterator = *next;
@@ -3172,8 +3195,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ITERATE_ARRAY) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(counter, 0);
- GET_INSTRUCTION_ARG(container, 1);
+ GET_VARIANT_PTR(counter, 0);
+ GET_VARIANT_PTR(container, 1);
const Array *array = VariantInternal::get_array((const Variant *)container);
int64_t *idx = VariantInternal::get_int(counter);
@@ -3184,7 +3207,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
ip = jumpto;
} else {
- GET_INSTRUCTION_ARG(iterator, 2);
+ GET_VARIANT_PTR(iterator, 2);
*iterator = array->get(*idx);
ip += 5; // Loop again.
@@ -3195,8 +3218,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
#define OPCODE_ITERATE_PACKED_ARRAY(m_var_type, m_elem_type, m_get_func, m_ret_get_func) \
OPCODE(OPCODE_ITERATE_PACKED_##m_var_type##_ARRAY) { \
CHECK_SPACE(4); \
- GET_INSTRUCTION_ARG(counter, 0); \
- GET_INSTRUCTION_ARG(container, 1); \
+ GET_VARIANT_PTR(counter, 0); \
+ GET_VARIANT_PTR(container, 1); \
const Vector<m_elem_type> *array = VariantInternal::m_get_func((const Variant *)container); \
int64_t *idx = VariantInternal::get_int(counter); \
(*idx)++; \
@@ -3205,7 +3228,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
GD_ERR_BREAK(jumpto<0 || jumpto> _code_size); \
ip = jumpto; \
} else { \
- GET_INSTRUCTION_ARG(iterator, 2); \
+ GET_VARIANT_PTR(iterator, 2); \
*VariantInternal::m_ret_get_func(iterator) = array->get(*idx); \
ip += 5; \
} \
@@ -3225,8 +3248,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE(OPCODE_ITERATE_OBJECT) {
CHECK_SPACE(4);
- GET_INSTRUCTION_ARG(counter, 0);
- GET_INSTRUCTION_ARG(container, 1);
+ GET_VARIANT_PTR(counter, 0);
+ GET_VARIANT_PTR(container, 1);
#ifdef DEBUG_ENABLED
bool freed = false;
@@ -3264,7 +3287,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
GD_ERR_BREAK(jumpto < 0 || jumpto > _code_size);
ip = jumpto;
} else {
- GET_INSTRUCTION_ARG(iterator, 2);
+ GET_VARIANT_PTR(iterator, 2);
*iterator = obj->callp(CoreStringNames::get_singleton()->_iter_get, (const Variant **)args, 1, ce);
#ifdef DEBUG_ENABLED
if (ce.error != Callable::CallError::CALL_OK) {
@@ -3283,7 +3306,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
int global_idx = _code_ptr[ip + 2];
GD_ERR_BREAK(global_idx < 0 || global_idx >= GDScriptLanguage::get_singleton()->get_global_array_size());
- GET_INSTRUCTION_ARG(dst, 0);
+ GET_VARIANT_PTR(dst, 0);
*dst = GDScriptLanguage::get_singleton()->get_global_array()[global_idx];
ip += 3;
@@ -3297,7 +3320,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
const StringName *globalname = &_global_names_ptr[globalname_idx];
GD_ERR_BREAK(!GDScriptLanguage::get_singleton()->get_named_globals_map().has(*globalname));
- GET_INSTRUCTION_ARG(dst, 0);
+ GET_VARIANT_PTR(dst, 0);
*dst = GDScriptLanguage::get_singleton()->get_named_globals_map()[*globalname];
ip += 3;
@@ -3307,7 +3330,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
#define OPCODE_TYPE_ADJUST(m_v_type, m_c_type) \
OPCODE(OPCODE_TYPE_ADJUST_##m_v_type) { \
CHECK_SPACE(2); \
- GET_INSTRUCTION_ARG(arg, 0); \
+ GET_VARIANT_PTR(arg, 0); \
VariantTypeAdjust<m_c_type>::adjust(arg); \
ip += 2; \
} \
@@ -3355,13 +3378,13 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
CHECK_SPACE(3);
#ifdef DEBUG_ENABLED
- GET_INSTRUCTION_ARG(test, 0);
+ GET_VARIANT_PTR(test, 0);
bool result = test->booleanize();
if (!result) {
String message_str;
if (_code_ptr[ip + 2] != 0) {
- GET_INSTRUCTION_ARG(message, 1);
+ GET_VARIANT_PTR(message, 1);
message_str = *message;
}
if (message_str.is_empty()) {