Exemplo n.º 1
0
		public Unary(LIRMethod parent, ISource src, IDestination dest, UnaryOperation op, LIRType argType) : base(parent, LIROpCode.Unary)
		{
			Source = src;
			Destination = dest;
			Operation = op;
			ArgumentType = argType;
		}
Exemplo n.º 2
0
        public static string GetUnaryOperator(UnaryOperation unaryOperation)
        {
            if (!UnaryOperators.Keys.Contains(unaryOperation))
            {
                throw new InvalidOperationException("Required operation was not recognized.");
            }

            return UnaryOperators[unaryOperation];
        }
Exemplo n.º 3
0
        /// <summary>
        /// Used to create: {UnaryOperation}{Value}
        /// </summary>
        public Expression(UnaryOperation unaryOperation, IValueType value)
        {
            StringBuilder sb = new StringBuilder(512);

            this.UnaryOperator = Operation.GetUnaryOperator(unaryOperation);

            sb.Append(this.UnaryOperator);
            sb.Append(value.ToString());

            this.Value = sb.ToString();
        }
Exemplo n.º 4
0
		private static string GetOperationSymbol(UnaryOperation op)
		{
			switch (op)
			{
				case UnaryOperation.Negate:
					return "-";
				case UnaryOperation.Not:
					return "!";
				default:
					throw new NotSupportedException();
			}
		}
        public override IList<AddressIndependentThing> Encode(UnaryOperation<Amd64Operation> op)
        {
            var ret = new List<AddressIndependentThing>();

            // any rex op
            ret.AddRange(OpCode.Convert());

            switch (Operand.Type)
            {
                case OperandType.Immediate:
                    ret.AddRange(EncodeImmediate(op.Target));
                    break;
                default:
                    throw new Exception("bad things");
            }

            return ret;
        }
Exemplo n.º 6
0
 public UnaryExpression(UnaryOperation operation, Expression arg)
 {
     Operation = operation;
     Argument  = arg ?? throw new ArgumentNullException(nameof(arg));
 }
Exemplo n.º 7
0
 public UnaryOperationExpression(UnaryOperation op, Expression exp)
 {
     mOp = op;
     mExpr = exp;
 }
Exemplo n.º 8
0
 private static bool IsUnaryOperator(TokenType type, out UnaryOperation operation)
 {
     return(UnaryOperations.Forward.TryGetValue(type, out operation));
 }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Lore.UnaryExpression"/> class.
 /// </summary>
 /// <param name="location">Location.</param>
 /// <param name="op">Op.</param>
 /// <param name="child">Child.</param>
 UnaryExpression(SourceLocation location, UnaryOperation op, AstNode child) : base(location)
 {
     Operation = op;
     Child     = child;
 }
