2017-03-05 15:47:28 +01:00
|
|
|
/*************************************************************************/
|
2017-11-16 18:38:18 +01:00
|
|
|
/* gdscript_function.h */
|
2017-03-05 15:47:28 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2017-03-05 15:47:28 +01:00
|
|
|
/*************************************************************************/
|
2020-01-01 11:16:22 +01:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2017-03-05 15:47:28 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2017-11-16 18:38:18 +01:00
|
|
|
#ifndef GDSCRIPT_FUNCTION_H
|
|
|
|
#define GDSCRIPT_FUNCTION_H
|
2016-06-01 03:28:27 +02:00
|
|
|
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/object/reference.h"
|
|
|
|
#include "core/object/script_language.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/os/thread.h"
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/string/string_name.h"
|
|
|
|
#include "core/templates/pair.h"
|
|
|
|
#include "core/templates/self_list.h"
|
|
|
|
#include "core/variant/variant.h"
|
2016-06-01 03:28:27 +02:00
|
|
|
|
2017-11-16 18:38:18 +01:00
|
|
|
class GDScriptInstance;
|
2016-06-01 03:28:27 +02:00
|
|
|
class GDScript;
|
|
|
|
|
2018-05-30 04:16:54 +02:00
|
|
|
struct GDScriptDataType {
|
2020-05-12 17:01:17 +02:00
|
|
|
enum Kind {
|
2019-01-30 02:12:41 +01:00
|
|
|
UNINITIALIZED,
|
2018-05-30 04:16:54 +02:00
|
|
|
BUILTIN,
|
|
|
|
NATIVE,
|
|
|
|
SCRIPT,
|
2019-01-30 02:12:41 +01:00
|
|
|
GDSCRIPT,
|
2020-05-12 17:01:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Kind kind = UNINITIALIZED;
|
|
|
|
|
|
|
|
bool has_type = false;
|
|
|
|
Variant::Type builtin_type = Variant::NIL;
|
2018-05-30 04:16:54 +02:00
|
|
|
StringName native_type;
|
2020-09-10 01:26:07 +02:00
|
|
|
Script *script_type = nullptr;
|
|
|
|
Ref<Script> script_type_ref;
|
2018-05-30 04:16:54 +02:00
|
|
|
|
2019-03-04 12:25:59 +01:00
|
|
|
bool is_type(const Variant &p_variant, bool p_allow_implicit_conversion = false) const {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!has_type) {
|
2020-05-10 12:56:01 +02:00
|
|
|
return true; // Can't type check
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-05-30 04:16:56 +02:00
|
|
|
|
|
|
|
switch (kind) {
|
2019-01-30 02:12:41 +01:00
|
|
|
case UNINITIALIZED:
|
|
|
|
break;
|
2018-05-30 04:16:56 +02:00
|
|
|
case BUILTIN: {
|
|
|
|
Variant::Type var_type = p_variant.get_type();
|
2019-03-04 12:25:59 +01:00
|
|
|
bool valid = builtin_type == var_type;
|
|
|
|
if (!valid && p_allow_implicit_conversion) {
|
|
|
|
valid = Variant::can_convert_strict(var_type, builtin_type);
|
|
|
|
}
|
|
|
|
return valid;
|
2018-05-30 04:16:56 +02:00
|
|
|
} break;
|
|
|
|
case NATIVE: {
|
|
|
|
if (p_variant.get_type() == Variant::NIL) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (p_variant.get_type() != Variant::OBJECT) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-01-16 14:53:34 +01:00
|
|
|
|
2020-02-13 20:03:10 +01:00
|
|
|
Object *obj = p_variant.get_validated_object();
|
|
|
|
if (!obj) {
|
2020-01-16 14:53:34 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ClassDB::is_parent_class(obj->get_class_name(), native_type)) {
|
|
|
|
// Try with underscore prefix
|
|
|
|
StringName underscore_native_type = "_" + native_type;
|
|
|
|
if (!ClassDB::is_parent_class(obj->get_class_name(), underscore_native_type)) {
|
|
|
|
return false;
|
2019-01-15 22:50:48 +01:00
|
|
|
}
|
2018-05-30 04:16:56 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} break;
|
|
|
|
case SCRIPT:
|
|
|
|
case GDSCRIPT: {
|
|
|
|
if (p_variant.get_type() == Variant::NIL) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (p_variant.get_type() != Variant::OBJECT) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-01-16 14:53:34 +01:00
|
|
|
|
2020-02-13 20:03:10 +01:00
|
|
|
Object *obj = p_variant.get_validated_object();
|
|
|
|
if (!obj) {
|
2020-01-16 14:53:34 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
Ref<Script> base = obj && obj->get_script_instance() ? obj->get_script_instance()->get_script() : nullptr;
|
2018-05-30 04:16:56 +02:00
|
|
|
bool valid = false;
|
|
|
|
while (base.is_valid()) {
|
|
|
|
if (base == script_type) {
|
|
|
|
valid = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
base = base->get_base_script();
|
|
|
|
}
|
|
|
|
return valid;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator PropertyInfo() const {
|
|
|
|
PropertyInfo info;
|
|
|
|
if (has_type) {
|
|
|
|
switch (kind) {
|
2019-01-30 02:12:41 +01:00
|
|
|
case UNINITIALIZED:
|
|
|
|
break;
|
2018-05-30 04:16:56 +02:00
|
|
|
case BUILTIN: {
|
|
|
|
info.type = builtin_type;
|
|
|
|
} break;
|
|
|
|
case NATIVE: {
|
|
|
|
info.type = Variant::OBJECT;
|
|
|
|
info.class_name = native_type;
|
|
|
|
} break;
|
|
|
|
case SCRIPT:
|
|
|
|
case GDSCRIPT: {
|
|
|
|
info.type = Variant::OBJECT;
|
|
|
|
info.class_name = script_type->get_instance_base_type();
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
info.type = Variant::NIL;
|
|
|
|
info.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
|
|
|
|
}
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
GDScriptDataType() {}
|
2018-05-30 04:16:54 +02:00
|
|
|
};
|
|
|
|
|
2017-11-16 18:38:18 +01:00
|
|
|
class GDScriptFunction {
|
2016-06-01 03:28:27 +02:00
|
|
|
public:
|
|
|
|
enum Opcode {
|
|
|
|
OPCODE_OPERATOR,
|
2020-11-13 20:47:45 +01:00
|
|
|
OPCODE_OPERATOR_VALIDATED,
|
2016-06-01 03:28:27 +02:00
|
|
|
OPCODE_EXTENDS_TEST,
|
2018-08-26 18:31:23 +02:00
|
|
|
OPCODE_IS_BUILTIN,
|
2020-11-16 16:59:53 +01:00
|
|
|
OPCODE_SET_KEYED,
|
|
|
|
OPCODE_SET_KEYED_VALIDATED,
|
|
|
|
OPCODE_SET_INDEXED_VALIDATED,
|
|
|
|
OPCODE_GET_KEYED,
|
|
|
|
OPCODE_GET_KEYED_VALIDATED,
|
|
|
|
OPCODE_GET_INDEXED_VALIDATED,
|
2016-06-01 03:28:27 +02:00
|
|
|
OPCODE_SET_NAMED,
|
2020-11-16 16:59:53 +01:00
|
|
|
OPCODE_SET_NAMED_VALIDATED,
|
2016-06-01 03:28:27 +02:00
|
|
|
OPCODE_GET_NAMED,
|
2020-11-16 16:59:53 +01:00
|
|
|
OPCODE_GET_NAMED_VALIDATED,
|
2017-01-04 21:37:45 +01:00
|
|
|
OPCODE_SET_MEMBER,
|
|
|
|
OPCODE_GET_MEMBER,
|
2016-06-01 03:28:27 +02:00
|
|
|
OPCODE_ASSIGN,
|
|
|
|
OPCODE_ASSIGN_TRUE,
|
|
|
|
OPCODE_ASSIGN_FALSE,
|
2018-05-30 04:16:56 +02:00
|
|
|
OPCODE_ASSIGN_TYPED_BUILTIN,
|
|
|
|
OPCODE_ASSIGN_TYPED_NATIVE,
|
|
|
|
OPCODE_ASSIGN_TYPED_SCRIPT,
|
|
|
|
OPCODE_CAST_TO_BUILTIN,
|
|
|
|
OPCODE_CAST_TO_NATIVE,
|
|
|
|
OPCODE_CAST_TO_SCRIPT,
|
2020-11-18 15:37:08 +01:00
|
|
|
OPCODE_CONSTRUCT, // Only for basic types!
|
|
|
|
OPCODE_CONSTRUCT_VALIDATED, // Only for basic types!
|
2016-06-01 03:28:27 +02:00
|
|
|
OPCODE_CONSTRUCT_ARRAY,
|
|
|
|
OPCODE_CONSTRUCT_DICTIONARY,
|
|
|
|
OPCODE_CALL,
|
|
|
|
OPCODE_CALL_RETURN,
|
2020-05-02 00:14:56 +02:00
|
|
|
OPCODE_CALL_ASYNC,
|
2016-06-01 03:28:27 +02:00
|
|
|
OPCODE_CALL_BUILT_IN,
|
2020-11-18 14:32:28 +01:00
|
|
|
OPCODE_CALL_BUILTIN_TYPE_VALIDATED,
|
2016-06-01 03:28:27 +02:00
|
|
|
OPCODE_CALL_SELF_BASE,
|
2020-11-17 14:44:52 +01:00
|
|
|
OPCODE_CALL_METHOD_BIND,
|
|
|
|
OPCODE_CALL_METHOD_BIND_RET,
|
|
|
|
// ptrcall have one instruction per return type.
|
|
|
|
OPCODE_CALL_PTRCALL_NO_RETURN,
|
|
|
|
OPCODE_CALL_PTRCALL_BOOL,
|
|
|
|
OPCODE_CALL_PTRCALL_INT,
|
|
|
|
OPCODE_CALL_PTRCALL_FLOAT,
|
|
|
|
OPCODE_CALL_PTRCALL_STRING,
|
|
|
|
OPCODE_CALL_PTRCALL_VECTOR2,
|
|
|
|
OPCODE_CALL_PTRCALL_VECTOR2I,
|
|
|
|
OPCODE_CALL_PTRCALL_RECT2,
|
|
|
|
OPCODE_CALL_PTRCALL_RECT2I,
|
|
|
|
OPCODE_CALL_PTRCALL_VECTOR3,
|
|
|
|
OPCODE_CALL_PTRCALL_VECTOR3I,
|
|
|
|
OPCODE_CALL_PTRCALL_TRANSFORM2D,
|
|
|
|
OPCODE_CALL_PTRCALL_PLANE,
|
|
|
|
OPCODE_CALL_PTRCALL_QUAT,
|
|
|
|
OPCODE_CALL_PTRCALL_AABB,
|
|
|
|
OPCODE_CALL_PTRCALL_BASIS,
|
|
|
|
OPCODE_CALL_PTRCALL_TRANSFORM,
|
|
|
|
OPCODE_CALL_PTRCALL_COLOR,
|
|
|
|
OPCODE_CALL_PTRCALL_STRING_NAME,
|
|
|
|
OPCODE_CALL_PTRCALL_NODE_PATH,
|
|
|
|
OPCODE_CALL_PTRCALL_RID,
|
|
|
|
OPCODE_CALL_PTRCALL_OBJECT,
|
|
|
|
OPCODE_CALL_PTRCALL_CALLABLE,
|
|
|
|
OPCODE_CALL_PTRCALL_SIGNAL,
|
|
|
|
OPCODE_CALL_PTRCALL_DICTIONARY,
|
|
|
|
OPCODE_CALL_PTRCALL_ARRAY,
|
|
|
|
OPCODE_CALL_PTRCALL_PACKED_BYTE_ARRAY,
|
|
|
|
OPCODE_CALL_PTRCALL_PACKED_INT32_ARRAY,
|
|
|
|
OPCODE_CALL_PTRCALL_PACKED_INT64_ARRAY,
|
|
|
|
OPCODE_CALL_PTRCALL_PACKED_FLOAT32_ARRAY,
|
|
|
|
OPCODE_CALL_PTRCALL_PACKED_FLOAT64_ARRAY,
|
|
|
|
OPCODE_CALL_PTRCALL_PACKED_STRING_ARRAY,
|
|
|
|
OPCODE_CALL_PTRCALL_PACKED_VECTOR2_ARRAY,
|
|
|
|
OPCODE_CALL_PTRCALL_PACKED_VECTOR3_ARRAY,
|
|
|
|
OPCODE_CALL_PTRCALL_PACKED_COLOR_ARRAY,
|
2020-05-02 00:14:56 +02:00
|
|
|
OPCODE_AWAIT,
|
|
|
|
OPCODE_AWAIT_RESUME,
|
2016-06-01 03:28:27 +02:00
|
|
|
OPCODE_JUMP,
|
|
|
|
OPCODE_JUMP_IF,
|
|
|
|
OPCODE_JUMP_IF_NOT,
|
|
|
|
OPCODE_JUMP_TO_DEF_ARGUMENT,
|
|
|
|
OPCODE_RETURN,
|
|
|
|
OPCODE_ITERATE_BEGIN,
|
2020-10-07 14:36:48 +02:00
|
|
|
OPCODE_ITERATE_BEGIN_INT,
|
|
|
|
OPCODE_ITERATE_BEGIN_FLOAT,
|
|
|
|
OPCODE_ITERATE_BEGIN_VECTOR2,
|
|
|
|
OPCODE_ITERATE_BEGIN_VECTOR2I,
|
|
|
|
OPCODE_ITERATE_BEGIN_VECTOR3,
|
|
|
|
OPCODE_ITERATE_BEGIN_VECTOR3I,
|
|
|
|
OPCODE_ITERATE_BEGIN_STRING,
|
|
|
|
OPCODE_ITERATE_BEGIN_DICTIONARY,
|
|
|
|
OPCODE_ITERATE_BEGIN_ARRAY,
|
|
|
|
OPCODE_ITERATE_BEGIN_PACKED_BYTE_ARRAY,
|
|
|
|
OPCODE_ITERATE_BEGIN_PACKED_INT32_ARRAY,
|
|
|
|
OPCODE_ITERATE_BEGIN_PACKED_INT64_ARRAY,
|
|
|
|
OPCODE_ITERATE_BEGIN_PACKED_FLOAT32_ARRAY,
|
|
|
|
OPCODE_ITERATE_BEGIN_PACKED_FLOAT64_ARRAY,
|
|
|
|
OPCODE_ITERATE_BEGIN_PACKED_STRING_ARRAY,
|
|
|
|
OPCODE_ITERATE_BEGIN_PACKED_VECTOR2_ARRAY,
|
|
|
|
OPCODE_ITERATE_BEGIN_PACKED_VECTOR3_ARRAY,
|
|
|
|
OPCODE_ITERATE_BEGIN_PACKED_COLOR_ARRAY,
|
|
|
|
OPCODE_ITERATE_BEGIN_OBJECT,
|
2016-06-01 03:28:27 +02:00
|
|
|
OPCODE_ITERATE,
|
2020-10-07 14:36:48 +02:00
|
|
|
OPCODE_ITERATE_INT,
|
|
|
|
OPCODE_ITERATE_FLOAT,
|
|
|
|
OPCODE_ITERATE_VECTOR2,
|
|
|
|
OPCODE_ITERATE_VECTOR2I,
|
|
|
|
OPCODE_ITERATE_VECTOR3,
|
|
|
|
OPCODE_ITERATE_VECTOR3I,
|
|
|
|
OPCODE_ITERATE_STRING,
|
|
|
|
OPCODE_ITERATE_DICTIONARY,
|
|
|
|
OPCODE_ITERATE_ARRAY,
|
|
|
|
OPCODE_ITERATE_PACKED_BYTE_ARRAY,
|
|
|
|
OPCODE_ITERATE_PACKED_INT32_ARRAY,
|
|
|
|
OPCODE_ITERATE_PACKED_INT64_ARRAY,
|
|
|
|
OPCODE_ITERATE_PACKED_FLOAT32_ARRAY,
|
|
|
|
OPCODE_ITERATE_PACKED_FLOAT64_ARRAY,
|
|
|
|
OPCODE_ITERATE_PACKED_STRING_ARRAY,
|
|
|
|
OPCODE_ITERATE_PACKED_VECTOR2_ARRAY,
|
|
|
|
OPCODE_ITERATE_PACKED_VECTOR3_ARRAY,
|
|
|
|
OPCODE_ITERATE_PACKED_COLOR_ARRAY,
|
|
|
|
OPCODE_ITERATE_OBJECT,
|
2016-06-01 03:28:27 +02:00
|
|
|
OPCODE_ASSERT,
|
|
|
|
OPCODE_BREAKPOINT,
|
|
|
|
OPCODE_LINE,
|
|
|
|
OPCODE_END
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Address {
|
2017-03-05 16:44:50 +01:00
|
|
|
ADDR_BITS = 24,
|
|
|
|
ADDR_MASK = ((1 << ADDR_BITS) - 1),
|
|
|
|
ADDR_TYPE_MASK = ~ADDR_MASK,
|
|
|
|
ADDR_TYPE_SELF = 0,
|
|
|
|
ADDR_TYPE_CLASS = 1,
|
|
|
|
ADDR_TYPE_MEMBER = 2,
|
|
|
|
ADDR_TYPE_CLASS_CONSTANT = 3,
|
|
|
|
ADDR_TYPE_LOCAL_CONSTANT = 4,
|
|
|
|
ADDR_TYPE_STACK = 5,
|
|
|
|
ADDR_TYPE_STACK_VARIABLE = 6,
|
|
|
|
ADDR_TYPE_GLOBAL = 7,
|
2018-05-01 16:06:23 +02:00
|
|
|
ADDR_TYPE_NAMED_GLOBAL = 8,
|
|
|
|
ADDR_TYPE_NIL = 9
|
2016-06-01 03:28:27 +02:00
|
|
|
};
|
|
|
|
|
2020-11-13 14:31:14 +01:00
|
|
|
enum Instruction {
|
|
|
|
INSTR_BITS = 20,
|
|
|
|
INSTR_MASK = ((1 << INSTR_BITS) - 1),
|
|
|
|
INSTR_ARGS_MASK = ~INSTR_MASK,
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
struct StackDebug {
|
|
|
|
int line;
|
|
|
|
int pos;
|
|
|
|
bool added;
|
|
|
|
StringName identifier;
|
|
|
|
};
|
2016-06-01 03:28:27 +02:00
|
|
|
|
|
|
|
private:
|
2017-11-16 18:38:18 +01:00
|
|
|
friend class GDScriptCompiler;
|
2020-07-28 20:17:49 +02:00
|
|
|
friend class GDScriptByteCodeGenerator;
|
2016-06-01 03:28:27 +02:00
|
|
|
|
|
|
|
StringName source;
|
|
|
|
|
|
|
|
mutable Variant nil;
|
2020-11-13 14:31:14 +01:00
|
|
|
mutable Variant *_constants_ptr = nullptr;
|
|
|
|
int _constant_count = 0;
|
|
|
|
const StringName *_global_names_ptr = nullptr;
|
|
|
|
int _global_names_count = 0;
|
|
|
|
const int *_default_arg_ptr = nullptr;
|
|
|
|
int _default_arg_count = 0;
|
2020-11-13 20:47:45 +01:00
|
|
|
int _operator_funcs_count = 0;
|
|
|
|
const Variant::ValidatedOperatorEvaluator *_operator_funcs_ptr = nullptr;
|
2020-11-16 16:59:53 +01:00
|
|
|
int _setters_count = 0;
|
|
|
|
const Variant::ValidatedSetter *_setters_ptr = nullptr;
|
|
|
|
int _getters_count = 0;
|
|
|
|
const Variant::ValidatedGetter *_getters_ptr = nullptr;
|
|
|
|
int _keyed_setters_count = 0;
|
|
|
|
const Variant::ValidatedKeyedSetter *_keyed_setters_ptr = nullptr;
|
|
|
|
int _keyed_getters_count = 0;
|
|
|
|
const Variant::ValidatedKeyedGetter *_keyed_getters_ptr = nullptr;
|
|
|
|
int _indexed_setters_count = 0;
|
|
|
|
const Variant::ValidatedIndexedSetter *_indexed_setters_ptr = nullptr;
|
|
|
|
int _indexed_getters_count = 0;
|
|
|
|
const Variant::ValidatedIndexedGetter *_indexed_getters_ptr = nullptr;
|
2020-11-18 14:32:28 +01:00
|
|
|
int _builtin_methods_count = 0;
|
|
|
|
const Variant::ValidatedBuiltInMethod *_builtin_methods_ptr = nullptr;
|
2020-11-18 15:37:08 +01:00
|
|
|
int _constructors_count = 0;
|
|
|
|
const Variant::ValidatedConstructor *_constructors_ptr = nullptr;
|
2020-11-17 14:44:52 +01:00
|
|
|
int _methods_count = 0;
|
|
|
|
MethodBind **_methods_ptr = nullptr;
|
2020-11-13 14:31:14 +01:00
|
|
|
const int *_code_ptr = nullptr;
|
|
|
|
int _code_size = 0;
|
|
|
|
int _argument_count = 0;
|
|
|
|
int _stack_size = 0;
|
|
|
|
int _instruction_args_size = 0;
|
2020-11-17 14:44:52 +01:00
|
|
|
int _ptrcall_args_size = 0;
|
|
|
|
|
2020-11-13 14:31:14 +01:00
|
|
|
int _initial_line = 0;
|
|
|
|
bool _static = false;
|
|
|
|
MultiplayerAPI::RPCMode rpc_mode = MultiplayerAPI::RPC_MODE_DISABLED;
|
|
|
|
|
|
|
|
GDScript *_script = nullptr;
|
2016-06-01 03:28:27 +02:00
|
|
|
|
|
|
|
StringName name;
|
|
|
|
Vector<Variant> constants;
|
|
|
|
Vector<StringName> global_names;
|
|
|
|
Vector<int> default_arguments;
|
2020-11-13 20:47:45 +01:00
|
|
|
Vector<Variant::ValidatedOperatorEvaluator> operator_funcs;
|
2020-11-16 16:59:53 +01:00
|
|
|
Vector<Variant::ValidatedSetter> setters;
|
|
|
|
Vector<Variant::ValidatedGetter> getters;
|
|
|
|
Vector<Variant::ValidatedKeyedSetter> keyed_setters;
|
|
|
|
Vector<Variant::ValidatedKeyedGetter> keyed_getters;
|
|
|
|
Vector<Variant::ValidatedIndexedSetter> indexed_setters;
|
|
|
|
Vector<Variant::ValidatedIndexedGetter> indexed_getters;
|
2020-11-18 14:32:28 +01:00
|
|
|
Vector<Variant::ValidatedBuiltInMethod> builtin_methods;
|
2020-11-18 15:37:08 +01:00
|
|
|
Vector<Variant::ValidatedConstructor> constructors;
|
2020-11-17 14:44:52 +01:00
|
|
|
Vector<MethodBind *> methods;
|
2016-06-01 03:28:27 +02:00
|
|
|
Vector<int> code;
|
2018-05-30 04:16:54 +02:00
|
|
|
Vector<GDScriptDataType> argument_types;
|
|
|
|
GDScriptDataType return_type;
|
2016-06-01 03:28:27 +02:00
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
Vector<StringName> arg_names;
|
2020-11-29 03:37:57 +01:00
|
|
|
Vector<Variant> default_arg_values;
|
2016-06-01 03:28:27 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
List<StackDebug> stack_debug;
|
|
|
|
|
2020-02-19 13:15:16 +01:00
|
|
|
_FORCE_INLINE_ Variant *_get_variant(int p_address, GDScriptInstance *p_instance, GDScript *p_script, Variant &self, Variant &static_ref, Variant *p_stack, String &r_error) const;
|
2020-02-19 20:27:19 +01:00
|
|
|
_FORCE_INLINE_ String _get_call_error(const Callable::CallError &p_err, const String &p_where, const Variant **argptrs) const;
|
2016-06-01 03:28:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
friend class GDScriptLanguage;
|
2016-06-01 03:28:27 +02:00
|
|
|
|
2020-11-13 14:31:14 +01:00
|
|
|
SelfList<GDScriptFunction> function_list{ this };
|
2016-06-01 03:28:27 +02:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
CharString func_cname;
|
2020-11-13 14:31:14 +01:00
|
|
|
const char *_func_cname = nullptr;
|
2016-06-01 03:28:27 +02:00
|
|
|
|
|
|
|
struct Profile {
|
|
|
|
StringName signature;
|
2020-11-13 14:31:14 +01:00
|
|
|
uint64_t call_count = 0;
|
|
|
|
uint64_t self_time = 0;
|
|
|
|
uint64_t total_time = 0;
|
|
|
|
uint64_t frame_call_count = 0;
|
|
|
|
uint64_t frame_self_time = 0;
|
|
|
|
uint64_t frame_total_time = 0;
|
|
|
|
uint64_t last_frame_call_count = 0;
|
|
|
|
uint64_t last_frame_self_time = 0;
|
|
|
|
uint64_t last_frame_total_time = 0;
|
2016-06-01 03:28:27 +02:00
|
|
|
} profile;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
|
|
|
struct CallState {
|
2020-05-05 12:53:05 +02:00
|
|
|
GDScript *script;
|
|
|
|
GDScriptInstance *instance;
|
2020-04-29 13:38:00 +02:00
|
|
|
#ifdef DEBUG_ENABLED
|
2020-05-05 12:53:05 +02:00
|
|
|
StringName function_name;
|
2020-04-29 13:38:00 +02:00
|
|
|
String script_path;
|
|
|
|
#endif
|
2016-06-01 03:28:27 +02:00
|
|
|
Vector<uint8_t> stack;
|
|
|
|
int stack_size;
|
|
|
|
Variant self;
|
|
|
|
uint32_t alloca_size;
|
|
|
|
int ip;
|
|
|
|
int line;
|
|
|
|
int defarg;
|
|
|
|
Variant result;
|
|
|
|
};
|
|
|
|
|
|
|
|
_FORCE_INLINE_ bool is_static() const { return _static; }
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const int *get_code() const; //used for debug
|
2016-06-01 03:28:27 +02:00
|
|
|
int get_code_size() const;
|
|
|
|
Variant get_constant(int p_idx) const;
|
|
|
|
StringName get_global_name(int p_idx) const;
|
|
|
|
StringName get_name() const;
|
|
|
|
int get_max_stack_size() const;
|
|
|
|
int get_default_argument_count() const;
|
|
|
|
int get_default_argument_addr(int p_idx) const;
|
2018-05-30 04:16:54 +02:00
|
|
|
GDScriptDataType get_return_type() const;
|
|
|
|
GDScriptDataType get_argument_type(int p_idx) const;
|
2018-11-24 23:46:13 +01:00
|
|
|
GDScript *get_script() const { return _script; }
|
2016-06-28 16:49:18 +02:00
|
|
|
StringName get_source() const { return source; }
|
2016-06-01 03:28:27 +02:00
|
|
|
|
2020-03-17 07:33:00 +01:00
|
|
|
void debug_get_stack_member_state(int p_line, List<Pair<StringName, int>> *r_stackvars) const;
|
2016-06-01 03:28:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ bool is_empty() const { return _code_size == 0; }
|
2016-06-01 03:28:27 +02:00
|
|
|
|
|
|
|
int get_argument_count() const { return _argument_count; }
|
|
|
|
StringName get_argument_name(int p_idx) const {
|
|
|
|
#ifdef TOOLS_ENABLED
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, arg_names.size(), StringName());
|
2016-06-01 03:28:27 +02:00
|
|
|
return arg_names[p_idx];
|
2017-08-22 19:01:57 +02:00
|
|
|
#else
|
2016-06-01 03:28:27 +02:00
|
|
|
return StringName();
|
2017-08-22 19:01:57 +02:00
|
|
|
#endif
|
2016-06-01 03:28:27 +02:00
|
|
|
}
|
|
|
|
Variant get_default_argument(int p_idx) const {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, default_arguments.size(), Variant());
|
2016-06-01 03:28:27 +02:00
|
|
|
return default_arguments[p_idx];
|
|
|
|
}
|
2020-11-29 03:37:57 +01:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
const Vector<Variant> &get_default_arg_values() const {
|
|
|
|
return default_arg_values;
|
|
|
|
}
|
|
|
|
#endif // TOOLS_ENABLED
|
2016-06-01 03:28:27 +02:00
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
Variant call(GDScriptInstance *p_instance, const Variant **p_args, int p_argcount, Callable::CallError &r_err, CallState *p_state = nullptr);
|
2016-06-01 03:28:27 +02:00
|
|
|
|
2020-08-17 15:00:42 +02:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
void disassemble(const Vector<String> &p_code_lines) const;
|
|
|
|
#endif
|
|
|
|
|
2018-05-13 07:07:56 +02:00
|
|
|
_FORCE_INLINE_ MultiplayerAPI::RPCMode get_rpc_mode() const { return rpc_mode; }
|
2017-11-16 18:38:18 +01:00
|
|
|
GDScriptFunction();
|
|
|
|
~GDScriptFunction();
|
2016-06-01 03:28:27 +02:00
|
|
|
};
|
|
|
|
|
2017-11-16 18:38:18 +01:00
|
|
|
class GDScriptFunctionState : public Reference {
|
|
|
|
GDCLASS(GDScriptFunctionState, Reference);
|
|
|
|
friend class GDScriptFunction;
|
|
|
|
GDScriptFunction *function;
|
|
|
|
GDScriptFunction::CallState state;
|
2020-02-19 20:27:19 +01:00
|
|
|
Variant _signal_callback(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
|
2018-06-28 17:40:11 +02:00
|
|
|
Ref<GDScriptFunctionState> first_state;
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2020-05-05 12:53:05 +02:00
|
|
|
SelfList<GDScriptFunctionState> scripts_list;
|
|
|
|
SelfList<GDScriptFunctionState> instances_list;
|
|
|
|
|
2016-06-01 03:28:27 +02:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2017-05-17 14:47:17 +02:00
|
|
|
bool is_valid(bool p_extended_check = false) const;
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant resume(const Variant &p_arg = Variant());
|
2020-05-05 12:53:05 +02:00
|
|
|
|
|
|
|
void _clear_stack();
|
|
|
|
|
2017-11-16 18:38:18 +01:00
|
|
|
GDScriptFunctionState();
|
|
|
|
~GDScriptFunctionState();
|
2016-06-01 03:28:27 +02:00
|
|
|
};
|
|
|
|
|
2017-11-16 18:38:18 +01:00
|
|
|
#endif // GDSCRIPT_FUNCTION_H
|