summaryrefslogtreecommitdiff
path: root/modules/gdscript/gd_compiler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdscript/gd_compiler.cpp')
-rw-r--r--modules/gdscript/gd_compiler.cpp83
1 files changed, 77 insertions, 6 deletions
diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gd_compiler.cpp
index 7483af298c..398c2cf82a 100644
--- a/modules/gdscript/gd_compiler.cpp
+++ b/modules/gdscript/gd_compiler.cpp
@@ -1099,7 +1099,72 @@ Error GDCompiler::_parse_block(CodeGen& codegen,const GDParser::BlockNode *p_blo
switch(cf->cf_type) {
-
+ case GDParser::ControlFlowNode::CF_MATCH: {
+ GDParser::MatchNode *match = cf->match;
+
+ GDParser::IdentifierNode *id = memnew(GDParser::IdentifierNode);
+ id->name = "#match_value";
+
+ // var #match_value
+ // copied because there is no _parse_statement :(
+ codegen.add_stack_identifier(id->name, p_stack_level++);
+ codegen.alloc_stack(p_stack_level);
+ new_identifiers++;
+
+ GDParser::OperatorNode *op = memnew(GDParser::OperatorNode);
+ op->op=GDParser::OperatorNode::OP_ASSIGN;
+ op->arguments.push_back(id);
+ op->arguments.push_back(match->val_to_match);
+
+ int ret = _parse_expression(codegen, op, p_stack_level);
+ if (ret < 0) {
+ return ERR_PARSE_ERROR;
+ }
+
+ // break address
+ codegen.opcodes.push_back(GDFunction::OPCODE_JUMP);
+ codegen.opcodes.push_back(codegen.opcodes.size() + 3);
+ int break_addr = codegen.opcodes.size();
+ codegen.opcodes.push_back(GDFunction::OPCODE_JUMP);
+ codegen.opcodes.push_back(0); // break addr
+
+ for (int j = 0; j < match->compiled_pattern_branches.size(); j++) {
+ GDParser::MatchNode::CompiledPatternBranch branch = match->compiled_pattern_branches[j];
+
+ // jump over continue
+ // jump unconditionally
+ // continue address
+ // compile the condition
+ int ret = _parse_expression(codegen, branch.compiled_pattern, p_stack_level);
+ if (ret < 0) {
+ return ERR_PARSE_ERROR;
+ }
+
+ codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_IF);
+ codegen.opcodes.push_back(ret);
+ codegen.opcodes.push_back(codegen.opcodes.size() + 3);
+ int continue_addr = codegen.opcodes.size();
+ codegen.opcodes.push_back(GDFunction::OPCODE_JUMP);
+ codegen.opcodes.push_back(0);
+
+
+
+ Error err = _parse_block(codegen, branch.body, p_stack_level, p_break_addr, continue_addr);
+ if (err) {
+ return ERR_PARSE_ERROR;
+ }
+
+ codegen.opcodes.push_back(GDFunction::OPCODE_JUMP);
+ codegen.opcodes.push_back(break_addr);
+
+ codegen.opcodes[continue_addr + 1] = codegen.opcodes.size();
+ }
+
+ codegen.opcodes[break_addr + 1] = codegen.opcodes.size();
+
+
+ } break;
+
case GDParser::ControlFlowNode::CF_IF: {
#ifdef DEBUG_ENABLED
@@ -1420,9 +1485,10 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode *
GDFunction *gdfunc=NULL;
- //if (String(p_func->name)=="") { //initializer func
- // gdfunc = &p_script->initializer;
-
+ /*
+ if (String(p_func->name)=="") { //initializer func
+ gdfunc = &p_script->initializer;
+ */
//} else { //regular func
p_script->member_functions[func_name]=memnew(GDFunction);
gdfunc = p_script->member_functions[func_name];
@@ -1510,7 +1576,7 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode *
//funciton and class
if (p_class->name) {
- signature+="::"+String(p_class->name)+"."+String(func_name);;
+ signature+="::"+String(p_class->name)+"."+String(func_name);
} else {
signature+="::"+String(func_name);
}
@@ -1729,9 +1795,14 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa
}
+ }else {
+ // without extends, implicitly extend Reference
+ int native_idx = GDScriptLanguage::get_singleton()->get_global_map()["Reference"];
+ native = GDScriptLanguage::get_singleton()->get_global_array()[native_idx];
+ ERR_FAIL_COND_V(native.is_null(), ERR_BUG);
+ p_script->native=native;
}
-
//print_line("Script: "+p_script->get_path()+" indices: "+itos(p_script->member_indices.size()));