Exemplo n.º 10
0
        double[] CalculateMultipleWithBuffer(MemoryStream codeStream, IReadOnlyTable <double> table, double[][] parameters)
        {
            int iterations = parameters.GetLength(0);
            Stack <double[]> resultStack = new Stack <double[]>();

            byte[] buffer = new byte[sizeof(double)];

            // a small memory & time optimization: it allows multiple usage of number buffers after performing calculations on them
            Queue <double[]> freeValueBuffers = new Queue <double[]>();

            while (true)
            {
                int command = codeStream.ReadByte();
                if (command == -1)
                {
                    throw new Exception("Can't execute next command");
                }

                double[] values = (freeValueBuffers.Count > 0) ? freeValueBuffers.Dequeue() : new double[iterations];

                if ((PostfixFunction.PostfixCommand)command == PostfixFunction.PostfixCommand.End)
                {
                    return(resultStack.Pop());
                }

                switch ((PostfixFunction.PostfixCommand)command)
                {
                case PostfixFunction.PostfixCommand.PushLiteral:
                {
                    codeStream.Read(buffer, 0, sizeof(double));
                    double literal = BitConverter.ToDouble(buffer, 0);

                    for (int i = 0; i < iterations; ++i)
                    {
                        values[i] = literal;
                    }
                }
                break;

                case PostfixFunction.PostfixCommand.PushVariable:
                {
                    codeStream.Read(buffer, 0, sizeof(int));
                    int index = BitConverter.ToInt32(buffer, 0);

                    for (int i = 0; i < iterations; ++i)
                    {
                        values[i] = table[index];
                    }
                }
                break;

                case PostfixFunction.PostfixCommand.PushParameter:
                {
                    codeStream.Read(buffer, 0, sizeof(int));
                    int index = BitConverter.ToInt32(buffer, 0);

                    for (int i = 0; i < iterations; ++i)
                    {
                        values[i] = parameters[i][index];
                    }
                }
                break;

                case PostfixFunction.PostfixCommand.CalculateUnary:
                {
                    double[] operands = resultStack.Pop();

                    codeStream.Read(buffer, 0, sizeof(int));
                    int            id        = BitConverter.ToInt32(buffer, 0);
                    UnaryOperation operation = (UnaryOperation)Operation.AllOperations[id];

                    for (int i = 0; i < values.Length; ++i)
                    {
                        values[i] = operation.Function(operands[i]);
                    }

                    // add free buffer to the queue
                    freeValueBuffers.Enqueue(operands);
                }
                break;

                case PostfixFunction.PostfixCommand.CalculateBinary:
                {
                    // pop in reverse order!
                    double[] rightOperands = resultStack.Pop();
                    double[] leftOperands  = resultStack.Pop();

                    codeStream.Read(buffer, 0, sizeof(int));
                    int             id        = BitConverter.ToInt32(buffer, 0);
                    BinaryOperation operation = (BinaryOperation)Operation.AllOperations[id];

                    for (int i = 0; i < values.Length; ++i)
                    {
                        values[i] = operation.Function(leftOperands[i], rightOperands[i]);
                    }

                    // add free buffers to the queue
                    freeValueBuffers.Enqueue(rightOperands);
                    freeValueBuffers.Enqueue(leftOperands);
                }
                break;
                }

                resultStack.Push(values);
            }
        }
Exemplo n.º 11
0
 public UnaryExpression(Expression Source, UnaryOperation Operation)
 {
     this.Source = Source;
     this.Operation = Operation;
 }
Exemplo n.º 12
0
 public static double InvokeUnary(UnaryOperation unaryOperation, double num)
 {
     return(Round(unaryOperation.Invoke(num), DigitsLimit));
 }
Exemplo n.º 13
0
 public override AstNode Visit(UnaryOperation node)
 {
     // Visit recursively.
     node.GetExpression().Accept(this);
     return(node);
 }
Exemplo n.º 14
0
 public UnaryExpression(UnaryOperation op, Expression sub)
 {
     Op  = op;
     Sub = sub;
 }
Exemplo n.º 15
0
        public void TestValidationCoolectioninCollectionModerator()
        {
            var model = new UnaryOperation()
            {
                Operand = new PropertyCollectionOperation
                {
                    Collection = new[]
                    {
                        new PropertyCollectionOperation
                        {
                            Collection = new[]
                            {
                                new ContextProperty {
                                    DynamicValue = (ctx) => ctx.Card(1, x => x.Voltage.Current)
                                },
                                new ContextProperty {
                                    DynamicValue = (ctx) => ctx.Card(2, x => x.Voltage.Current)
                                },
                                new ContextProperty {
                                    DynamicValue = (ctx) => ctx.Card(3, x => x.Voltage.Current)
                                },
                                new ContextProperty {
                                    DynamicValue = (ctx) => ctx.Card(4, x => x.Voltage.Current)
                                },
                                new ContextProperty {
                                    DynamicValue = (ctx) => ctx.Card(5, x => x.Voltage.Current)
                                },
                            },
                            Operator = CollectionOperator.AllEqual,
                            Property = new BaseProperty
                            {
                                Value = 1111
                            }
                        },
                        new PropertyCollectionOperation
                        {
                            Collection = new[]
                            {
                                new ContextProperty {
                                    DynamicValue = (ctx) => ctx.Card(1, x => x.TempLimit.Current)
                                },
                                new ContextProperty {
                                    DynamicValue = (ctx) => ctx.Card(2, x => x.TempLimit.Current)
                                },
                                new ContextProperty {
                                    DynamicValue = (ctx) => ctx.Card(3, x => x.TempLimit.Current)
                                },
                                new ContextProperty {
                                    DynamicValue = (ctx) => ctx.Card(4, x => x.TempLimit.Current)
                                },
                                new ContextProperty {
                                    DynamicValue = (ctx) => ctx.Card(5, x => x.TempLimit.Current)
                                },
                            },
                            Operator = CollectionOperator.Contains,
                            Property = new BaseProperty
                            {
                                Value = 50
                            }
                        }
                    },
                    Operator = CollectionOperator.AllEqual,
                    Property = new BaseProperty
                    {
                        Value = true
                    }
                }
            };
            var moderator = new FarmVisitor();
            var result    = moderator.Validate(model, FakeState());

            Assert.AreEqual(result.IsValid, true);
        }
