Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        public bool Compile()
        {
            Clear();
            if ((IDE == null) || (IDE.GrammarTree == null))
            {
                return(false);
            }

            var gt = IDE.GrammarTree;

            if (gt.ParseErrors.Count > 0)
            {
                return(false);
            }

            //Functions = IDE.ExecutionTree.Functions;
            SyntaxOccurences = IDE.CompiledSyntaxOccurences;
            IDE.CompiledAnnotations.Clear();
            IDE.ExecutionTree.Clear();

            //Create functions stubs
            foreach (var parse_function in gt.Functions)
            {
                var fun = new Function(parse_function.ArgumentsCount, parse_function.Variables.Count, parse_function.Name);
                Functions.Add(parse_function, fun);
                IDE.ExecutionTree.Functions.Add(parse_function.Name, fun);

                //Create variable names list
                fun.VariablesNames = new Dictionary <int, string>(fun.VariablesAndArgumentsCount);
                foreach (var var in parse_function.Variables)
                {
                    fun.VariablesNames[var.Value] = var.Key;
                }
            }

            //Compile functions
            foreach (var fun in gt.Functions)
            {
                ComplileFunction(fun);
                IDE.CompiledAnnotations.Add(fun.Annotation.CompiledPosition, fun.Annotation);
            }

            IDE.AssemblyOutput = Output.ToString();

            IDE.ExecutionTree.MaxFunctionVariables = IDE.GrammarTree.MaxFunctionVariables;

            return(true);
        }
        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);
            }
        }
        public bool Compile()
        {
            Clear();
            if ((IDE == null) || (IDE.GrammarTree == null))
                return false;

            var gt = IDE.GrammarTree;

            if (gt.ParseErrors.Count > 0)
                return false;

            //Functions = IDE.ExecutionTree.Functions;
            SyntaxOccurences = IDE.CompiledSyntaxOccurences;
            IDE.CompiledAnnotations.Clear();
            IDE.ExecutionTree.Clear();

            //Create functions stubs
            foreach (var parse_function in gt.Functions)
            {
                var fun = new Function(parse_function.ArgumentsCount, parse_function.Variables.Count, parse_function.Name);
                Functions.Add(parse_function, fun);
                IDE.ExecutionTree.Functions.Add(parse_function.Name, fun);

                //Create variable names list
                fun.VariablesNames = new Dictionary<int, string>(fun.VariablesAndArgumentsCount);
                foreach (var var in parse_function.Variables)
                    fun.VariablesNames[var.Value] = var.Key;
            }

            //Compile functions
            foreach (var fun in gt.Functions)
            {
                ComplileFunction(fun);
                IDE.CompiledAnnotations.Add(fun.Annotation.CompiledPosition, fun.Annotation);
            }

            IDE.AssemblyOutput = Output.ToString();

            IDE.ExecutionTree.MaxFunctionVariables = IDE.GrammarTree.MaxFunctionVariables;

            return true;
        }