public void Run(AstUseInheritanceStatement statement)
        {
#if DEBUG
            //Log($"statement = {statement}");
#endif

            CompileValue(statement.SubName);
            CompileValue(statement.SuperName);
            CompileValue(statement.Rank);

            var command = new IntermediateScriptCommand();
            command.OperationCode = OperationCode.PushVal;
            command.Value         = statement.GetAnnotationValue();

            AddCommand(command);

            command = new IntermediateScriptCommand();

            if (statement.HasNot)
            {
                command.OperationCode = OperationCode.UseNotInheritance;
            }
            else
            {
                command.OperationCode = OperationCode.UseInheritance;
            }

            AddCommand(command);

            AddCommand(new IntermediateScriptCommand()
            {
                OperationCode = OperationCode.ClearStack
            });
        }
Beispiel #2
0
        protected void CompilePushVal(Value value)
        {
            var command = new IntermediateScriptCommand();

            command.OperationCode = OperationCode.PushVal;
            command.Value         = value;

            AddCommand(command);
        }
Beispiel #3
0
        protected void CompilePushAnnotation(AnnotatedItem annotatedItem)
        {
            var command = new IntermediateScriptCommand();

            command.OperationCode = OperationCode.PushVal;
            command.Value         = annotatedItem.GetAnnotationValue();

            AddCommand(command);
        }
Beispiel #4
0
        public void Run(AstErrorStatement statement)
        {
#if DEBUG
            //Log($"statement = {statement}");
#endif

            CompileValue(statement.RuleInstanceValue);

            var command = new IntermediateScriptCommand();
            command.OperationCode = OperationCode.Error;
            AddCommand(command);

            //throw new NotImplementedException();
        }
Beispiel #5
0
        private void RunAssignBinaryOperator(BinaryOperatorAstExpression expression)
        {
#if DEBUG
            //Log($"expression = {expression}");
#endif

            var rightBranch = expression.Right;

#if DEBUG
            //Log($"rightBranch = {rightBranch}");
#endif

            if (rightBranch.Kind == KindOfAstExpression.ConstValue)
            {
                var rightNode = new ExpressionNode(_context);
                rightNode.Run(rightBranch);
                AddCommands(rightNode.Result);
            }
            else
            {
                var command = new IntermediateScriptCommand();
                command.OperationCode = OperationCode.PushValToVar;
                command.Value         = (rightBranch as VarAstExpression).Name;

                AddCommand(command);
            }

            var leftBranch = expression.Left;

#if DEBUG
            //Log($"leftBranch = {leftBranch}");
#endif

            if (leftBranch.Kind == KindOfAstExpression.Var)
            {
                var command = new IntermediateScriptCommand();
                command.OperationCode = OperationCode.PushValToVar;
                command.Value         = (leftBranch as VarAstExpression).Name;

                AddCommand(command);
            }
            else
            {
                var rightNode = new ExpressionNode(_context);
                rightNode.Run(leftBranch);
                AddCommands(rightNode.Result);
            }
        }
Beispiel #6
0
        public void Run(UnaryOperatorAstExpression expression)
        {
#if DEBUG
            //Log($"expression = {expression}");
#endif

            var leftNode = new ExpressionNode(_context);
            leftNode.Run(expression.Left);
            AddCommands(leftNode.Result);

            CompilePushAnnotation(expression);


            var command = new IntermediateScriptCommand();
            command.OperationCode  = OperationCode.CallUnOp;
            command.KindOfOperator = expression.KindOfOperator;

            AddCommand(command);
        }
Beispiel #7
0
        private void RunUsualBinaryOperator(BinaryOperatorAstExpression expression)
        {
            var leftNode = new ExpressionNode(_context);

            leftNode.Run(expression.Left);
            AddCommands(leftNode.Result);

            var rightNode = new ExpressionNode(_context);

            rightNode.Run(expression.Right);
            AddCommands(rightNode.Result);

            CompilePushAnnotation(expression);

            var command = new IntermediateScriptCommand();

            command.OperationCode  = OperationCode.CallBinOp;
            command.KindOfOperator = expression.KindOfOperator;

            AddCommand(command);
        }
Beispiel #8
0
        protected void CompileValue(Value value)
        {
#if DEBUG
            //Log($"value = {value}");
#endif

            if (value.IsStrongIdentifierValue)
            {
                var name = value.AsStrongIdentifierValue;

                var kindOfName = name.KindOfName;

                switch (kindOfName)
                {
                case KindOfName.Concept:
                case KindOfName.Channel:
                case KindOfName.Entity:
                    CompilePushVal(value);
                    break;

                case KindOfName.SystemVar:
                case KindOfName.Var:
                    CompilePushValFromVar(value);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(kindOfName), kindOfName, null);
                }

                return;
            }

            var command = new IntermediateScriptCommand();
            command.OperationCode = OperationCode.PushVal;
            command.Value         = value;

            AddCommand(command);
        }
