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); } }
public void Run(AstExpressionStatement statement) { #if DEBUG //Log($"statement = {statement}"); #endif var node = new ExpressionNode(_context); node.Run(statement.Expression); AddCommands(node.Result); AddCommand(new IntermediateScriptCommand() { OperationCode = OperationCode.ClearStack }); }
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); }
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); }
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); }