本文整理汇总了C#中Emitter.EmitCompareLess方法的典型用法代码示例。如果您正苦于以下问题:C# Emitter.EmitCompareLess方法的具体用法?C# Emitter.EmitCompareLess怎么用?C# Emitter.EmitCompareLess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Emitter
的用法示例。
在下文中一共展示了Emitter.EmitCompareLess方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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++;
}
}
示例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;
}
}
示例3: CompileArray
/// <summary>
/// Create iteration code for an array
/// </summary>
/// <param name="emitter"></param>
public void CompileArray(Emitter.Emitter emitter)
{
var iterType = Iterable.GetExpressionType(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 arrVar = emitter.CurrentMethod.Scope.Introduce(iterType, emitter.ResolveType(iterType));
var currType = emitter.GetArrayItemType(iterType);
var currVar = emitter.CurrentMethod.Scope.Introduce(currType, emitter.ResolveType(currType), Item.Data);
// prelude: arr = ..., idx = -1
Iterable.Compile(emitter);
emitter.EmitSaveVariable(arrVar);
emitter.EmitLoadInt(-1);
emitter.EmitSaveVariable(idxVar);
emitter.PlaceLabel(BodyStart);
// increment
emitter.EmitLoadVariable(idxVar);
emitter.EmitLoadInt(1);
emitter.EmitAdd();
emitter.EmitSaveVariable(idxVar);
// loop exit condition
emitter.EmitLoadVariable(idxVar);
emitter.EmitLoadVariable(arrVar);
emitter.EmitLoadArraySize();
emitter.EmitCompareLess();
emitter.EmitBranchFalse(BodyEnd);
// variable: curr = array[idx]
emitter.EmitLoadVariable(arrVar);
emitter.EmitLoadVariable(idxVar);
emitter.EmitLoadIndex(currType);
emitter.EmitSaveVariable(currVar);
// body
var preCurrLoop = emitter.CurrentLoop;
emitter.CurrentLoop = this;
Body.Compile(emitter);
emitter.CurrentLoop = preCurrLoop;
emitter.EmitBranch(BodyStart);
emitter.PlaceLabel(BodyEnd);
emitter.CurrentMethod.Scope.LeaveSubScope();
}