Beispiel #9
0
 protected void AddCommand(IntermediateScriptCommand command)
 {
     _result.Add(command);
 }
Beispiel #10
0
        public void Run(AstTryStatement statement)
        {
#if DEBUG
            //Log($"statement = {statement}");
#endif

            IntermediateScriptCommand firstElseCommand  = null;
            IntermediateScriptCommand firstEnsureComand = null;
            var afterCommand = new IntermediateScriptCommand()
            {
                OperationCode = OperationCode.Nop
            };

            if (!statement.ElseStatements.IsNullOrEmpty())
            {
                firstElseCommand = new IntermediateScriptCommand()
                {
                    OperationCode = OperationCode.Nop
                };
            }

            if (!statement.EnsureStatements.IsNullOrEmpty())
            {
                firstEnsureComand = new IntermediateScriptCommand()
                {
                    OperationCode = OperationCode.Nop
                };
            }

            var sehGroup = new IntermediateSEHGroup();

            if (firstEnsureComand == null)
            {
                sehGroup.AfterPosition = afterCommand;
            }
            else
            {
                sehGroup.AfterPosition = firstEnsureComand;
            }

            var tryCommand = new IntermediateScriptCommand();
            tryCommand.OperationCode = OperationCode.SetSEHGroup;
            tryCommand.SEHGroup      = sehGroup;
            AddCommand(tryCommand);

            var tryCodeBlockNode = new CodeBlockNode(_context);
            tryCodeBlockNode.Run(statement.TryStatements);
            AddCommands(tryCodeBlockNode.Result);

            var removeSEHCommand = new IntermediateScriptCommand()
            {
                OperationCode = OperationCode.RemoveSEHGroup
            };

            AddCommand(removeSEHCommand);

            var tryAfterCommand = new IntermediateScriptCommand()
            {
                OperationCode = OperationCode.JumpTo
            };

            if (firstElseCommand != null)
            {
                tryAfterCommand.JumpToMe = firstElseCommand;
            }
            else
            {
                if (firstEnsureComand == null)
                {
                    tryAfterCommand.JumpToMe = afterCommand;
                }
                else
                {
                    tryAfterCommand.JumpToMe = firstEnsureComand;
                }
            }

            AddCommand(tryAfterCommand);

            if (!statement.CatchStatements.IsNullOrEmpty())
            {
                foreach (var catchStatement in statement.CatchStatements)
                {
                    var firstCatchCommand = new IntermediateScriptCommand()
                    {
                        OperationCode = OperationCode.Nop
                    };
                    AddCommand(firstCatchCommand);

                    var sehItem = new IntermediateSEHItem();
                    sehGroup.Items.Add(sehItem);
                    sehItem.VariableName = catchStatement.VariableName;
                    sehItem.Condition    = catchStatement.Condition;
                    sehItem.JumpToMe     = firstCatchCommand;

                    var catchCodeBlockNode = new CodeBlockNode(_context);
                    catchCodeBlockNode.Run(catchStatement.Statements);
                    AddCommands(catchCodeBlockNode.Result);

                    var catchAfterCommand = new IntermediateScriptCommand()
                    {
                        OperationCode = OperationCode.JumpTo
                    };

                    if (firstEnsureComand == null)
                    {
                        catchAfterCommand.JumpToMe = afterCommand;
                    }
                    else
                    {
                        catchAfterCommand.JumpToMe = firstEnsureComand;
                    }

                    AddCommand(catchAfterCommand);
                }
            }

            if (!statement.ElseStatements.IsNullOrEmpty())
            {
                AddCommand(firstElseCommand);

                var elseCodeBlockNode = new CodeBlockNode(_context);
                elseCodeBlockNode.Run(statement.ElseStatements);
                AddCommands(elseCodeBlockNode.Result);

                var elseAfterCommand = new IntermediateScriptCommand()
                {
                    OperationCode = OperationCode.JumpTo
                };

                if (firstEnsureComand == null)
                {
                    elseAfterCommand.JumpToMe = afterCommand;
                }
                else
                {
                    elseAfterCommand.JumpToMe = firstEnsureComand;
                }

                AddCommand(elseAfterCommand);
            }

            if (!statement.EnsureStatements.IsNullOrEmpty())
            {
                AddCommand(firstEnsureComand);

                var ensureCodeBlockNode = new CodeBlockNode(_context);
                ensureCodeBlockNode.Run(statement.EnsureStatements);
                AddCommands(ensureCodeBlockNode.Result);

                var ensureAfterCommand = new IntermediateScriptCommand()
                {
                    OperationCode = OperationCode.JumpTo
                };
                ensureAfterCommand.JumpToMe = afterCommand;
                AddCommand(ensureAfterCommand);
            }

            AddCommand(afterCommand);
        }
