当前位置: 首页>>代码示例>>C#>>正文


C# Emitter.EmitConvertToFloat方法代码示例

本文整理汇总了C#中Emitter.EmitConvertToFloat方法的典型用法代码示例。如果您正苦于以下问题:C# Emitter.EmitConvertToFloat方法的具体用法?C# Emitter.EmitConvertToFloat怎么用?C# Emitter.EmitConvertToFloat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Emitter的用法示例。


在下文中一共展示了Emitter.EmitConvertToFloat方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Compile

        public override void Compile(Emitter.Emitter emitter)
        {
            var numTypes = new[] { "int", "float" };

              var fromType = From.GetExpressionType(emitter);
              var toType = To.GetExpressionType(emitter);
              var stepType = Step.GetExpressionType(emitter);

              // validate parameters
              if (!fromType.IsAnyOf(numTypes) || !toType.IsAnyOf(numTypes) || !stepType.IsAnyOf(numTypes))
            Error(Resources.errIntFloatExpected);

              // from, to, step
              From.Compile(emitter);
              if (fromType != "float")
            emitter.EmitConvertToFloat();

              To.Compile(emitter);
              if (toType != "float")
            emitter.EmitConvertToFloat();

              Step.Compile(emitter);
              if (stepType != "float")
            emitter.EmitConvertToFloat();

              // invoke method
              var method = typeof(MirelleStdlib.ArrayHelper).GetMethod("CreateRangedArray", new[] { typeof(double), typeof(double), typeof(double) });
              emitter.EmitCall(emitter.AssemblyImport(method));
        }
开发者ID:menozz,项目名称:mirelle,代码行数:29,代码来源:FloatRangeNode.cs

示例2: Compile

        public override void Compile(Emitter.Emitter emitter)
        {
            // ensure this is a matrix
              if (ExpressionPrefix.GetExpressionType(emitter) != "matrix")
            Error(Resources.errIndexingNotAMatrix);

              // ensure indexes are integers
              if (Index1.GetExpressionType(emitter) != "int")
            Error(Resources.errIntIndexExpected, Index1.Lexem);

              if (Index2.GetExpressionType(emitter) != "int")
            Error(Resources.errIntIndexExpected, Index2.Lexem);

              // ensure assigned value is either int or float
              var exprType = Expression.GetExpressionType(emitter);
              if (!exprType.IsAnyOf("int", "float"))
            Error(Resources.errMatrixItemTypeMismatch);

              ExpressionPrefix.Compile(emitter);

              Index1.Compile(emitter);
              Index2.Compile(emitter);

              Expression.Compile(emitter);
              if(exprType != "float")
            emitter.EmitConvertToFloat();

              var method = emitter.AssemblyImport(typeof(MN.DenseMatrix).GetMethod("At", new[] { typeof(int), typeof(int), typeof(double) }));
              emitter.EmitCall(method);
        }
开发者ID:menozz,项目名称:mirelle,代码行数:30,代码来源:MatrixSetNode.cs

示例3: Compile

        public override void Compile(Emitter.Emitter emitter)
        {
            var leftType = Left.GetExpressionType(emitter);
              var rightType = Right.GetExpressionType(emitter);

              var type = GetExpressionType(emitter);

              // divide matrix by a number
              if(type == "matrix")
              {
            Left.Compile(emitter);

            // division is broken, therefore multiply by an inverse value
            emitter.EmitLoadFloat(1);
            Right.Compile(emitter);

            if (rightType != "float")
              emitter.EmitConvertToFloat();

            emitter.EmitDiv();

            var matrixType = typeof(MN.Matrix<double>);
            var method = emitter.AssemblyImport(matrixType.GetMethod("Multiply", new[] { typeof(double) }));
            emitter.EmitCall(method);
              }

              // divide complex numbers
              else if (type == "complex")
              {
            Left.Compile(emitter);
            if (leftType != "complex")
            {
              emitter.EmitUpcastBasicType(leftType, "float");
              emitter.EmitLoadFloat(0);
              emitter.EmitNewObj(emitter.FindMethod("complex", ".ctor", "float", "float"));
            }

            Right.Compile(emitter);
            if (rightType != "complex")
            {
              emitter.EmitUpcastBasicType(rightType, "float");
              emitter.EmitLoadFloat(0);
              emitter.EmitNewObj(emitter.FindMethod("complex", ".ctor", "float", "float"));
            }

            emitter.EmitCall(emitter.AssemblyImport(typeof(SN.Complex).GetMethod("op_Division", new[] { typeof(SN.Complex), typeof(SN.Complex) })));
              }

              // divide floating point numbers or integers
              else if (type.IsAnyOf("int", "float"))
              {
            Left.Compile(emitter);
            emitter.EmitUpcastBasicType(leftType, type);
            Right.Compile(emitter);
            emitter.EmitUpcastBasicType(rightType, type);
            emitter.EmitDiv();
              }
        }
开发者ID:menozz,项目名称:mirelle,代码行数:58,代码来源:OperatorDivideNode.cs

