From c8579ef63f2ae71bd9f82bda57d7ef2fffc2b7fd Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 13 Jul 2022 00:38:23 +0200 Subject: [PATCH] Removed yield from cscript. --- modules/cscript/cscript.cpp | 27 -- modules/cscript/cscript.h | 8 - modules/cscript/cscript_compiler.cpp | 26 -- modules/cscript/cscript_editor.cpp | 78 +---- modules/cscript/cscript_function.cpp | 405 ++++---------------------- modules/cscript/cscript_function.h | 29 +- modules/cscript/cscript_parser.cpp | 115 -------- modules/cscript/cscript_parser.h | 6 - modules/cscript/cscript_tokenizer.cpp | 3 - modules/cscript/cscript_tokenizer.h | 1 - modules/cscript/register_types.cpp | 1 - 11 files changed, 64 insertions(+), 635 deletions(-) diff --git a/modules/cscript/cscript.cpp b/modules/cscript/cscript.cpp index 558ff2623..f3b5ff4c0 100644 --- a/modules/cscript/cscript.cpp +++ b/modules/cscript/cscript.cpp @@ -77,17 +77,6 @@ Object *CScriptNativeClass::instance() { return ClassDB::instance(name); } -void CScript::_clear_pending_func_states() { - CScriptLanguage::get_singleton()->lock.lock(); - while (SelfList *E = pending_func_states.first()) { - // Order matters since clearing the stack may already cause - // the CSCriptFunctionState to be destroyed and thus removed from the list. - pending_func_states.remove(E); - E->self()->_clear_stack(); - } - CScriptLanguage::get_singleton()->lock.unlock(); -} - CScriptInstance *CScript::_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_isref, Variant::CallError &r_error) { /* STEP 1, CREATE */ @@ -628,7 +617,6 @@ Error CScript::reload(bool p_keep_state) { for (Map>::Element *E = subclasses.front(); E; E = E->next()) { _set_subclass_path(E->get(), path); } - _clear_pending_func_states(); return OK; } @@ -955,8 +943,6 @@ void CScript::_save_orphaned_subclasses() { } CScript::~CScript() { - _clear_pending_func_states(); - for (Map::Element *E = member_functions.front(); E; E = E->next()) { memdelete(E->get()); } @@ -1328,13 +1314,6 @@ CScriptInstance::CScriptInstance() { CScriptInstance::~CScriptInstance() { CScriptLanguage::singleton->lock.lock(); - while (SelfList *E = pending_func_states.first()) { - // Order matters since clearing the stack may already cause - // the CSCriptFunctionState to be destroyed and thus removed from the list. - pending_func_states.remove(E); - E->self()->_clear_stack(); - } - if (script.is_valid() && owner) { script->instances.erase(owner); } @@ -1742,7 +1721,6 @@ void CScriptLanguage::get_reserved_words(List *p_words) const { "setget", "signal", "tool", - "yield", // var "const", "enum", @@ -1930,10 +1908,6 @@ String CScriptWarning::get_message() const { case NARROWING_CONVERSION: { return "Narrowing conversion (float is converted to int and loses precision)."; } break; - case FUNCTION_MAY_YIELD: { - CHECK_SYMBOLS(1); - return "Assigned variable is typed but the function '" + symbols[0] + "()' may yield and return a CScriptFunctionState instead."; - } break; case VARIABLE_CONFLICTS_FUNCTION: { CHECK_SYMBOLS(1); return "Variable declaration of '" + symbols[0] + "' conflicts with a function of the same name."; @@ -2025,7 +1999,6 @@ String CScriptWarning::get_name_from_code(Code p_code) { "STANDALONE_EXPRESSION", "VOID_ASSIGNMENT", "NARROWING_CONVERSION", - "FUNCTION_MAY_YIELD", "VARIABLE_CONFLICTS_FUNCTION", "FUNCTION_CONFLICTS_VARIABLE", "FUNCTION_CONFLICTS_CONSTANT", diff --git a/modules/cscript/cscript.h b/modules/cscript/cscript.h index 0c613652f..947f3f1ec 100644 --- a/modules/cscript/cscript.h +++ b/modules/cscript/cscript.h @@ -109,9 +109,6 @@ class CScript : public Script { String fully_qualified_name; SelfList script_list; - SelfList::List pending_func_states; - void _clear_pending_func_states(); - CScriptInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_isref, Variant::CallError &r_error); void _set_subclass_path(Ref &p_sc, const String &p_path); @@ -258,8 +255,6 @@ class CScriptInstance : public ScriptInstance { Vector members; bool base_ref; - SelfList::List pending_func_states; - void _ml_call_reversed(CScript *sptr, const StringName &p_method, const Variant **p_args, int p_argcount); public: @@ -311,7 +306,6 @@ struct CScriptWarning { STANDALONE_EXPRESSION, // Expression not assigned to a variable VOID_ASSIGNMENT, // Function returns void but it's assigned to a variable NARROWING_CONVERSION, // Float value into an integer slot, precision is lost - FUNCTION_MAY_YIELD, // Typed assign of function call that yields (it may return a function state) VARIABLE_CONFLICTS_FUNCTION, // Variable has the same name of a function FUNCTION_CONFLICTS_VARIABLE, // Function has the same name of a variable FUNCTION_CONFLICTS_CONSTANT, // Function has the same name of a constant @@ -346,8 +340,6 @@ struct CScriptWarning { #endif // DEBUG_ENABLED class CScriptLanguage : public ScriptLanguage { - friend class CScriptFunctionState; - static CScriptLanguage *singleton; Variant *_global_array; diff --git a/modules/cscript/cscript_compiler.cpp b/modules/cscript/cscript_compiler.cpp index 74f7d9d0e..33bcfcfa8 100644 --- a/modules/cscript/cscript_compiler.cpp +++ b/modules/cscript/cscript_compiler.cpp @@ -676,32 +676,6 @@ int CScriptCompiler::_parse_expression(CodeGen &codegen, const CScriptParser::No } } } break; - case CScriptParser::OperatorNode::OP_YIELD: { - ERR_FAIL_COND_V(on->arguments.size() && on->arguments.size() != 2, -1); - - Vector arguments; - int slevel = p_stack_level; - for (int i = 0; i < on->arguments.size(); i++) { - int ret = _parse_expression(codegen, on->arguments[i], slevel); - if (ret < 0) { - return ret; - } - if ((ret >> CScriptFunction::ADDR_BITS & CScriptFunction::ADDR_TYPE_STACK) == CScriptFunction::ADDR_TYPE_STACK) { - slevel++; - codegen.alloc_stack(slevel); - } - arguments.push_back(ret); - } - - //push call bytecode - codegen.opcodes.push_back(arguments.size() == 0 ? CScriptFunction::OPCODE_YIELD : CScriptFunction::OPCODE_YIELD_SIGNAL); // basic type constructor - for (int i = 0; i < arguments.size(); i++) { - codegen.opcodes.push_back(arguments[i]); //arguments - } - codegen.opcodes.push_back(CScriptFunction::OPCODE_YIELD_RESUME); - //next will be where to place the result :) - - } break; //indexing operator case CScriptParser::OperatorNode::OP_INDEX: diff --git a/modules/cscript/cscript_editor.cpp b/modules/cscript/cscript_editor.cpp index 46f5ddf83..e0d7d3ba6 100644 --- a/modules/cscript/cscript_editor.cpp +++ b/modules/cscript/cscript_editor.cpp @@ -391,16 +391,6 @@ void CScriptLanguage::get_public_functions(List *p_functions) const mi.return_val = PropertyInfo(Variant::OBJECT, "", PROPERTY_HINT_RESOURCE_TYPE, "Resource"); p_functions->push_back(mi); } - { - MethodInfo mi; - mi.name = "yield"; - mi.arguments.push_back(PropertyInfo(Variant::OBJECT, "object")); - mi.arguments.push_back(PropertyInfo(Variant::STRING, "signal")); - mi.default_arguments.push_back(Variant()); - mi.default_arguments.push_back(String()); - mi.return_val = PropertyInfo(Variant::OBJECT, "", PROPERTY_HINT_RESOURCE_TYPE, "CScriptFunctionState"); - p_functions->push_back(mi); - } { MethodInfo mi; mi.name = "assert"; @@ -2193,7 +2183,7 @@ static void _find_identifiers(const CScriptCompletionContext &p_context, bool p_ static const char *_keywords[] = { "and", "in", "not", "or", "false", "PI", "TAU", "INF", "NAN", "self", "true", "as", "assert", - "breakpoint", "class", "extends", "is", "func", "preload", "setget", "signal", "tool", "yield", + "breakpoint", "class", "extends", "is", "func", "preload", "setget", "signal", "tool", "const", "enum", "export", "onready", "static", "var", "break", "continue", "if", "elif", "else", "for", "pass", "return", "match", "while", nullptr @@ -2771,72 +2761,6 @@ Error CScriptLanguage::complete_code(const String &p_code, const String &p_path, options.insert(option.display, option); } } break; - case CScriptParser::COMPLETION_YIELD: { - const CScriptParser::Node *node = parser.get_completion_node(); - - CScriptCompletionContext c = context; - c.line = node->line; - CScriptCompletionIdentifier type; - if (!_guess_expression_type(c, node, type)) { - break; - } - - CScriptParser::DataType base_type = type.type; - while (base_type.has_type) { - switch (base_type.kind) { - case CScriptParser::DataType::CLASS: { - for (int i = 0; i < base_type.class_type->_signals.size(); i++) { - ScriptCodeCompletionOption option(base_type.class_type->_signals[i].name.operator String(), ScriptCodeCompletionOption::KIND_SIGNAL); - option.insert_text = quote_style + option.display + quote_style; - options.insert(option.display, option); - } - base_type = base_type.class_type->base_type; - } break; - case CScriptParser::DataType::SCRIPT: - case CScriptParser::DataType::CSCRIPT: { - Ref