Beispiel #11
0
        public void Run(EntityConditionAstExpression expression)
        {
#if DEBUG
            //Log($"expression = {expression}");
#endif

            var count = 0;

            if (expression.FirstCoordinate != null)
            {
                count++;

                var node = new ExpressionNode(_context);
                node.Run(expression.FirstCoordinate);
                AddCommands(node.Result);

                if (expression.SecondCoordinate != null)
                {
                    count++;

                    node = new ExpressionNode(_context);
                    node.Run(expression.SecondCoordinate);
                    AddCommands(node.Result);
                }
            }

            var isNamed = false;

            if (expression.Name != null && !expression.Name.IsEmpty && expression.Name.NameValue != "#@")
            {
                isNamed = true;
                CompilePushVal(expression.Name);
            }

            count++;

            CompilePushAnnotation(expression);

            var kindOfEntityConditionAstExpression = expression.KindOfEntityConditionAstExpression;

#if DEBUG
            //Log($"count = {count}");
            //Log($"isNamed = {isNamed}");
            //Log($"kindOfEntityConditionAstExpression = {kindOfEntityConditionAstExpression}");
#endif

            switch (kindOfEntityConditionAstExpression)
            {
            case KindOfEntityConditionAstExpression.Waypoint:
            {
                var command = new IntermediateScriptCommand();

                if (isNamed)
                {
                    command.OperationCode = OperationCode.AllocateNamedWaypoint;
                }
                else
                {
                    command.OperationCode = OperationCode.AllocateAnonymousWaypoint;
                }

                command.CountParams = count;

                AddCommand(command);
            }
            break;

            default:
                throw new ArgumentOutOfRangeException(nameof(kindOfEntityConditionAstExpression), kindOfEntityConditionAstExpression, null);
            }
        }
        public void Run(CallingFunctionAstExpression expression)
        {
#if DEBUG
            //Log($"expression = {expression}");
#endif

            var kindOfParameters = KindOfParameters.NoParameters;

            var command = new IntermediateScriptCommand();

            if (!expression.Parameters.IsNullOrEmpty())
            {
                if (expression.Parameters.Any(p => p.IsNamed) && expression.Parameters.Any(p => !p.IsNamed))
                {
                    throw new NotSupportedException();
                }

                command.CountParams = expression.Parameters.Count;

                var isNamed = expression.Parameters.Any(p => p.IsNamed);

#if DEBUG
                //Log($"isNamed = {isNamed}");
#endif

                if (isNamed)
                {
                    kindOfParameters = KindOfParameters.NamedParameters;
                }
                else
                {
                    kindOfParameters = KindOfParameters.PositionedParameters;
                }

                foreach (var parameter in expression.Parameters)
                {
#if DEBUG
                    //Log($"parameter = {parameter}");
#endif

                    if (isNamed)
                    {
                        var node = new ExpressionNode(_context);
                        node.Run(parameter.Name);
                        AddCommands(node.Result);
                        node = new ExpressionNode(_context);
                        node.Run(parameter.Value);
                        AddCommands(node.Result);
                    }
                    else
                    {
                        var node = new ExpressionNode(_context);
                        node.Run(parameter.Value);
                        AddCommands(node.Result);
                    }
                }
            }

            var leftNode = new ExpressionNode(_context);
            leftNode.Run(expression.Left);
            AddCommands(leftNode.Result);

            CompilePushAnnotation(expression);

#if DEBUG
            //Log($"kindOfParameters = {kindOfParameters}");
#endif

            if (expression.IsAsync)
            {
                switch (kindOfParameters)
                {
                case KindOfParameters.NoParameters:
                    command.OperationCode = OperationCode.AsyncCall;
                    break;

                case KindOfParameters.NamedParameters:
                    command.OperationCode = OperationCode.AsyncCall_N;
                    break;

                case KindOfParameters.PositionedParameters:
                    command.OperationCode = OperationCode.AsyncCall_P;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(kindOfParameters), kindOfParameters, null);
                }
            }
            else
            {
                switch (kindOfParameters)
                {
                case KindOfParameters.NoParameters:
                    command.OperationCode = OperationCode.Call;
                    break;

                case KindOfParameters.NamedParameters:
                    command.OperationCode = OperationCode.Call_N;
                    break;

                case KindOfParameters.PositionedParameters:
                    command.OperationCode = OperationCode.Call_P;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(kindOfParameters), kindOfParameters, null);
                }
            }

#if DEBUG
            //Log($"command = {command}");
#endif

            AddCommand(command);
        }