本文整理汇总了C#中CodeGen.EmitInt方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGen.EmitInt方法的具体用法?C# CodeGen.EmitInt怎么用?C# CodeGen.EmitInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeGen
的用法示例。
在下文中一共展示了CodeGen.EmitInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetEnvironmentType
private static Type GetEnvironmentType(int size, CodeGen cg, out ConstructorInfo ctor, out EnvironmentFactory ef)
{
Type envType;
#region Generated partial factories
// *** BEGIN GENERATED CODE ***
if (size <= 32 && Options.OptimizeEnvironments) {
if (size <= 2) {
envType = typeof(FunctionEnvironment2Dictionary);
} else if (size <= 4) {
envType = typeof(FunctionEnvironment4Dictionary);
} else if (size <= 8) {
envType = typeof(FunctionEnvironment8Dictionary);
} else if (size <= 16) {
envType = typeof(FunctionEnvironment16Dictionary);
} else {
envType = typeof(FunctionEnvironment32Dictionary);
}
ctor = envType.GetConstructor(new Type[] { typeof(FunctionEnvironmentDictionary), typeof(IModuleEnvironment), typeof(SymbolId[]), typeof(SymbolId[]) });
ef = new FieldEnvironmentFactory(envType);
} else {
cg.EmitInt(size);
envType = typeof(FunctionEnvironmentNDictionary);
ctor = envType.GetConstructor(new Type[] { typeof(int), typeof(FunctionEnvironmentDictionary), typeof(IModuleEnvironment), typeof(SymbolId[]), typeof(SymbolId[]) });
ef = new IndexEnvironmentFactory(size);
}
// *** END GENERATED CODE ***
#endregion
return envType;
}
示例2: EmitGet
public override void EmitGet(CodeGen cg)
{
Contract.RequiresNotNull(cg, "cg");
_param.EmitGet(cg);
cg.EmitInt(_index);
cg.Emit(OpCodes.Ldelem_Ref);
}
示例3: EmitGet
public override void EmitGet(CodeGen cg)
{
Contract.RequiresNotNull(cg, "cg");
_instance.EmitGet(cg);
cg.EmitInt(_index);
if (Type == typeof(object)) cg.Emit(OpCodes.Ldelem_Ref);
else cg.Emit(OpCodes.Ldelem, Type);
}
示例4: EmitGetAddr
public override void EmitGetAddr(CodeGen cg)
{
instance.EmitGet(cg);
cg.EmitInt(index);
cg.Emit(OpCodes.Ldelema, Type);
}
示例5: EmitYieldDispatch
private void EmitYieldDispatch(List<YieldTarget> yieldTargets, Slot isYielded, Slot choiceVar, CodeGen cg)
{
if (IsBlockYieldable(yieldTargets)) {
cg.EmitFieldGet(typeof(Ops).GetField("FALSE"));
isYielded.EmitSet(cg);
int index = 0;
foreach (YieldTarget yt in yieldTargets) {
choiceVar.EmitGet(cg);
cg.EmitInt(index);
cg.Emit(OpCodes.Beq, yt.YieldContinuationTarget);
index++;
}
}
}
示例6: Emit
//.........这里部分代码省略.........
cg.EmitPosition(Start, header);
if (IsBlockYieldable(tryYieldTargets)) {
tryChoiceVar = cg.GetLocalTmp(typeof(int));
isTryYielded = cg.Names.GetTempSlot("is", typeof(object));
cg.EmitFieldGet(typeof(Ops).GetField("FALSE"));
isTryYielded.EmitSet(cg);
}
if (IsBlockYieldable(catchYieldTargets)) {
catchChoiceVar = cg.GetLocalTmp(typeof(int));
storedException = cg.Names.GetTempSlot("exc", typeof(object));
isCatchYielded = cg.Names.GetTempSlot("is", typeof(object));
cg.EmitFieldGet(typeof(Ops).GetField("FALSE"));
isCatchYielded.EmitSet(cg);
}
if (IsBlockYieldable(finallyYieldTargets)) {
finallyChoiceVar = cg.GetLocalTmp(typeof(int));
isFinallyYielded = cg.Names.GetTempSlot("is", typeof(object));
cg.EmitFieldGet(typeof(Ops).GetField("FALSE"));
isFinallyYielded.EmitSet(cg);
}
if (IsBlockYieldable(elseYieldTargets)) {
elseChoiceVar = cg.GetLocalTmp(typeof(int));
isElseYielded = cg.Names.GetTempSlot("is", typeof(object));
cg.EmitFieldGet(typeof(Ops).GetField("FALSE"));
isElseYielded.EmitSet(cg);
}
if (elseStmt != null) {
isElseBlock = cg.GetLocalTmp(typeof(bool));
cg.EmitInt(0);
isElseBlock.EmitSet(cg);
}
Slot exception = null;
bool foundLoopControl;
bool returnInFinally = ControlFlowFinder.FindControlFlow(FinallyStatement, out foundLoopControl);
if (IsBlockYieldable(finallyYieldTargets)) {
exception = cg.Names.GetTempSlot("exception", typeof(Exception));
cg.Emit(OpCodes.Ldnull);
exception.EmitSet(cg);
} else if (returnInFinally) {
exception = cg.GetLocalTmp(typeof(Exception));
cg.Emit(OpCodes.Ldnull);
exception.EmitSet(cg);
}
EmitTopYieldTargetLabels(tryYieldTargets, tryChoiceVar, cg);
EmitTopYieldTargetLabels(catchYieldTargets, catchChoiceVar, cg);
EmitTopYieldTargetLabels(elseYieldTargets, elseChoiceVar, cg);
EmitTopYieldTargetLabels(finallyYieldTargets, finallyChoiceVar, cg);
cg.EmitInt(CodeGen.FinallyExitsNormally);
flowControlVar.EmitSet(cg);
Label afterFinally = cg.DefineLabel();
cg.PushExceptionBlock(Targets.TargetBlockType.Try, flowControlVar, isTryYielded);
cg.BeginExceptionBlock();
// if catch yielded, rethow the storedException to be handled by Catch block
if (IsBlockYieldable(catchYieldTargets)) {
示例7: EmitEnvironmentIDs
private void EmitEnvironmentIDs(CodeGen cg)
{
int size = 0;
foreach (KeyValuePair<SymbolId, Binding> kv in names) {
if (kv.Value.IsEnvironment) size++;
}
// Create the array for the names
cg.EmitInt(size);
cg.Emit(OpCodes.Newarr, typeof(SymbolId));
int index = 0;
foreach (KeyValuePair<SymbolId, Binding> kv in names) {
if (kv.Value.IsEnvironment) {
cg.Emit(OpCodes.Dup);
cg.EmitInt(index++);
cg.Emit(OpCodes.Ldelema, typeof(SymbolId));
cg.EmitSymbolIdId(kv.Key);
cg.Emit(OpCodes.Call, typeof(SymbolId).GetConstructor(new Type[] { typeof(int) }));
}
}
}
示例8: Generate
public override void Generate(CodeGen cg, Slot contextSlot, Slot[] argSlots)
{
cg.EmitInt(count);
cg.Emit(OpCodes.Newarr, parameter.Type);
for (int i = 0; i < count; i++) {
cg.Emit(OpCodes.Dup);
cg.EmitInt(i);
argSlots[start + i].EmitGet(cg);
cg.EmitConvertFromObject(parameter.Type);
cg.EmitStelem(parameter.Type);
}
}
示例9: EmitFinallyFlowControl
/// <summary>
/// If the finally statement contains break, continue, return or yield, we need to
/// handle the control flow statement after we exit out of finally via OpCodes.Endfinally.
/// </summary>
private static void EmitFinallyFlowControl(CodeGen cg, TryFlowResult flow, Slot flag)
{
if (flow.Return || flow.Yield) {
Debug.Assert(flag != null);
Label noReturn = cg.DefineLabel();
flag.EmitGet(cg);
cg.EmitInt(CodeGen.BranchForReturn);
cg.Emit(OpCodes.Bne_Un, noReturn);
if (cg.IsGenerator) {
// return true from the generator method
cg.Emit(OpCodes.Ldc_I4_1);
cg.EmitReturn();
} else if (flow.Any) {
// return the actual value
cg.EmitReturnValue();
cg.EmitReturn();
}
cg.MarkLabel(noReturn);
}
// Only emit break handling if it is actually needed
if (flow.Break) {
Debug.Assert(flag != null);
Label noReturn = cg.DefineLabel();
flag.EmitGet(cg);
cg.EmitInt(CodeGen.BranchForBreak);
cg.Emit(OpCodes.Bne_Un, noReturn);
cg.EmitBreak();
cg.MarkLabel(noReturn);
}
// Only emit continue handling if it if actually needed
if (flow.Continue) {
Debug.Assert(flag != null);
Label noReturn = cg.DefineLabel();
flag.EmitGet(cg);
cg.EmitInt(CodeGen.BranchForContinue);
cg.Emit(OpCodes.Bne_Un, noReturn);
cg.EmitContinue();
cg.MarkLabel(noReturn);
}
}
示例10: EmitYieldDispatch
internal static void EmitYieldDispatch(List<YieldTarget> targets, CodeGen cg)
{
if (YieldInBlock(targets)) {
Debug.Assert(cg.GotoRouter != null);
// TODO: Emit as switch!
foreach (YieldTarget yt in targets) {
cg.GotoRouter.EmitGet(cg);
cg.EmitInt(yt.Index);
cg.Emit(OpCodes.Beq, yt.EnsureLabel(cg));
}
}
}
示例11: TryEmitJumpTable
// Tries to emit switch as a jmp table
private bool TryEmitJumpTable(CodeGen cg, Label[] labels, Label defaultTarget)
{
if (_cases.Count > MaxJumpTableSize) {
return false;
}
int min = Int32.MaxValue;
int max = Int32.MinValue;
// Find the min and max of the values
for (int i = 0; i < _cases.Count; ++i) {
// Not the default case.
if (!_cases[i].IsDefault) {
int val = _cases[i].Value;
if (min > val) min = val;
if (max < val) max = val;
}
}
long delta = (long)max - (long)min;
if (delta > MaxJumpTableSize) {
return false;
}
// Value distribution is too sparse, don't emit jump table.
if (delta > _cases.Count + MaxJumpTableSparsity) {
return false;
}
// The actual jmp table of switch
int len = (int)delta + 1;
Label[] jmpLabels = new Label[len];
// Initialize all labels to the default
for (int i = 0; i < len; i++) {
jmpLabels[i] = defaultTarget;
}
// Replace with the actual label target for all cases
for (int i = 0; i < _cases.Count; i++) {
SwitchCase sc = _cases[i];
if (!sc.IsDefault) {
jmpLabels[sc.Value - min] = labels[i];
}
}
// Emit the normalized index and then switch based on that
if (min != 0) {
cg.EmitInt(min);
cg.Emit(OpCodes.Sub);
}
cg.Emit(OpCodes.Switch, jmpLabels);
return true;
}
示例12: EmitConditionalBranches
// Emits the switch as if stmts
private void EmitConditionalBranches(CodeGen cg, Label[] labels)
{
Slot testValueSlot = cg.GetNamedLocal(typeof(int), "switchTestValue");
testValueSlot.EmitSet(cg);
// For all the "cases" create their conditional branches
for (int i = 0; i < _cases.Count; i++) {
// Not default case emit the condition
if (!_cases[i].IsDefault) {
// Test for equality of case value and the test expression
cg.EmitInt(_cases[i].Value);
testValueSlot.EmitGet(cg);
cg.Emit(OpCodes.Beq, labels[i]);
}
}
}
示例13: EmitGet
public override void EmitGet(CodeGen cg)
{
param.EmitGet(cg);
cg.EmitInt(index);
cg.Emit(OpCodes.Ldelem_Ref);
}
示例14: EmitSet
public override void EmitSet(CodeGen cg, Slot val)
{
val.EmitGet(cg);
cg.EmitConvertToObject(Type);
val = cg.GetLocalTmp(typeof(object));
val.EmitSet(cg);
instance.EmitGet(cg);
cg.EmitInt(index);
val.EmitGet(cg);
cg.Emit(OpCodes.Stelem_Ref);
}
示例15: EmitSet
internal override void EmitSet(CodeGen cg)
{
// Disallow "[] = l", "[], a = l, l", "[[]] = [l]", etc
if (items.Length == 0) {
cg.Context.AddError("can't assign to " + EmptySequenceString, this);
return;
}
// int leftCount = items.Length;
Slot leftCount = cg.GetLocalTmp(typeof(int));
cg.EmitInt(items.Length);
leftCount.EmitSet(cg);
// object[] values = new object[leftCount];
Slot values = cg.GetLocalTmp(typeof(object[]));
leftCount.EmitGet(cg);
cg.Emit(OpCodes.Newarr, typeof(object));
values.EmitSet(cg);
// ie = Ops.GetEnumerator(<value on stack>)
Slot ie = cg.GetLocalTmp(typeof(IEnumerator));
cg.EmitCall(typeof(Ops), "GetEnumeratorForUnpack");
ie.EmitSet(cg);
// int rightCount = Ops.GetEnumeratorValues(ie, ref values);
Slot rightCount = cg.GetLocalTmp(typeof(int));
ie.EmitGet(cg);
values.EmitGetAddr(cg);
cg.EmitCall(typeof(Ops), "GetEnumeratorValues");
rightCount.EmitSet(cg);
// if (leftCount != rightCount)
// throw Ops.ValueErrorForUnpackMismatch(leftCount, rightCount);
Label equalSizes = cg.DefineLabel();
leftCount.EmitGet(cg);
rightCount.EmitGet(cg);
cg.Emit(OpCodes.Ceq);
cg.Emit(OpCodes.Brtrue_S, equalSizes);
leftCount.EmitGet(cg);
rightCount.EmitGet(cg);
cg.EmitCall(typeof(Ops).GetMethod("ValueErrorForUnpackMismatch"));
cg.Emit(OpCodes.Throw);
cg.MarkLabel(equalSizes);
// for (int i = 0; i < leftCount; i++)
// items[i].Assign(values[i], env);
int i = 0;
foreach (Expression expr in items) {
values.EmitGet(cg);
cg.EmitInt(i++);
cg.Emit(OpCodes.Ldelem_Ref);
expr.EmitSet(cg);
}
cg.FreeLocalTmp(leftCount);
cg.FreeLocalTmp(rightCount);
cg.FreeLocalTmp(values);
cg.FreeLocalTmp(ie);
}