本文整理汇总了C#中Emitter.CreateLabel方法的典型用法代码示例。如果您正苦于以下问题:C# Emitter.CreateLabel方法的具体用法?C# Emitter.CreateLabel怎么用?C# Emitter.CreateLabel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Emitter
的用法示例。
在下文中一共展示了Emitter.CreateLabel方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compile
public override void Compile(Emitter.Emitter emitter)
{
// check types
var leftType = Left.GetExpressionType(emitter);
var rightType = Right.GetExpressionType(emitter);
if (leftType != "bool" || rightType != "bool")
Error(String.Format(Resources.errOperatorTypesMismatch, "||", leftType, rightType));
// create labels
var labelElse = emitter.CreateLabel();
var labelEnd = emitter.CreateLabel();
Left.Compile(emitter);
emitter.EmitBranchFalse(labelElse);
emitter.EmitLoadBool(true);
emitter.EmitBranch(labelEnd);
emitter.PlaceLabel(labelElse);
Right.Compile(emitter);
emitter.PlaceLabel(labelEnd);
}
示例2: Compile
public override void Compile(Emitter.Emitter emitter)
{
// check if condition is boolean
var condType = Condition.GetExpressionType(emitter);
MethodNode converter = null;
if (condType != "bool")
{
try
{
converter = emitter.FindMethod(condType, "to_b");
}
catch
{
Error(Resources.errBoolExpected);
}
}
// create markers
BodyStart = emitter.CreateLabel();
BodyEnd = emitter.CreateLabel();
emitter.PlaceLabel(BodyStart);
// condition
Condition.Compile(emitter);
if (converter != null)
emitter.EmitCall(converter);
emitter.EmitBranchFalse(BodyEnd);
// body
var preCurrLoop = emitter.CurrentLoop;
emitter.CurrentLoop = this;
Body.Compile(emitter);
emitter.CurrentLoop = preCurrLoop;
// re-test condition
emitter.EmitBranch(BodyStart);
emitter.PlaceLabel(BodyEnd);
}
示例3: Compile
public override void Compile(Emitter.Emitter emitter)
{
// check variable
if (emitter.CurrentMethod.Scope.Exists(Item.Data))
Error(String.Format(Resources.errVariableRedefinition, Item.Data), Item);
// check key if exists
if (Key != null && emitter.CurrentMethod.Scope.Exists(Key.Data))
Error(String.Format(Resources.errVariableRedefinition, Key.Data), Key);
// define labels
BodyStart = emitter.CreateLabel();
BodyEnd = emitter.CreateLabel();
var iterType = Iterable.GetExpressionType(emitter);
if (iterType == "range")
CompileRange(emitter);
else if (iterType == "dict")
CompileDict(emitter);
else if (iterType.EndsWith("[]"))
CompileArray(emitter);
else
Error(Resources.errForIterableExpected);
}
示例4: Compile
public override void Compile(Emitter.Emitter emitter)
{
// check if condition is boolean or can be converted
var condType = Condition.GetExpressionType(emitter);
MethodNode converter = null;
if (condType != "bool")
{
try
{
converter = emitter.FindMethod(condType, "to_b");
}
catch
{
Error(Resources.errBoolExpected);
}
}
FalseBlockStart = emitter.CreateLabel();
// condition
Condition.Compile(emitter);
if (converter != null)
emitter.EmitCall(converter);
emitter.EmitBranchFalse(FalseBlockStart);
// "true" body
TrueBlock.Compile(emitter);
// there is a false block?
if(FalseBlock != null)
{
// create a jump
FalseBlockEnd = emitter.CreateLabel();
emitter.EmitBranch(FalseBlockEnd);
emitter.PlaceLabel(FalseBlockStart);
// "false" body
FalseBlock.Compile(emitter);
emitter.PlaceLabel(FalseBlockEnd);
}
else
{
// put the 'nop' after the condition body
emitter.PlaceLabel(FalseBlockStart);
}
}
示例5: 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++;
}
}