Beispiel #1
0
        private void EvaluateExpressionItem(T1ExpressionItem expression)
        {
            switch (expression.Operator)
            {
            case T1Operator.DirectByte:
                if (expression.OperandLeft.Value is byte)
                {
                    ExpressionResult = (byte)expression.OperandLeft.Value;
                }
                else if (expression.OperandLeft.Value is T1ExpressionItem)
                {
                    EvaluateExpression(expression.OperandLeft);
                }
                else
                {
                    throw new Exception("Runtime error: type mismatch");
                }

                ExpressionType = T1VariableType.Byte;
                break;

            case T1Operator.DirectInt:
                if (expression.OperandLeft.Value is int)
                {
                    ExpressionResult = (int)expression.OperandLeft.Value;
                }
                else if (expression.OperandLeft.Value is T1ExpressionItem)
                {
                    EvaluateExpression(expression.OperandLeft);
                }
                else
                {
                    throw new Exception("Runtime error: type mismatch");
                }

                ExpressionType = T1VariableType.Int;
                break;

            case T1Operator.DirectNumeric:
                if (expression.OperandLeft.Value is double)
                {
                    ExpressionResult = (double)expression.OperandLeft.Value;
                }
                else if (expression.OperandLeft.Value is T1ExpressionItem)
                {
                    EvaluateExpression(expression.OperandLeft);
                }
                else
                {
                    throw new Exception("Runtime error: type mismatch");
                }

                ExpressionType = T1VariableType.Double;
                break;

            case T1Operator.DirectString:
                if (expression.OperandLeft.Value is string)
                {
                    ExpressionResult = (string)expression.OperandLeft.Value;
                }
                else if (expression.OperandLeft.Value is T1ExpressionItem)
                {
                    EvaluateExpression(expression.OperandLeft);
                }
                else
                {
                    throw new Exception("Runtime error: type mismatch");
                }

                ExpressionType = T1VariableType.String;
                break;

            case T1Operator.Dereference:
                T1Variable variable = ((T1RuntimeVairableReference)expression.OperandLeft.Value).Scope.VariableTable[((T1RuntimeVairableReference)expression.OperandLeft.Value).VariableId];

                switch (variable.VariableType)
                {
                case T1VariableType.Byte:
                    ExpressionResult = (byte)variable.Value;
                    break;

                case T1VariableType.Double:
                    ExpressionResult = (double)variable.Value;
                    break;

                case T1VariableType.Int:
                    ExpressionResult = (int)variable.Value;
                    break;

                case T1VariableType.String:
                    ExpressionResult = (string)variable.Value;
                    break;
                }

                ExpressionType = variable.VariableType;
                break;

            case T1Operator.Concatanate:
                EvaluateExpression(expression.OperandLeft);
                ExpressionStackPush();
                EvaluateExpression(expression.OperandRight);

                ExpressionResult = ExpressionStackPopString() + (string)ExpressionResult;
                ExpressionType   = T1VariableType.String;

                break;

            case T1Operator.Add:
                EvaluateExpression(expression.OperandLeft);
                ExpressionStackPush();
                EvaluateExpression(expression.OperandRight);

                switch (ExpressionType)
                {
                case T1VariableType.Int:
                    ExpressionResult = ExpressionStackPopInt() + (int)ExpressionResult;
                    break;

                case T1VariableType.Byte:
                    ExpressionResult = ExpressionStackPopByte() + (byte)ExpressionResult;
                    break;

                case T1VariableType.Double:
                    ExpressionResult = ExpressionStackPopDouble() + (double)ExpressionResult;
                    break;

                default:
                    throw new Exception("Runtime error: Invalid type in math");
                }

                break;

            case T1Operator.Subtract:
                EvaluateExpression(expression.OperandLeft);
                ExpressionStackPush();
                EvaluateExpression(expression.OperandRight);

                switch (ExpressionType)
                {
                case T1VariableType.Int:
                    ExpressionResult = ExpressionStackPopInt() - (int)ExpressionResult;
                    break;

                case T1VariableType.Byte:
                    ExpressionResult = ExpressionStackPopByte() - (byte)ExpressionResult;
                    break;

                case T1VariableType.Double:
                    ExpressionResult = ExpressionStackPopDouble() - (double)ExpressionResult;
                    break;

                default:
                    throw new Exception("Runtime error: Invalid type in math");
                }

                break;

            case T1Operator.Multiply:
                EvaluateExpression(expression.OperandLeft);
                ExpressionStackPush();
                EvaluateExpression(expression.OperandRight);

                switch (ExpressionType)
                {
                case T1VariableType.Int:
                    ExpressionResult = ExpressionStackPopInt() * (int)ExpressionResult;
                    break;

                case T1VariableType.Byte:
                    ExpressionResult = ExpressionStackPopByte() * (byte)ExpressionResult;
                    break;

                case T1VariableType.Double:
                    ExpressionResult = ExpressionStackPopDouble() * (double)ExpressionResult;
                    break;

                default:
                    throw new Exception("Runtime error: Invalid type in math");
                }

                break;

            case T1Operator.Divide:
                EvaluateExpression(expression.OperandLeft);
                ExpressionStackPush();
                EvaluateExpression(expression.OperandRight);

                switch (ExpressionType)
                {
                case T1VariableType.Int:
                    ExpressionResult = ExpressionStackPopInt() / (int)ExpressionResult;
                    break;

                case T1VariableType.Byte:
                    ExpressionResult = ExpressionStackPopByte() / (byte)ExpressionResult;
                    break;

                case T1VariableType.Double:
                    ExpressionResult = ExpressionStackPopDouble() / (double)ExpressionResult;
                    break;

                default:
                    throw new Exception("Runtime error: Invalid type in math");
                }

                break;

            case T1Operator.Mod:
                EvaluateExpression(expression.OperandLeft);
                ExpressionStackPush();
                EvaluateExpression(expression.OperandRight);

                switch (ExpressionType)
                {
                case T1VariableType.Int:
                    ExpressionResult = ExpressionStackPopInt() % (int)ExpressionResult;
                    break;

                case T1VariableType.Byte:
                    ExpressionResult = ExpressionStackPopByte() % (byte)ExpressionResult;
                    break;

                case T1VariableType.Double:
                    ExpressionResult = ExpressionStackPopDouble() % (double)ExpressionResult;
                    break;

                default:
                    throw new Exception("Runtime error: Invalid type in math");
                }

                break;

            case T1Operator.ShiftLeft:
                EvaluateExpression(expression.OperandLeft);
                ExpressionStackPush();
                EvaluateExpression(expression.OperandRight);

                ExpressionResult = ExpressionStackPopInt() << (int)ExpressionResult;

                break;

            case T1Operator.Power:
                EvaluateExpression(expression.OperandLeft);
                ExpressionStackPush();
                EvaluateExpression(expression.OperandRight);

                ExpressionResult = (int)Math.Pow(ExpressionStackPopInt(), (int)ExpressionResult);

                break;

            case T1Operator.ShiftRight:
                EvaluateExpression(expression.OperandLeft);
                ExpressionStackPush();
                EvaluateExpression(expression.OperandRight);

                ExpressionResult = ExpressionStackPopInt() >> (int)ExpressionResult;

                break;

            case T1Operator.OrLogical:
                EvaluateExpression(expression.OperandLeft);
                ExpressionStackPush();
                EvaluateExpression(expression.OperandRight);

                ExpressionResult = (ExpressionStackPopDouble() == 1) || ((double)ExpressionResult == 1);

                break;

            case T1Operator.OrBitwise:
                EvaluateExpression(expression.OperandLeft);
                ExpressionStackPush();
                EvaluateExpression(expression.OperandRight);

                ExpressionResult = (ExpressionStackPopDouble() == 1) | ((double)ExpressionResult == 1);

                break;

            case T1Operator.AndLogical:
                EvaluateExpression(expression.OperandLeft);
                ExpressionStackPush();
                EvaluateExpression(expression.OperandRight);

                ExpressionResult = (ExpressionStackPopDouble() == 1) && ((double)ExpressionResult == 1);

                break;

            case T1Operator.AndBitwise:
                EvaluateExpression(expression.OperandLeft);
                ExpressionStackPush();
                EvaluateExpression(expression.OperandRight);

                ExpressionResult = (ExpressionStackPopDouble() == 1) & ((double)ExpressionResult == 1);

                break;
            }
        }
Beispiel #2
0
 public T1InstructionAssignment(T1RuntimeVairableReference variable, T1ExpressionItem expression) : base(T1InstructionType.Assignment, variable)
 {
     this.variable   = variable;
     this.expression = expression;
 }
Beispiel #3
0
        public T1InstructionConditionalJump(int labelId, T1ExpressionItem expression) : base(labelId)
        {
            type = T1InstructionType.ConditionalJump;

            this.expression = expression;
        }
Beispiel #4
0
 public T1InstructionEvaluateExpression(T1ExpressionItem expression) : base(T1InstructionType.ExpressionEvaluation, expression)
 {
     this.expression = expression;
 }