コード例 #1
0
ファイル: BinaryOperation.cs プロジェクト: hunpody/psimulex
        public override void Do(ICommandContext context)
        {
            BaseType op2 = null; //context.RunStack.Pop().Clone();
            BaseType op1 = null; //context.RunStack.Pop().Clone();

            BaseType result = null;
            BaseType first = null;
            BaseType second = null;

            using (var listener = new Memory.AutoCleanup())
            {
                op2 = context.RunStack.Pop().Clone();
                op1 = context.RunStack.Pop().Clone();

                TypeEnum biggerType = TypeHierarchy.GetBiggerType(op1.Type, op2.Type);
                first = op1.ConvertTo(biggerType);
                second = op2.ConvertTo(biggerType);

                // Note: Dereference has no effect on tests.
                result = first.Dereference().Clone();

                switch (operation)
                {
                    case Operations.Addition:
                        result.Add(second);
                        break;
                    case Operations.Subtraction:
                        result.Subtract(second);
                        break;
                    case Operations.Multiplication:
                        result.Multiply(second);
                        break;
                    case Operations.Division:
                        result.Divide(second);
                        break;
                    case Operations.Power:
                        result.Power(second);
                        break;
                    case Operations.Modulo:
                        result.Modulo(second);
                        break;
                    case Operations.LogicalXor:
                        result = ValueFactory.Create(first && !second || !first && second);
                        break;
                    case Operations.LogicalOr:
                        result = ValueFactory.Create(first || second);
                        break;
                    case Operations.LogicalAnd:
                        result = ValueFactory.Create(first && second);
                        break;
                    default:
                        break;
                }
            }

            //op1.Delete();
            //op2.Delete();

            context.RunStack.Push(result.Clone());
        }
コード例 #2
0
ファイル: UnaryOperation.cs プロジェクト: hunpody/psimulex
        public override void Do(ICommandContext context)
        {
            BaseType value = context.RunStack.Pop();

            BaseType result = value;

            using (var listener = new Memory.AutoCleanup())
            {
                switch (operation)
                {
                    case Operations.Negate:
                        result = value.Dereference().Clone();
                        result.Negate();
                        break;
                    case Operations.Plus:
                        // It does simply nothing. Completely useless.
                        break;
                    case Operations.PrefixDecrement:
                        value.Subtract(ValueFactory.Create(1));
                        break;
                    case Operations.PrefixIncrement:
                        value.Add(ValueFactory.Create(1));
                        break;
                    case Operations.PostfixDecrement:
                        result = value.Dereference().Clone();
                        value.Subtract(ValueFactory.Create(1));
                        break;
                    case Operations.PostfixIncrement:
                        result = value.Dereference().Clone();
                        value.Add(ValueFactory.Create(1));
                        break;
                    case Operations.LogicalNot:
                        result = new VapeTeam.Psimulex.Core.Types.Boolean(!value.ToBoolean());
                        break;
                    default:
                        break;
                }
            }

            context.RunStack.Push(result.Clone());
        }