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


C# Emitter.EmitCompareEqual方法代码示例

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


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

示例1: Compile

        public override void Compile(Emitter.Emitter emitter)
        {
            if (Expression.GetExpressionType(emitter) != "bool")
            Error(Resources.errBoolExpected);

              Expression.Compile(emitter);
              emitter.EmitLoadBool(false);
              emitter.EmitCompareEqual();
        }
开发者ID:menozz,项目名称:mirelle,代码行数:9,代码来源:OperatorNegateNode.cs

示例2: CompileRelation

        /// <summary>
        /// Compare two values for their relative order: less and greater
        /// </summary>
        /// <param name="emitter">Emitter link</param>
        /// <param name="leftType">Left-hand argument type</param>
        /// <param name="rightType">Left-hand argument type</param>
        private void CompileRelation(Emitter.Emitter emitter, string leftType, string rightType)
        {
            if(leftType == "string")
              {
            var method = emitter.AssemblyImport(typeof(string).GetMethod("Compare", new[] { typeof(string), typeof(string) }));
            emitter.EmitCall(method);
            emitter.EmitLoadBool(false);
              }

              switch (ComparisonType)
              {
            case LexemType.Less: emitter.EmitCompareLess(); break;

            case LexemType.LessEqual: emitter.EmitCompareGreater();
              emitter.EmitLoadBool(false);
              emitter.EmitCompareEqual(); break;

            case LexemType.Greater: emitter.EmitCompareGreater(); break;

            case LexemType.GreaterEqual: emitter.EmitCompareLess();
              emitter.EmitLoadBool(false);
              emitter.EmitCompareEqual(); break;
              }
        }
开发者ID:menozz,项目名称:mirelle,代码行数:30,代码来源:OperatorCompareNode.cs

示例3: CompileEquality

        /// <summary>
        /// Compare two values for their equality
        /// </summary>
        /// <param name="emitter">Emitter link</param>
        /// <param name="leftType">Left-hand argument type</param>
        /// <param name="rightType">Left-hand argument type</param>
        private void CompileEquality(Emitter.Emitter emitter, string leftType, string rightType)
        {
            var basicTypes = new[] { "bool", "int", "float", "string" };
              if (leftType.IsAnyOf(basicTypes))
              {
            // compare strings
            if (leftType == "string")
            {
              var method = emitter.AssemblyImport(typeof(string).GetMethod("Compare", new[] { typeof(string), typeof(string) }));
              emitter.EmitCall(method);
              emitter.EmitLoadBool(false);
            }

            emitter.EmitCompareEqual();
              }

              // long, complex and others
              else
              {
            System.Reflection.MethodInfo method;
            if(leftType.IsAnyOf("long", "complex"))
            {
              var type = (leftType == "long" ? typeof(System.Numerics.BigInteger) : typeof(System.Numerics.Complex));
              method = type.GetMethod("op_Equality", new[] { type, type });
            }
            else
              method = typeof(MirelleStdlib.Compare).GetMethod("Equal", new[] { typeof(object), typeof(object) });

            emitter.EmitCall(emitter.AssemblyImport(method));
              }

              // invert ?
              if (ComparisonType == LexemType.NotEqual)
              {
            emitter.EmitLoadBool(false);
            emitter.EmitCompareEqual();
              }
        }
开发者ID:menozz,项目名称:mirelle,代码行数:44,代码来源:OperatorCompareNode.cs

示例4: Compile

        public override void Compile(Emitter.Emitter emitter)
        {
            // make sure there is an array
              var exprType = Expression.GetExpressionType(emitter);
              if (!exprType.Contains("[]"))
            Error(Resources.errSplatArrayExpected);

              // define required variables
              var type = emitter.GetArrayItemType(exprType);
              var typeRef = emitter.ResolveType(type);
              var idx = 0;
              var tmpVar = emitter.CurrentMethod.Scope.Introduce(exprType, emitter.ResolveType(exprType));

              // compile array
              Expression.Compile(emitter);
              emitter.EmitSaveVariable(tmpVar);

              foreach(var curr in Names)
              {
            // check for variable redefinition
            if (emitter.CurrentMethod.Scope.Exists(curr.Data))
              Error(String.Format(Resources.errVariableRedefinition, curr.Data), curr);

            var varDecl = emitter.CurrentMethod.Scope.Introduce(type, emitter.ResolveType(type), curr.Data);
            var elseLabel = emitter.CreateLabel();
            var endLabel = emitter.CreateLabel();

            // make sure the array is not a null
            emitter.EmitLoadNull();
            emitter.EmitLoadVariable(tmpVar);
            emitter.EmitCompareEqual();
            emitter.EmitBranchTrue(elseLabel);

            // make sure there are items in the array
            emitter.EmitLoadInt(idx);
            emitter.EmitLoadVariable(tmpVar);
            emitter.EmitLoadArraySize();
            emitter.EmitCompareLess();
            emitter.EmitBranchFalse(elseLabel);

            // retrieve the current value
            emitter.EmitLoadVariable(tmpVar);
            emitter.EmitLoadInt(idx);
            if(type == "complex")
            {
              emitter.EmitLoadIndexAddress(typeRef);
              emitter.EmitLoadObject(typeRef);
            }
            else
              emitter.EmitLoadIndex(type);
            emitter.EmitBranch(endLabel);

            // or create a default
            emitter.PlaceLabel(elseLabel);
            emitter.EmitLoadDefaultValue(type);

            // assign the variable
            emitter.PlaceLabel(endLabel);
            emitter.EmitSaveVariable(varDecl);

            idx++;
              }
        }