示例4: Compile

        public override void Compile(Emitter.Emitter emitter)
        {
            Resolve(emitter);

              // operands
              Left.Compile(emitter);
              emitter.EmitConvertToFloat();
              Right.Compile(emitter);
              emitter.EmitConvertToFloat();

              // magic method
              var method = emitter.AssemblyImport(typeof(Math).GetMethod("Pow", new[] { typeof(double), typeof(double) }));
              emitter.EmitCall(method);

              // convert back
              if (IsInt)
            emitter.EmitConvertToInt();
              else
            emitter.EmitConvertToFloat();
        }
开发者ID:menozz,项目名称:mirelle,代码行数:20,代码来源:OperatorPowerNode.cs

示例5: Compile

        public override void Compile(Emitter.Emitter emitter)
        {
            // retrieve matrix dimensions
              var height = MatrixItems.Count;
              var width = MatrixItems[0].Count;

              // retrieve info about matrices
              var matrixType = typeof(MN.DenseMatrix);
              var matrixCtor = emitter.AssemblyImport(matrixType.GetConstructor(new[] { typeof(int), typeof(int) }));
              var matrixSet = emitter.AssemblyImport(matrixType.GetMethod("At", new[] { typeof(int), typeof(int), typeof(double) }));

              var tmpVar = emitter.CurrentMethod.Scope.Introduce("matrix", emitter.AssemblyImport(matrixType));

              // create matrix
              emitter.EmitLoadInt(height);
              emitter.EmitLoadInt(width);
              emitter.EmitNewObj(matrixCtor);
              emitter.EmitSaveVariable(tmpVar);

              // set items
              for(var idx1 = 0; idx1 < MatrixItems.Count; idx1++)
              {
            // ensure all lines have the same number of items
            if (idx1 > 0 && MatrixItems[0].Count != MatrixItems[idx1].Count)
              Error(String.Format(Resources.errMatrixLineLengthMismatch, MatrixItems[0].Count, idx1+1, MatrixItems[idx1].Count));

            for(var idx2 = 0; idx2 < MatrixItems[idx1].Count; idx2++)
            {
              var item = MatrixItems[idx1][idx2];
              var itemType = item.GetExpressionType(emitter);
              if (!itemType.IsAnyOf("int", "float"))
            Error(Resources.errMatrixItemTypeMismatch, item.Lexem);

              emitter.EmitLoadVariable(tmpVar);

              emitter.EmitLoadInt(idx1);
              emitter.EmitLoadInt(idx2);
              item.Compile(emitter);

              if (itemType != "float")
            emitter.EmitConvertToFloat();

              emitter.EmitCall(matrixSet);
            }
              }

              emitter.EmitLoadVariable(tmpVar);
        }
开发者ID:menozz,项目名称:mirelle,代码行数:48,代码来源:MatrixNode.cs

示例6: Compile

        public override void Compile(Emitter.Emitter emitter)
        {
            var fromType = Expression.GetExpressionType(emitter);
              var toType = ToType;
              var simpleTypes = new[] { "bool", "int", "float", "long", "complex" };

              if (emitter.ResolveType(toType) == null)
            Error(String.Format(Resources.errTypeNotFound, toType));

              // compile the expression itself
              Expression.Compile(emitter);

              // idiotic case?
              if (fromType == toType) return;

              if(fromType == "null")
              {
            if(toType.IsAnyOf(simpleTypes))
              Error(String.Format(Resources.errInvalidNullCast, toType));

            // no actual casting is required
              }
              // cast simple types
              else if(fromType.IsAnyOf(simpleTypes))
              {
            if (toType.IsAnyOf(simpleTypes))
            {
              switch(toType)
              {
            case "bool": emitter.EmitConvertToBool(); break;
            case "int": emitter.EmitConvertToInt(); break;
            case "float": emitter.EmitConvertToFloat(); break;
            default: throw new NotImplementedException();
              }
            }
            else
              Error(String.Format(Resources.errInvalidCast, fromType, toType));
              }
              else
              {
            // complex type to simple type: search for a conversion method
            if(toType.IsAnyOf(simpleTypes))
            {
              // to_b, to_f, to_i
              string methodName = "to_" + toType[0];
              MethodNode converter = null;
              try
              {
            converter = emitter.FindMethod(fromType, methodName);
              }
              catch
              {
            Error(String.Format(Resources.errInvalidCast, fromType, toType));
              }

              // call the method
              emitter.EmitCall(converter);
            }
            else
            {
              if (fromType.Contains("[]") || toType.Contains("[]"))
            Error(Resources.errCastArray);

              if(!emitter.TypeCastable(fromType, toType))
            Error(String.Format(Resources.errInvalidCast, fromType, toType));

              var type = emitter.FindType(toType);
              emitter.EmitCast(type.Type);
            }
              }
        }
开发者ID:menozz,项目名称:mirelle,代码行数:71,代码来源:AsNode.cs

