本文整理汇总了C#中CodeGen.Finish方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGen.Finish方法的具体用法?C# CodeGen.Finish怎么用?C# CodeGen.Finish使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeGen
的用法示例。
在下文中一共展示了CodeGen.Finish方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitGenerator
private void EmitGenerator(CodeGen ncg)
{
YieldTarget[] targets = YieldLabelBuilder.BuildYieldTargets(this, ncg);
Label[] jumpTable = new Label[yieldCount];
for (int i = 0; i < yieldCount; i++) jumpTable[i] = targets[i].TopBranchTarget;
ncg.yieldLabels = jumpTable;
// Generator will ofcourse yield, but we are not interested in the isBlockYielded value
// hence push a dummySlot to pass the Assertion.
Slot dummySlot = ncg.GetLocalTmp(typeof(object));
ncg.PushTryBlock(dummySlot);
ncg.BeginExceptionBlock();
ncg.Emit(OpCodes.Ldarg_0);
ncg.EmitFieldGet(typeof(Generator), "location");
ncg.Emit(OpCodes.Switch, jumpTable);
// fall-through on first pass
// yield statements will insert the needed labels after their returns
Body.Emit(ncg);
//free the dummySlot
ncg.FreeLocalTmp(dummySlot);
// fall-through is almost always possible in generators, so this
// is almost always needed
ncg.EmitReturnInGenerator(null);
// special handling for StopIteration thrown in body
ncg.BeginCatchBlock(typeof(StopIterationException));
ncg.EndExceptionBlock();
ncg.EmitReturnInGenerator(null);
ncg.PopTargets();
ncg.Finish();
}
示例2: EmitGenerator
private void EmitGenerator(CodeGen ncg)
{
Debug.Assert(_topTargets != null);
Label[] jumpTable = new Label[_topTargets.Count];
for (int i = 0; i < jumpTable.Length; i++) {
jumpTable[i] = _topTargets[i].EnsureLabel(ncg);
}
ncg.YieldLabels = jumpTable;
Slot router = ncg.GetLocalTmp(typeof(int));
ncg.EmitGetGeneratorLocation();
router.EmitSet(ncg);
ncg.GotoRouter = router;
router.EmitGet(ncg);
ncg.Emit(OpCodes.Switch, jumpTable);
// fall-through on first pass
// yield statements will insert the needed labels after their returns
Body.Emit(ncg);
// fall-through is almost always possible in generators, so this
// is almost always needed
ncg.EmitReturnInGenerator(null);
ncg.Finish();
ncg.GotoRouter = null;
ncg.FreeLocalTmp(router);
}