Exemplo n.º 16
0
 // 遍历词法分析器序列,对于不同类型的关键字,跳转到特殊函数执行
 public void BParser()
 {
     try
     {
         // 当词法分析器序列tt没有读尽,就继续处理
         while (tt[tt_i] != null)
         {
             // 读取到auto关键字,跳转到auto函数处理
             if (tt[tt_i].Type.Equals("auto"))
             {
                 Auto.M_Auto(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }   // 读取到putnumb关键字,跳转到putnumb函数,输出数值型变量值
             else if (tt[tt_i].Type.Equals("putnumb"))
             {
                 Putnumb.Put_numb(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }   // 读取到putchar关键字,跳转到putchar函数,输出字符型型变量值
             else if (tt[tt_i].Type.Equals("putchar"))
             {
                 Putchar.Put_char(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }   // 单目运算,自增自减
             else if (tt[tt_i].Code.Equals("++") || tt[tt_i].Code.Equals("--"))
             {
                 UnaryOperation.Unary_Operation(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }   // 读取到类型为operator,即操作符类型,跳转到operator函数
             else if (tt[tt_i].Type.Equals("operator"))
             {
                 BOperator.Operator(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }   // 读取到关键字getchar,跳转到getchar函数进行读入字符串操作
             else if (tt[tt_i].Type.Equals("getchar"))
             {
                 Getchar.Get_char(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }   // 读取到关键字getnumb,跳转到getnumb函数执行读入数值操作
             else if (tt[tt_i].Type.Equals("getnumb"))
             {
                 Getnumb.Get_numb(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }   // 读取到关键字goto,跳转到Bgoto函数处理goto语句
             else if (tt[tt_i].Type.Equals("goto"))
             {
                 Bgoto.B_goto(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3, ref markmap);
             }   // 读取到if关键字,跳转到Bif函数处理if语句
             else if (tt[tt_i].Type.Equals("if"))
             {
                 Bif.B_if(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3, ref markmap, ref while_or);
             }   // 读取到while关键字, 跳转到BWhile函数处理while循环语句
             else if (tt[tt_i].Type.Equals("while"))
             {
                 BWhile.B_While(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3, ref markmap, ref while_or);
             }   // 读取到do关键字,跳转到BDo_while函数执行do while函数执行
             else if (tt[tt_i].Type.Equals("do"))
             {
                 BDoWhile.B_Dowhile(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3, ref markmap, ref while_or);
             }   // 读取到for关键字,执行for循环
             else if (tt[tt_i].Type.Equals("for"))
             {
                 Bfor.B_for(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }   // 读取到note关键字, 跳转到Note函数处理注释
             else if (tt[tt_i].Type.Equals("note"))
             {
                 Note.M_Note(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }   // 读取到putstr函数,输出数组
             else if (tt[tt_i].Type.Equals("putstr"))
             {
                 Putstr.Put_str(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }   // 读取到switch
             else if (tt[tt_i].Type.Equals("switch"))
             {
                 Bswitch.B_switch(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3, ref markmap, ref while_or);
             }   // 都不满足就将tt_i下标加1,不作处理
             else
             {
                 tt_i++;
             }
         }
     }
     catch (NotDefineVarException e)
     {
         Console.WriteLine(e.ToString());
         Console.Write(e.StackTrace);
     }
     catch (NotAVarException e)
     {
         Console.WriteLine(e.ToString());
         Console.Write(e.StackTrace);
     }
     catch (WrongGrammarException e)
     {
         Console.WriteLine(e.ToString());
         Console.Write(e.StackTrace);
     }
     catch (NotFoundMarkException e)
     {
         Console.WriteLine(e.ToString());
         Console.Write(e.StackTrace);
     }
 }
Exemplo n.º 17
0
 public virtual IodineObject PerformUnaryOperation(VirtualMachine vm, UnaryOperation op)
 {
     string methodName = null;
     switch (op) {
     case UnaryOperation.Negate:
         methodName = "__negate__";
         break;
     case UnaryOperation.Not:
         methodName = "__not__";
         break;
     case UnaryOperation.BoolNot:
         methodName = "__logicalNot__";
         break;
     }
     if (HasAttribute (methodName)) {
         return GetAttribute (vm, methodName).Invoke (vm, new IodineObject[] { });
     }
     vm.RaiseException (new IodineNotSupportedException (
         "The requested unary operator has not been implemented"));
     return null;
 }
Exemplo n.º 18
0
 public UnaryExpressionOperator(string symbol, ExpressionResultType result, bool canOverflow, bool signed, UnaryOperation type, UnaryOperatorDelegate code)
 {
     this.Symbol        = symbol;
     this.ResultType    = result;
     this.CanOverflow   = canOverflow;
     this.Signed        = signed;
     this.OperationType = type;
     this.Operation     = code;
 }
Exemplo n.º 19
0
        private static string ToPTX(this BasicBlockInstruction bbi)
        {
            BinaryOperation bop = bbi as BinaryOperation;
            UnaryOperation  uop = bbi as UnaryOperation;

            switch (bbi.OpCode)
            {
            case IROpCodes.ADD:
            case IROpCodes.SUB:
            case IROpCodes.REM:
            case IROpCodes.MIN:
            case IROpCodes.MAX:
                return(bop.OpCode.ToString().ToLower() + "." + bop.Target.DataType.ToPTX() +
                       " " + bop.Target + ", " + bop.LeftOperand + ", " + bop.RightOperand);

            case IROpCodes.MUL:
                return("mul." + (Util.IntegralTypes.Contains(bop.Target.DataType) ? "lo." : "") + bop.Target.DataType.ToPTX() +
                       " " + bop.Target + ", " + bop.LeftOperand + ", " + bop.RightOperand);

            case IROpCodes.MAD:
                MADOperation mad = bbi as MADOperation;
                return("mad." + (Util.IntegralTypes.Contains(mad.Target.DataType) ? "lo." : "") + mad.Target.DataType.ToPTX() +
                       " " + mad.Target + ", " + mad.MulLeftOperand + ", " + mad.MulRightOperand + ", " + mad.AddOperand);

            case IROpCodes.DIV:
                return("div." + (Util.IntegralTypes.Contains(bop.Target.DataType) ? bop.Target.DataType.ToPTX() :
                                 (bop.Target.DataType == typeof(float)) ? "approx.f32" : "rz.f64") +
                       " " + bop.Target + ", " + bop.LeftOperand + ", " + bop.RightOperand);

            case IROpCodes.AND:
            case IROpCodes.OR:
            case IROpCodes.XOR:
                return(bop.OpCode.ToString().ToLower() + ".b" + bop.Target.DataType.SizeOf() * 8 +
                       " " + bop.Target + ", " + bop.LeftOperand + ", " + bop.RightOperand);

            case IROpCodes.EQ:
            case IROpCodes.NE:
            case IROpCodes.GE:
            case IROpCodes.GT:
            case IROpCodes.LE:
            case IROpCodes.LT:
                return("set." + bop.OpCode.ToString().ToLower() +
                       "." + bop.Target.DataType.ToPTX() + "." + bop.LeftOperand.DataType.ToPTX() +
                       " " + bop.Target + ", " + bop.LeftOperand + ", " + bop.RightOperand);

            case IROpCodes.ABS:
            case IROpCodes.NEG:
            case IROpCodes.MOV:
                return(uop.OpCode.ToString().ToLower() + "." + uop.Target.DataType.ToPTX() +
                       " " + uop.Target + ", " + uop.Operand);

            case IROpCodes.NOT:
                return("not.b" + uop.Target.DataType.SizeOf() * 8 +
                       " " + uop.Target + ", " + uop.Operand);

            case IROpCodes.CVT:
            {
                string targetModif  = uop.Target.DataType.ToPTX();
                string operandModif = uop.Operand.DataType.ToPTX();
                string roundModif   = (uop.Target.DataType == typeof(float)) && (uop.Operand.DataType == typeof(double)) ? ".rz" :
                                      Util.RealTypes.Contains(uop.Target.DataType) && Util.IntegralTypes.Contains(uop.Operand.DataType) ? ".rz" :
                                      Util.IntegralTypes.Contains(uop.Target.DataType) && Util.RealTypes.Contains(uop.Operand.DataType) ? ".rzi" :
                                      "";
                return(((targetModif != operandModif) ? "cvt" + roundModif + "." + targetModif : "mov") + "." + operandModif +
                       " " + uop.Target + ", " + uop.Operand);
            }

            case IROpCodes.LD:
            {
                LDInstruction op = bbi as LDInstruction;
                return("ld." + op.Address.StateSpace.ToString().ToLower() + "." + op.Address.UnderlyingType.ToPTX() +
                       " " + op.Target + ", [" + op.Address + "]");
            }

            case IROpCodes.ST:
            {
                STInstruction op = bbi as STInstruction;
                return("st." + op.Address.StateSpace.ToString().ToLower() + "." + op.Address.UnderlyingType.ToPTX() +
                       " " + "[" + op.Address + "], " + op.Source);
            }

            case IROpCodes.SYNC:
                return("bar.sync 0");

            case IROpCodes.SQRT:
                return("sqrt" + ((uop.Target.DataType == typeof(float)) ? ".approx.f32" : ".rz.f64") +
                       " " + uop.Target + ", " + uop.Operand);

            case IROpCodes.RSQRT:
            case IROpCodes.SIN:
            case IROpCodes.COS:
            case IROpCodes.LG2:
            case IROpCodes.EX2:
                return(uop.OpCode.ToString().ToLower() + ".approx.f32" +
                       " " + uop.Target + ", " + uop.Operand);

            case IROpCodes.CALL:
            {
                CALLInstruction call = bbi as CALLInstruction;

                IEnumerable <Tuple <FormalParameter, GenericOperand> > argmap =
                    call.Target.FormalParameters.Zip(call.Arguments, (fp, ap) =>
                                                     new Tuple <FormalParameter, GenericOperand>(fp, ap));

                return(string.Format("call.uni ({0}), {1}, ({2})",
                                     string.Join(", ", from tuple in argmap where tuple.Item1.PassingStyle != PassingStyles.VAL select tuple.Item2),
                                     call.Target.Name,
                                     string.Join(", ", from tuple in argmap where tuple.Item1.PassingStyle != PassingStyles.OUT select tuple.Item2)));
            }

            default:
                throw new NotSupportedException(bbi.OpCode.ToString());
            }
        }
Exemplo n.º 20
0
 public override bool Visit(UnaryOperation node)
 {
     return(false);
 }
Exemplo n.º 21
0
 public UnaryExpression(Location location, Expression sub, UnaryOperation operation)
     : base(location)
 {
     this.sub = sub;
     this.operation = operation;
 }
Exemplo n.º 22
0
 public UnaryExpression(Expression operand, UnaryOperation operation, MjoType type)
 {
     Operand   = operand;
     Operation = operation;
     Type      = type;
 }
Exemplo n.º 23
0
 public void VisitUnaryOperation(UnaryOperation node)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 24
0
 public UnaryOperationNode(SourceLocation location, AstNode target, UnaryOperation unaryOperation)
 {
     this.SourceLocation = location;
     Children.Add(target);
     UnaryOperation = unaryOperation;
 }
Exemplo n.º 25
0
        public double Calculate(PostfixFunction function, double[] parameters)
        {
            Stack <double> resultStack = new Stack <double>();
            MemoryStream   codeStream  = function.GetStream();

            byte[] buffer = new byte[sizeof(double)];

            while (true)
            {
                int command = codeStream.ReadByte();
                if (command == -1)
                {
                    throw new Exception("Can't execute next command");
                }

                switch ((PostfixFunction.PostfixCommand)command)
                {
                case PostfixFunction.PostfixCommand.End: return(resultStack.Pop());

                case PostfixFunction.PostfixCommand.PushLiteral:
                {
                    codeStream.Read(buffer, 0, sizeof(double));
                    double literal = BitConverter.ToDouble(buffer, 0);
                    resultStack.Push(literal);
                }
                break;

                case PostfixFunction.PostfixCommand.PushVariable:
                {
                    codeStream.Read(buffer, 0, sizeof(int));
                    int index = BitConverter.ToInt32(buffer, 0);
                    resultStack.Push(function.OriginalFunction.VariableTable[index]);
                }
                break;

                case PostfixFunction.PostfixCommand.PushParameter:
                {
                    codeStream.Read(buffer, 0, sizeof(int));
                    int index = BitConverter.ToInt32(buffer, 0);
                    resultStack.Push(parameters[index]);
                }
                break;

                case PostfixFunction.PostfixCommand.CalculateUnary:
                {
                    double operand = resultStack.Pop();

                    codeStream.Read(buffer, 0, sizeof(int));
                    int            id        = BitConverter.ToInt32(buffer, 0);
                    UnaryOperation operation = (UnaryOperation)Operation.AllOperations[id];
                    resultStack.Push(operation.Function(operand));
                }
                break;

                case PostfixFunction.PostfixCommand.CalculateBinary:
                {
                    // pop in reverse order!
                    double rightOperand = resultStack.Pop();
                    double leftOperand  = resultStack.Pop();

                    codeStream.Read(buffer, 0, sizeof(int));
                    int             id        = BitConverter.ToInt32(buffer, 0);
                    BinaryOperation operation = (BinaryOperation)Operation.AllOperations[id];
                    resultStack.Push(operation.Function(leftOperand, rightOperand));
                }
                break;

                default: throw new Exception("Unknown command");
                }
            }
        }
Exemplo n.º 26
0
 public virtual IList<AddressIndependentThing> Encode(UnaryOperation<Amd64Operation> op)
 {
     throw new InvalidOperationException();
 }
Exemplo n.º 27
0
 public void VisitUnaryOperation(UnaryOperation node) => InferSimpleType(node.Operand);
Exemplo n.º 28
0
 protected void Attribute(string name, UnaryOperation value)
 {
     wr.WriteAttributeString(name, Convert(value));
 }
Exemplo n.º 29
0
 /// <summary>
 /// Create a new instance of the <see cref="BinaryExpression"/> class.
 /// </summary>
 /// <param name="location">Location.</param>
 /// <param name="op">Op.</param>
 /// <param name="child">Right.</param>
 public static UnaryExpression Create(SourceLocation location, UnaryOperation op, AstNode child)
 => new UnaryExpression(location, op, child);
Exemplo n.º 30
0
 public void VisitUnaryOperation(UnaryOperation node)
 {
     Visit(node.expr);
 }
Exemplo n.º 31
0
		public override IodineObject PerformUnaryOperation (VirtualMachine vm, UnaryOperation op)
		{
			switch (op) {
			case UnaryOperation.Not:
				return new IodineInteger (~Value);
			case UnaryOperation.Negate:
				return new IodineInteger (-Value);
			}
			return null;
		}
Exemplo n.º 32
0
 public UnaryExpression(SourceLocation location, UnaryOperation op, AstNode val)
     : base(location)
 {
     Operation = op;
     Add(val);
 }
Exemplo n.º 33
0
 public static UnaryExpression <T> Create <T>(Filter <T> left, UnaryOperation op)
 {
     return(new UnaryExpression <T>(left, op));
 }
Exemplo n.º 34
0
 public UnaryExpression(Location location, UnaryOperation op, AstNode val)
     : base(location)
 {
     Operation = op;
     Add (val);
 }
Exemplo n.º 35
0
 public static void Parser_ReNamed2(ref WordType[] tt, ref int tt_i, ref MyArray[] a, ref int a_i, ref string parseresult, ref Dictionary<string, int> varmap, ref Dictionary<string, string> varmap2, ref Dictionary<string, MyArray> varmap3, int start_num, int end_num, int eend_num)
 {
     try
     {
         for (tt_i = start_num; tt_i < end_num && tt[tt_i] != null; )
         {
             // 读取到auto关键字,跳转到auto函数处理
             if (tt[tt_i].Type.Equals("auto"))
             {
                 Auto.M_Auto(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }
             // 读取到putnumb关键字,跳转到putnumb函数,输出数值型变量值
             else if (tt[tt_i].Type.Equals("putnumb"))
             {
                 Putnumb.Put_numb(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }
             // 读取到putchar关键字,跳转到putchar函数,输出字符型型变量值
             else if (tt[tt_i].Type.Equals("putchar"))
             {
                 Putchar.Put_char(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }
             // 单目运算,自增自减
             else if (tt[tt_i].Code.Equals("++") || tt[tt_i].Code.Equals("--"))
             {
                 UnaryOperation.Unary_Operation(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }
             // 读取到类型为operator,即操作符类型,跳转到operator函数
             else if (tt[tt_i].Type.Equals("operator"))
             {
                 BOperator.Operator(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }
             // 读取到关键字getchar,跳转到getchar函数进行获取字符串输入操作
             else if (tt[tt_i].Type.Equals("getchar"))
             {
                 Getchar.Get_char(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }
             // 读取到关键字getnumb,跳转到getnumb函数进行获取数值输入操作
             else if (tt[tt_i].Type.Equals("getnumb"))
             {
                 Getnumb.Get_numb(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }
             // 读取到note关键字, 跳转到Note函数处理注释
             else if (tt[tt_i].Type.Equals("note"))
             {
                 Note.M_Note(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }
             // 读取到putstr函数,输出数组
             else if (tt[tt_i].Type.Equals("putstr"))
             {
                 Putstr.Put_str(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }
             // 都不满足就将tt_i下标加1,不作处理
             else
             {
                 tt_i++;
             }
         }
     }
     catch (NotDefineVarException e)
     {
         Console.WriteLine(e.ToString());
         Console.Write(e.StackTrace);
     }
     catch (NotAVarException e)
     {
         Console.WriteLine(e.ToString());
         Console.Write(e.StackTrace);
     }
     catch (WrongGrammarException e)
     {
         Console.WriteLine(e.ToString());
         Console.Write(e.StackTrace);
     }
     tt_i = eend_num;
     return;
 }
Exemplo n.º 36
0
 void IUnaryOperationVisitor.Visit(UnaryOperation This)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Exemplo n.º 37
0
 public override IodineObject PerformUnaryOperation(VirtualMachine vm, UnaryOperation op)
 {
     switch (op) {
     case UnaryOperation.BoolNot:
         return IodineBool.Create (!Value);
     }
     return null;
 }
Exemplo n.º 38
0
 public UnaryInstruction(uint label, IVariable result, UnaryOperation operation, IVariable operand)
     : base(label, result)
 {
     this.Operation = operation;
     this.Operand   = operand;
 }
Exemplo n.º 39
0
 public TotemUnaryOperationBinder Register(Type type, UnaryOperation operation)
 {
     unops.Add(type, operation);
     return this;
 }
 public UnaryOperationExpression(UnaryOperation operation, ValueExpression operand)
 {
     Operation = operation;
     Operand   = operand;
 }
Exemplo n.º 41
0
 public static void F_Parser(ref WordType[] tt, ref int tt_i, ref MyArray[] a, ref int a_i, ref string parseresult, ref Dictionary <string, int> varmap, ref Dictionary <string, string> varmap2, ref Dictionary <string, MyArray> varmap3, int start_num, int end_num)
 {
     for (tt_i = start_num; tt_i < end_num && tt[tt_i] != null;)
     {
         if (tt[tt_i].Type.Equals("auto"))
         {
             try
             {
                 Auto.M_Auto(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }
             catch (WrongGrammarException e)
             {
                 Console.WriteLine(e.ToString());
                 Console.Write(e.StackTrace);
             }
             catch (NotAVarException e)
             {
                 Console.WriteLine(e.ToString());
                 Console.Write(e.StackTrace);
             }
         }
         else if (tt[tt_i].Type.Equals("putnumb"))
         {
             try
             {
                 Putnumb.Put_numb(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }
             catch (NotDefineVarException e)
             {
                 Console.WriteLine(e.ToString());
                 Console.Write(e.StackTrace);
             }
             catch (WrongGrammarException e)
             {
                 Console.WriteLine(e.ToString());
                 Console.Write(e.StackTrace);
             }
             catch (NotAVarException e)
             {
                 Console.WriteLine(e.ToString());
                 Console.Write(e.StackTrace);
             }
         }
         else if (tt[tt_i].Type.Equals("putchar"))
         {
             try
             {
                 Putchar.Put_char(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }
             catch (NotDefineVarException e)
             {
                 Console.WriteLine(e.ToString());
                 Console.Write(e.StackTrace);
             }
             catch (WrongGrammarException e)
             {
                 Console.WriteLine(e.ToString());
                 Console.Write(e.StackTrace);
             }
         }
         else if (tt[tt_i].Code.Equals("++") || tt[tt_i].Code.Equals("--"))
         {
             try
             {
                 UnaryOperation.Unary_Operation(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }
             catch (NotDefineVarException e)
             {
                 Console.WriteLine(e.ToString());
                 Console.Write(e.StackTrace);
             }
             catch (WrongGrammarException e)
             {
                 Console.WriteLine(e.ToString());
                 Console.Write(e.StackTrace);
             }
         }
         else if (tt[tt_i].Type.Equals("operator"))
         {
             try
             {
                 BOperator.Operator(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }
             catch (NotAVarException e)
             {
                 Console.WriteLine(e.ToString());
                 Console.Write(e.StackTrace);
             }
             catch (NotDefineVarException e)
             {
                 Console.WriteLine(e.ToString());
                 Console.Write(e.StackTrace);
             }
         }
         else if (tt[tt_i].Type.Equals("getchar"))
         {
             try
             {
                 Getchar.Get_char(ref tt, ref tt_i, ref a, ref a_i, ref parseresult, ref varmap, ref varmap2, ref varmap3);
             }
             catch (NotDefineVarException e)
             {
                 Console.WriteLine(e.ToString());
                 Console.Write(e.StackTrace);
             }
             catch (WrongGrammarException e)
             {
                 Console.WriteLine(e.ToString());
                 Console.Write(e.StackTrace);
             }
         }
         else
         {
             tt_i++;
         }
     }
     return;
 }
Exemplo n.º 42
0
 public UnaryOpNode(UnaryOperation type, AstNode value)
 {
     this.UnOp = type;
     this.Children.Add(value);
 }
Exemplo n.º 43
0
 void IExpressionVisitor.Visit(UnaryOperation This)
 {
     result = new ILUnaryOperation(generator, This);
 }
Exemplo n.º 44
0
 public virtual bool Visit(UnaryOperation node)
 {
     return(CommonVisit(node));
 }
Exemplo n.º 45
0
 public virtual void EndVisit(UnaryOperation node)
 {
     CommonEndVisit(node);
 }
Exemplo n.º 46
0
 public UnaryOpNode(UnaryOperation type, AstNode value)
 {
     this.UnOp = type;
     this.Children.Add(value);
 }