开发者ID:menozz,项目名称:mirelle,代码行数:63,代码来源:VarSplatNode.cs

示例5: CompileRange

        /// <summary>
        /// Create iteration code for a range
        /// </summary>
        /// <param name="emitter"></param>
        public void CompileRange(Emitter.Emitter emitter)
        {
            // make local variables only visible inside the scope
              emitter.CurrentMethod.Scope.EnterSubScope();
              var idxVar = emitter.CurrentMethod.Scope.Introduce("int", emitter.ResolveType("int"), Key == null ? null : Key.Data);
              var rangeVar = emitter.CurrentMethod.Scope.Introduce("range", emitter.ResolveType("range"));
              var currVar = emitter.CurrentMethod.Scope.Introduce("int", emitter.ResolveType("int"), Item.Data);

              // preface: range = ..., range.reset
              Iterable.Compile(emitter);
              emitter.EmitSaveVariable(rangeVar);
              emitter.EmitLoadVariable(rangeVar);
              emitter.EmitCall(emitter.FindMethod("range", "reset"));

              // set key if exists
              if(Key != null)
              {
            emitter.EmitLoadInt(-1);
            emitter.EmitSaveVariable(idxVar);
              }

              // range.next == false ? exit
              emitter.PlaceLabel(BodyStart);
              emitter.EmitLoadVariable(rangeVar);
              emitter.EmitCall(emitter.FindMethod("range", "next"));
              emitter.EmitLoadBool(false);
              emitter.EmitCompareEqual();
              emitter.EmitBranchTrue(BodyEnd);

              // curr = range.current
              emitter.EmitLoadVariable(rangeVar);
              emitter.EmitCall(emitter.FindMethod("range", "current"));
              emitter.EmitSaveVariable(currVar);

              // increment key if exists
              if(Key != null)
              {
            emitter.EmitLoadVariable(idxVar);
            emitter.EmitLoadInt(1);
            emitter.EmitAdd();
            emitter.EmitSaveVariable(idxVar);
              }

              // body
              var preCurrLoop = emitter.CurrentLoop;
              emitter.CurrentLoop = this;
              Body.Compile(emitter);
              emitter.CurrentLoop = preCurrLoop;

              emitter.EmitBranch(BodyStart);

              emitter.PlaceLabel(BodyEnd);
              emitter.CurrentMethod.Scope.LeaveSubScope();
        }
开发者ID:menozz,项目名称:mirelle,代码行数:58,代码来源:ForNode.cs

示例6: CompileDict

        /// <summary>
        /// Create iteration code for a dictionary
        /// </summary>
        /// <param name="emitter"></param>
        public void CompileDict(Emitter.Emitter emitter)
        {
            // check if key defined
              if (Key == null)
            Error(Resources.errDictIterKeyRequired);

              // make local variables only visible inside the scope
              emitter.CurrentMethod.Scope.EnterSubScope();
              var dictVar = emitter.CurrentMethod.Scope.Introduce("dict", emitter.ResolveType("dict"));
              var currVar = emitter.CurrentMethod.Scope.Introduce("string[]", emitter.ResolveType("string[]"));
              var keyVar = emitter.CurrentMethod.Scope.Introduce("string", emitter.ResolveType("string"), Key.Data);
              var itemVar = emitter.CurrentMethod.Scope.Introduce("string", emitter.ResolveType("string"), Item.Data);

              // preface: dictVar = ...;
              Iterable.Compile(emitter);
              emitter.EmitSaveVariable(dictVar);
              emitter.EmitLoadVariable(dictVar);
              emitter.EmitCall(emitter.FindMethod("dict", "reset"));

              // dict.next == false ? exit
              emitter.PlaceLabel(BodyStart);
              emitter.EmitLoadVariable(dictVar);
              emitter.EmitCall(emitter.FindMethod("dict", "next"));
              emitter.EmitLoadBool(false);
              emitter.EmitCompareEqual();
              emitter.EmitBranchTrue(BodyEnd);

              // curr = dict.current
              emitter.EmitLoadVariable(dictVar);
              emitter.EmitCall(emitter.FindMethod("dict", "current"));
              emitter.EmitSaveVariable(currVar);

              // (key, value) = curr
              emitter.EmitLoadVariable(currVar);
              emitter.EmitLoadInt(0);
              emitter.EmitLoadIndex("string");
              emitter.EmitSaveVariable(keyVar);
              emitter.EmitLoadVariable(currVar);
              emitter.EmitLoadInt(1);
              emitter.EmitLoadIndex("string");
              emitter.EmitSaveVariable(itemVar);

              // body
              var preCurrLoop = emitter.CurrentLoop;
              emitter.CurrentLoop = this;
              Body.Compile(emitter);
              emitter.CurrentLoop = preCurrLoop;

              emitter.EmitBranch(BodyStart);

              emitter.PlaceLabel(BodyEnd);
              emitter.CurrentMethod.Scope.LeaveSubScope();
        }
开发者ID:menozz,项目名称:mirelle,代码行数:57,代码来源:ForNode.cs


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