/*************************************************************************/ /* gdscript_vm.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* 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. */ /*************************************************************************/ #include "gdscript_function.h" #include "core/core_string_names.h" #include "core/os/os.h" #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