示例7: CompileInitiation

        /// <summary>
        /// Generate code to setup the currently defined emitter
        /// </summary>
        /// <param name="emitter"></param>
        private void CompileInitiation(Emitter.Emitter emitter)
        {
            var emitterType = emitter.FindType(EmitterID);
              var tmpVar = emitter.CurrentMethod.Scope.Introduce(EmitterID, emitterType.Type);

              // tmp = new emitterN()
              emitter.EmitNewObj(emitter.FindMethod(EmitterID, ".ctor"));
              emitter.EmitSaveVariable(tmpVar);

              // step
              if (Step != null)
              {
            // validate step
            var stepType = Step.GetExpressionType(emitter);
            if (!stepType.IsAnyOf("int", "float"))
              Error(Resources.errEmitStepExpected);

            // tmp.Step = step
            emitter.EmitLoadVariable(tmpVar);
            Step.Compile(emitter);
            if (stepType == "int")
              emitter.EmitConvertToFloat();
            emitter.EmitSaveField(emitter.FindField(EmitterID, "step"));
              }

              // distribution
              if (Distribution != null)
              {
            // validate distr
            if (Distribution.GetExpressionType(emitter) != "distr")
              Error(Resources.errEmitDistributionExpected);

            // tmp.Distr = distr
            emitter.EmitLoadVariable(tmpVar);
            Distribution.Compile(emitter);
            emitter.EmitSaveField(emitter.FindField(EmitterID, "distr"));
              }

              // limit
              if (Limit != null)
              {
            // validate distr
            if (Limit.GetExpressionType(emitter) != "int")
              Error(Resources.errEmitLimitExpected);

            // tmp.Distr = distr
            emitter.EmitLoadVariable(tmpVar);
            Limit.Compile(emitter);
            emitter.EmitSaveField(emitter.FindField(EmitterID, "limit"));
              }

              SaveClosuredVariables(emitter, tmpVar);

              // register emitter in the system
              emitter.EmitLoadVariable(tmpVar);
              var registerMethod = emitter.AssemblyImport(typeof(Simulation).GetMethod("RegisterEmitter", new[] { typeof(EventEmitter) }));
              emitter.EmitCall(registerMethod);
        }
开发者ID:menozz,项目名称:mirelle,代码行数:62,代码来源:EmitNode.cs

示例8: Compile

        public override void Compile(Emitter.Emitter emitter)
        {
            var leftType = Left.GetExpressionType(emitter);
              var rightType = Right.GetExpressionType(emitter);

              var type = GetExpressionType(emitter);

              // repeat a string
              if (type == "string")
              {
            Left.Compile(emitter);
            Right.Compile(emitter);
            emitter.EmitCall(emitter.FindMethod("string", "repeat", "int"));
              }

              // multiply matrices
              else if(type == "matrix")
              {
            var matrixType = typeof(MN.Matrix<double>);

            // matrix by matrix
            if(leftType == rightType)
            {
              Left.Compile(emitter);
              Right.Compile(emitter);

              var method = emitter.AssemblyImport(matrixType.GetMethod("Multiply", new[] { matrixType }));
              emitter.EmitCall(method);
            }
            else
            {
              // matrix should be the first in stack
              if(leftType == "matrix")
              {
            Left.Compile(emitter);
            Right.Compile(emitter);
            if (rightType != "float")
              emitter.EmitConvertToFloat();
              }
              else
              {
            Right.Compile(emitter);
            Left.Compile(emitter);
            if (leftType != "float")
              emitter.EmitConvertToFloat();
              }

              var method = emitter.AssemblyImport(matrixType.GetMethod("Multiply", new[] { typeof(double) }));
              emitter.EmitCall(method);
            }
              }

              // multiply complex numbers
              else if (type == "complex")
              {
            Left.Compile(emitter);
            if (leftType != "complex")
            {
              emitter.EmitUpcastBasicType(leftType, "float");
              emitter.EmitLoadFloat(0);
              emitter.EmitNewObj(emitter.FindMethod("complex", ".ctor", "float", "float"));
            }

            Right.Compile(emitter);
            if (rightType != "complex")
            {
              emitter.EmitUpcastBasicType(rightType, "float");
              emitter.EmitLoadFloat(0);
              emitter.EmitNewObj(emitter.FindMethod("complex", ".ctor", "float", "float"));
            }

            emitter.EmitCall(emitter.AssemblyImport(typeof(SN.Complex).GetMethod("op_Multiply", new[] { typeof(SN.Complex), typeof(SN.Complex) })));
              }

              // repeat array
              else if (leftType.EndsWith("[]"))
              {
            Left.Compile(emitter);
            Right.Compile(emitter);
            var method = emitter.AssemblyImport(typeof(MirelleStdlib.ArrayHelper).GetMethod("RepeatArray", new[] { typeof(object), typeof(int) }));
            emitter.EmitCall(method);
              }

              // multiply floating point numbers or integers
              else if (type.IsAnyOf("int", "float"))
              {
            Left.Compile(emitter);
            emitter.EmitUpcastBasicType(leftType, type);
            Right.Compile(emitter);
            emitter.EmitUpcastBasicType(rightType, type);
            emitter.EmitMul();
              }
        }
开发者ID:menozz,项目名称:mirelle,代码行数:93,代码来源:OperatorMultiplyNode.cs


注:本文中的Emitter.EmitConvertToFloat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。