private void CEFunctionCall(Parse.FunctionCall Item, Parse.Block Parent, Block Compiled) { int first_runnable_execution_index = Compiled.Count; //Clear any temps that are left if (Item.Arguments.Count > 0) { Compiled.AddItem(new PushTemporariesCount()); } //Get the arguments foreach (var el in Item.Arguments) { //Get the argument CompileElement(el, Parent, Compiled); //Push in temprary Compiled.AddItem(new ResultToTemp()); } //Get the arguments and call the function var tar = Item.Target; if (!Functions.ContainsKey(tar)) { var fun = new Function(tar.ArgumentsCount, tar.Variables.Count, Item.Name); Functions.Add(tar, fun); //Create a unique function name (functions from imports may define same named functions if (IDE.ExecutionTree.Functions.ContainsKey(tar.Name)) { var i = 1; string new_name; do { new_name = string.Format("{0}_{1}", tar.Name, i); i++; } while (IDE.ExecutionTree.Functions.ContainsKey(new_name)); IDE.ExecutionTree.Functions.Add(new_name, fun); } else { IDE.ExecutionTree.Functions.Add(tar.Name, fun); } //Compile the function ComplileFunction(tar); IDE.CompiledAnnotations.Add(tar.Annotation.CompiledPosition, tar.Annotation); } Compiled.AddItem(new CallFunction(Functions[tar])); int last_runnable_execution_index = Compiled.Count - 1; //Clear any temps that are left if (Item.Arguments.Count > 0) { var ct = new PopClearTemporaries(); Compiled.AddItem(ct); CESetOnJumpFailTo(Compiled, first_runnable_execution_index, last_runnable_execution_index, ct); } }
private void CEFunctionCall(Parse.FunctionCall Item, Parse.Block Parent, Block Compiled) { int first_runnable_execution_index = Compiled.Count; //Clear any temps that are left if (Item.Arguments.Count > 0) Compiled.AddItem(new PushTemporariesCount()); //Get the arguments foreach (var el in Item.Arguments) { //Get the argument CompileElement(el, Parent, Compiled); //Push in temprary Compiled.AddItem(new ResultToTemp()); } //Get the arguments and call the function var tar = Item.Target; if (!Functions.ContainsKey(tar)) { var fun = new Function(tar.ArgumentsCount, tar.Variables.Count, Item.Name); Functions.Add(tar, fun); //Create a unique function name (functions from imports may define same named functions if (IDE.ExecutionTree.Functions.ContainsKey(tar.Name)) { var i = 1; string new_name; do { new_name = string.Format("{0}_{1}", tar.Name, i); i++; } while (IDE.ExecutionTree.Functions.ContainsKey(new_name)); IDE.ExecutionTree.Functions.Add(new_name, fun); } else IDE.ExecutionTree.Functions.Add(tar.Name, fun); //Compile the function ComplileFunction(tar); IDE.CompiledAnnotations.Add(tar.Annotation.CompiledPosition, tar.Annotation); } Compiled.AddItem(new CallFunction(Functions[tar])); int last_runnable_execution_index = Compiled.Count - 1; //Clear any temps that are left if (Item.Arguments.Count > 0) { var ct = new PopClearTemporaries(); Compiled.AddItem(ct); CESetOnJumpFailTo(Compiled, first_runnable_execution_index, last_runnable_execution_index, ct); } }
private void CEBinaryOperator(Parse.BinaryOperator Item, Parse.Block Parent, Block Compiled) { //Get left element CompileElement(Item.lhs, Parent, Compiled); //If not pipe then push left and get right element if (Item.Type != Parse.BinaryOperator.eType.Pipe) { //Clear any temps that are left Compiled.AddItem(new PushTemporariesCount()); //Push it to temp Compiled.AddItem(new ResultToTemp()); var first_runnable_execute_index = Compiled.Count; //Get right element CompileElement(Item.rhs, Parent, Compiled); var last_runnable_execute_index = Compiled.Count - 1; //Clear any temps that are left var ct = new PopClearTemporaries(); Compiled.AddItem(ct); CESetOnJumpFailTo(Compiled, first_runnable_execute_index, last_runnable_execute_index, ct); } //Apply operator switch (Item.Type) { case Parse.BinaryOperator.eType.Equal: Compiled.AddItem(new ResultTextEqualTempText(true, Item.IgnoreCase)); break; case Parse.BinaryOperator.eType.NotEqual: Compiled.AddItem(new ResultTextEqualTempText(false, Item.IgnoreCase)); break; case Parse.BinaryOperator.eType.ReferenceEqual: Compiled.AddItem(new ResultNodeEqualTempNode(true)); break; case Parse.BinaryOperator.eType.ReferenceNotEqual: Compiled.AddItem(new ResultNodeEqualTempNode(false)); break; case Parse.BinaryOperator.eType.ReferenceCopy: Compiled.AddItem(new ResultNodeToTempVariable()); break; case Parse.BinaryOperator.eType.TextAppend: Compiled.AddItem(new ResultTextAppendToTempText()); break; case Parse.BinaryOperator.eType.TreeAppend: Compiled.AddItem(new ResultNodeAppendToTempNode()); break; case Parse.BinaryOperator.eType.TildeAppend: Compiled.AddItem(new TempTextAppendToResultNode()); break; case Parse.BinaryOperator.eType.Tilde: Compiled.AddItem(new TempTextToResultNode()); break; case Parse.BinaryOperator.eType.Pipe: //Save Source Compiled.AddItem(new SourceAndSkippedToTemp()); //Change Source Compiled.AddItem(new ResultToSource()); var first_runnable_execute_index = Compiled.Count; //Get right element CompileElement(Item.rhs, Parent, Compiled); var last_runnable_execute_index = Compiled.Count - 1; //Get Source back var tts = new TempToSourceAndSkipped(); Compiled.AddItem(tts); //Get Source back if anything fails CESetOnJumpFailTo(Compiled, first_runnable_execute_index, last_runnable_execute_index, tts); ////Save Source //Compiled.AddItem(new NextToSource()); ////Change source //Compiled.AddItem(new ResultToNext()); ////Get right element //CompileElement(Item.rhs, Parent, Compiled); ////Get source back //Compiled.AddItem(new SourceToNext()); break; default: ThrowParseError("Unknown type", Item.Annotation.SourcePosition); break; } }