本文整理汇总了C#中ILGen.DeclareLocal方法的典型用法代码示例。如果您正苦于以下问题:C# ILGen.DeclareLocal方法的具体用法?C# ILGen.DeclareLocal怎么用?C# ILGen.DeclareLocal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILGen
的用法示例。
在下文中一共展示了ILGen.DeclareLocal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LabelInfo
internal LabelInfo(ILGen il, LabelTarget node, bool canReturn) {
_ilg = il;
Node = node;
Label = il.DefineLabel();
_canReturn = canReturn;
if (node != null && node.Type != typeof(void)) {
Value = il.DeclareLocal(node.Type);
}
// Until we have more information, default to a leave instruction, which always works
_opCode = OpCodes.Leave;
}
示例2: GetBranch
private Branch GetBranch(List<Branch> branches, ILGen il, Type type)
{
foreach (Branch b in branches)
if (b.type == type)
return b;
Branch branch = new Branch();
branch.type = type;
branch.localVar = il.DeclareLocal(type);
branch.handler = il.DefineLabel();
branches.Add(branch);
return branch;
}
示例3: EmitArgument
internal static ReturnFixer EmitArgument(ILGen cg, int argIndex, Type argType) {
cg.EmitLoadArg(argIndex);
if (!argType.IsByRef) {
cg.EmitBoxing(argType);
return null;
}
Type elementType = argType.GetElementType();
cg.EmitLoadValueIndirect(elementType);
Type concreteType = typeof(StrongBox<>).MakeGenericType(elementType);
cg.EmitNew(concreteType, new Type[] { elementType });
LocalBuilder refSlot = cg.DeclareLocal(concreteType);
cg.Emit(OpCodes.Dup);
cg.Emit(OpCodes.Stloc, refSlot);
return new ReturnFixer(refSlot, argIndex, argType);
}
示例4: Compile
public override Type Compile(Executive engine, ILGen il, LocalAccess locals, Type[] parameterTypes)
{
LocalBuilder[] localVar = new LocalBuilder[Name.Arity];
for (int k = Name.Arity -1; k >= 0; k--)
{
localVar[k] = il.DeclareLocal(Name.Signature[k]);
il.Emit(OpCodes.Stloc, localVar[k]);
}
il.Emit(OpCodes.Ldarg_1);
il.EmitInt(locals.DefineConstant(m_delegate));
il.Emit(OpCodes.Ldelem_Ref);
il.Emit(OpCodes.Isinst, m_delegate.GetType());
for (int k = 0; k < Name.Arity; k++)
{
il.Emit(OpCodes.Ldloc, localVar[k]);
il.FreeLocal(localVar[k]);
}
il.EmitCall(m_delegate.GetType(), "Invoke");
return m_delegate.Method.GetReturnType();
}
示例5: EmitConvertFromObject
/// <summary>
/// Emit code to convert object to a given type. This code is semantically equivalent
/// to PythonBinder.EmitConvertFromObject, except this version accepts ILGen whereas
/// PythonBinder accepts Compiler. The Binder will chagne soon and the two will merge.
/// </summary>
public void EmitConvertFromObject(ILGen il, Type toType) {
if (toType == typeof(object)) {
return;
} else if (toType == typeof(void)) {
il.Emit(OpCodes.Pop);
return;
}
var callTarget = il.DeclareLocal(typeof(object));
il.Emit(OpCodes.Stloc, callTarget);
if (toType.IsGenericParameter && toType.DeclaringMethod != null) {
MethodInfo siteFactory = GetGenericConversionSiteFactory(toType);
Debug.Assert(siteFactory.GetParameters().Length == 0 && typeof(CallSite).IsAssignableFrom(siteFactory.ReturnType));
// siteVar = GetConversionSite<T>()
var siteVar = il.DeclareLocal(siteFactory.ReturnType);
il.Emit(OpCodes.Call, siteFactory);
il.Emit(OpCodes.Stloc, siteVar);
// Emit the site invoke
il.Emit(OpCodes.Ldloc, siteVar);
FieldInfo target = siteVar.LocalType.GetField("Target");
il.EmitFieldGet(target);
il.Emit(OpCodes.Ldloc, siteVar);
// Emit the context
EmitContext(il, false);
il.Emit(OpCodes.Ldloc, callTarget);
il.EmitCall(target.FieldType, "Invoke");
} else {
var site = GetConversionSiteField(toType);
// Emit the site invoke
il.EmitFieldGet(site);
FieldInfo target = site.FieldType.GetField("Target");
il.EmitFieldGet(target);
il.EmitFieldGet(site);
// Emit the context
EmitContext(il, false);
il.Emit(OpCodes.Ldloc, callTarget);
il.EmitCall(target.FieldType, "Invoke");
}
}
示例6: EmitVirtualSiteCall
public void EmitVirtualSiteCall(ILGen il, MethodInfo mi, string name) {
Label baseCallLabel = il.DefineLabel();
LocalBuilder resultVar = il.DeclareLocal(typeof(object));
EmitClrCallStub(il, mi, name);
il.Emit(OpCodes.Stloc, resultVar);
il.Emit(OpCodes.Ldloc, resultVar);
il.Emit(OpCodes.Ldsfld, Fields.ForwardToBase);
il.Emit(OpCodes.Ceq);
il.Emit(OpCodes.Brtrue, baseCallLabel);
if (mi.ReturnType != typeof(void)) {
il.Emit(OpCodes.Ldloc, resultVar);
EmitConvertFromObject(il, mi.ReturnType);
}
il.Emit(OpCodes.Ret);
il.MarkLabel(baseCallLabel);
EmitBaseMethodDispatch(mi, il);
}
示例7: CreateUnaryOperationIC
public static void CreateUnaryOperationIC(ILGen.BaseILGenerator ilGen, IR.NodeType nodeType, int resultIndex, mdr.ValueTypes i0Type, bool i0TypeCheck)
{
ilGen.WriteComment("IC method for {0}({1}, {2}) written to {3}", nodeType, i0Type, i0Type, resultIndex);
var values = ilGen.DeclareLocal(CodeGen.Types.DValue.ArrayOf);
ilGen.Ldarg_CallFrame();
ilGen.Ldfld(CodeGen.Types.CallFrame.Values);
ilGen.Stloc(values);
var t0 = ilGen.DeclareLocal(CodeGen.Types.ClrSys.Int32);
//if (i0TypeCheck)
{
LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef);
ilGen.Call(CodeGen.Types.DValue.GetValueType);
ilGen.Stloc(t0);
}
var guardFail = ilGen.DefineLabel();
var done = ilGen.DefineLabel();
var operation = CodeGen.Types.Operations.Unary.Get(nodeType);
if (i0Type == mdr.ValueTypes.DValueRef) //Just a better guess!
i0Type = operation.ReturnType(i0Type); //we will need to repeat the lookup again
ilGen.Ldloc(t0);
ilGen.Ldc_I4((int)i0Type);
ilGen.Bne_Un(guardFail);
var mi = operation.Get(i0Type);
var returnType = operation.ReturnType(i0Type);
if (returnType == mdr.ValueTypes.DValueRef)
{
Debug.Assert(mi.GetParameters().Length == 2 && mi.GetParameters()[1].ParameterType == CodeGen.Types.TypeOf(mdr.ValueTypes.DValueRef), "Invalid situation, method {0} must get a second parameter of type 'ref DValue'", mi);
LoadValue(ilGen, values, resultIndex, i0Type);
LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef);
ilGen.Call(mi);
}
else
{
LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef);
LoadValue(ilGen, values, resultIndex, i0Type);
ilGen.Call(mi);
ilGen.Call(CodeGen.Types.DValue.Set.Get(returnType));
}
ilGen.Br(done);
ilGen.MarkLabel(guardFail);
ilGen.Ldarg_CallFrame();
ilGen.Ldarg_1();
ilGen.Ldc_I4((int)nodeType);
ilGen.Ldc_I4(resultIndex);
ilGen.Ldloc(t0);
ilGen.Ldc_I4(i0TypeCheck);
ilGen.Call(CodeGen.Types.Operations.ICMethods.RunAndUpdateUnaryOperationIC);
ilGen.Ret();
ilGen.MarkLabel(done);
}
示例8: CreateBinaryOperationIC
public static void CreateBinaryOperationIC(ILGen.BaseILGenerator ilGen, IR.NodeType nodeType, int resultIndex, mdr.ValueTypes i0Type, mdr.ValueTypes i1Type, bool i0TypeCheck, bool i1TypeCheck)
{
ilGen.WriteComment("IC method for {0}({1}, {2}) written to {3}", nodeType, i0Type, i0Type, resultIndex);
var values = ilGen.DeclareLocal(CodeGen.Types.DValue.ArrayOf);
ilGen.Ldarg_CallFrame();
ilGen.Ldfld(CodeGen.Types.CallFrame.Values);
ilGen.Stloc(values);
///Try to make a better guess on the unknown types.
if (i0Type == mdr.ValueTypes.DValueRef)
{
if (i1Type != mdr.ValueTypes.DValueRef)
i0Type = i1Type;
else
i0Type = i1Type = mdr.ValueTypes.Int32; //Just a guess!
}
else if (i1Type == mdr.ValueTypes.DValueRef)
i1Type = i0Type;
var t0 = ilGen.DeclareLocal(CodeGen.Types.ClrSys.Int32);
//if (i0TypeCheck)
{
LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef);
ilGen.Call(CodeGen.Types.DValue.GetValueType);
ilGen.Stloc(t0);
}
var t1 = ilGen.DeclareLocal(CodeGen.Types.ClrSys.Int32);
//if (i0TypeCheck)
{
LoadValue(ilGen, values, resultIndex + 1, mdr.ValueTypes.DValueRef);
ilGen.Call(CodeGen.Types.DValue.GetValueType);
ilGen.Stloc(t1);
}
var guardFail = ilGen.DefineLabel();
var done = ilGen.DefineLabel();
ilGen.Ldloc(t0);
ilGen.Ldc_I4(8);
ilGen.Shl();
ilGen.Ldloc(t1);
ilGen.Or();
ilGen.Ldc_I4(((int)i0Type << 8) | (int)i1Type);
ilGen.Bne_Un(guardFail);
var operation = CodeGen.Types.Operations.Binary.Get(nodeType);
var mi = operation.Get(i0Type, i1Type);
var returnType = operation.ReturnType(i0Type, i1Type);
if (returnType == mdr.ValueTypes.DValueRef)
{
Debug.Assert(mi.GetParameters().Length == 3 && mi.GetParameters()[2].ParameterType == CodeGen.Types.TypeOf(mdr.ValueTypes.DValueRef), "Invalid situation, method {0} must get a third parameter of type 'ref DValue'", mi);
LoadValue(ilGen, values, resultIndex, i0Type);
LoadValue(ilGen, values, resultIndex + 1, i1Type);
LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef);
ilGen.Call(mi);
}
else
{
LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef);
LoadValue(ilGen, values, resultIndex, i0Type);
LoadValue(ilGen, values, resultIndex + 1, i1Type);
ilGen.Call(mi);
ilGen.Call(CodeGen.Types.DValue.Set.Get(returnType));
}
ilGen.Br(done);
ilGen.MarkLabel(guardFail);
ilGen.Ldarg_CallFrame();
ilGen.Ldarg_1();
ilGen.Ldc_I4((int)nodeType);
ilGen.Ldc_I4(resultIndex);
ilGen.Ldloc(t0);
ilGen.Ldloc(t1);
ilGen.Ldc_I4(i0TypeCheck);
ilGen.Ldc_I4(i1TypeCheck);
ilGen.Call(CodeGen.Types.Operations.ICMethods.RunAndUpdateBinaryOperationIC);
ilGen.Ret();
ilGen.MarkLabel(done);
}
示例9: CompileExpr
internal void CompileExpr(ILGen il, LocalAccess locals, Stack<Type> st, object lval)
{
if (lval == null)
{
il.EmitNull();
st.Push(typeof(System.Object));
}
else if (Lisp.IsNode(lval))
{
if (lval == Lisp.NIL || lval == Lisp.T)
{
if (lval == Lisp.NIL)
il.EmitNull();
else
il.Emit(OpCodes.Ldsfld, typeof(RuntimeOps).GetField("True"));
st.Push(typeof(System.Object));
}
else if (lval == Lisp.INST)
{
il.Emit(OpCodes.Ldarg_0);
il.EmitPropertyGet(typeof(CompiledLambda), "Engine");
st.Push(typeof(Executive));
}
else if (lval == Lisp.ARGV)
{
il.Emit(OpCodes.Ldarg_2);
st.Push(typeof(object[]));
}
else if (lval == Lisp.MPOOL)
{
il.Emit(OpCodes.Ldarg_3);
st.Push(typeof(MemoryPool));
}
else
{
LocalBuilder localVar = locals.GetLocal(lval);
if (localVar != null)
{
il.Emit(OpCodes.Ldloc, localVar);
st.Push(localVar.LocalType);
}
else
{
Type type = lval.GetType();
if (type == typeof(Integer))
{
il.EmitDecimal((Decimal)((Integer)lval));
il.EmitNew(typeof(Integer).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null,
new Type[] { typeof(Decimal) }, null));
}
else if (!il.TryEmitConstant(lval, type))
{
il.Emit(OpCodes.Ldarg_1);
il.EmitInt(locals.DefineConstant(lval));
il.Emit(OpCodes.Ldelem_Ref);
if (type.IsValueType)
il.EmitUnbox(type);
}
st.Push(type);
}
}
}
else if (Lisp.IsFunctor(lval))
{
object head = Lisp.Car(lval);
object[] args = Lisp.ToArray(Lisp.Cdr(lval));
ControlFormBase control;
if (m_control.TryGetValue(head, out control))
control.Compile(this, lval, il, locals, st, args);
else
{
foreach (object a in args)
CompileExpr(il, locals, st, a);
Type[] parameterTypes = new Type[args.Length];
for (int k = args.Length - 1; k >= 0; k--)
parameterTypes[k] = st.Pop();
FuncName name = new FuncName(head, parameterTypes);
FuncBase body = GetFunc(name, false);
if (body == null)
{
bool successed = false;
if (parameterTypes.Length == 2)
{
Type castType = ValueProxy.GetType(parameterTypes[0], parameterTypes[1]);
ValueConverter converter1 = FindConverter(parameterTypes[0], castType);
ValueConverter converter2 = FindConverter(parameterTypes[1], castType);
body = GetFunc(new FuncName(name.ID, new Type[] { castType, castType }), false);
if (body != null && converter1 != null && converter2 != null)
{
LocalBuilder localVar = il.DeclareLocal(parameterTypes[1]);
il.Emit(OpCodes.Stloc, localVar);
converter1.Compile(this, il, locals, parameterTypes[0]);
il.Emit(OpCodes.Ldloc, localVar);
il.FreeLocal(localVar);
converter2.Compile(this, il, locals, parameterTypes[1]);
successed = true;
}
}
if (!successed)
{
//.........这里部分代码省略.........
示例10: EmitNonInheritedMethodLookup
/// <summary>
/// Emits the call to lookup a member defined in the user's type. Returns
/// the local which stores the resulting value and leaves a value on the
/// stack indicating the success of the lookup.
/// </summary>
private LocalBuilder EmitNonInheritedMethodLookup(string name, ILGen il) {
LocalBuilder callTarget = il.DeclareLocal(typeof(object));
// emit call to helper to do lookup
il.EmitLoadArg(0);
if (typeof(IPythonObject).IsAssignableFrom(_baseType)) {
Debug.Assert(_typeField == null);
il.EmitPropertyGet(TypeInfo._IPythonObject.PythonType);
} else {
il.EmitFieldGet(_typeField);
}
il.EmitLoadArg(0);
EmitSymbolId(il, name);
il.Emit(OpCodes.Ldloca, callTarget);
il.EmitCall(typeof(UserTypeOps), "TryGetNonInheritedMethodHelper");
return callTarget;
}
示例11: DefineCtors
static void DefineCtors(TypeBuilder proxyTB,
Type superClass,
string initName,
string postInitName,
ISeq ctorsTypes,
FieldBuilder initFB,
FieldBuilder postInitFB,
FieldBuilder stateFB,
string factoryName)
{
for (ISeq s = ctorsTypes; s != null; s = s.next())
{
IMapEntry me = (IMapEntry)s.first();
ISeq thisParamTypesV = (ISeq)me.key();
ISeq baseParamTypesV = (ISeq)me.val();
Type[] thisParamTypes = CreateTypeArray(thisParamTypesV);
Type[] baseParamTypes = CreateTypeArray(baseParamTypesV);
BindingFlags flags = BindingFlags.CreateInstance| BindingFlags.NonPublic| BindingFlags.Public| BindingFlags.Instance;
ConstructorInfo superCtor = superClass.GetConstructor(flags,null,baseParamTypes,null);
if (superCtor == null || superCtor.IsPrivate)
throw new InvalidOperationException("Base class constructor missing or private");
ConstructorBuilder cb = proxyTB.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis, thisParamTypes);
ILGen gen = new ILGen(cb.GetILGenerator());
Label noInitLabel = gen.DefineLabel();
Label noPostInitLabel = gen.DefineLabel();
Label endPostInitLabel = gen.DefineLabel();
Label endLabel = gen.DefineLabel();
LocalBuilder locSuperArgs = gen.DeclareLocal(typeof(object));
LocalBuilder locInitVal = gen.DeclareLocal(typeof(object));
if (initFB != null)
{
// init supplied
EmitGetVar(gen, initFB);
gen.Emit(OpCodes.Dup);
gen.Emit(OpCodes.Brfalse_S, noInitLabel);
gen.Emit(OpCodes.Castclass, typeof(IFn));
// box init args
for (int i = 0; i < thisParamTypes.Length; i++)
{
gen.EmitLoadArg(i + 1); // gen.Emit(OpCodes.Ldarg, i + 1);
if (thisParamTypes[i].IsValueType)
gen.Emit(OpCodes.Box,thisParamTypes[i]);
}
gen.EmitCall(Compiler.Methods_IFn_invoke[thisParamTypes.Length]); // gen.Emit(OpCodes.Call, Compiler.Methods_IFn_invoke[thisParamTypes.Length]);
// Expecting: [[super-ctor-args...] state]
// store the init return in a local
gen.Emit(OpCodes.Dup);
gen.Emit(OpCodes.Stloc,locInitVal);
// store the first element in a local
gen.EmitInt(0); // gen.Emit(OpCodes.Ldc_I4_0);
gen.EmitCall(Method_RT_nth); // gen.Emit(OpCodes.Call, Method_RT_nth);
gen.Emit(OpCodes.Stloc, locSuperArgs);
// Stack this + super-ctor-args + call base-class ctor.
gen.EmitLoadArg(0); // gen.Emit(OpCodes.Ldarg_0);
for (int i = 0; i < baseParamTypes.Length; i++)
{
gen.Emit(OpCodes.Ldloc, locSuperArgs);
gen.EmitInt(i); // gen.Emit(OpCodes.Ldc_I4, i);
gen.EmitCall(Method_RT_nth); // gen.Emit(OpCodes.Call, Method_RT_nth);
if (baseParamTypes[i].IsValueType)
gen.Emit(OpCodes.Unbox_Any, baseParamTypes[i]);
else
gen.Emit(OpCodes.Castclass, baseParamTypes[i]);
}
gen.Emit(OpCodes.Call, superCtor);
if (stateFB != null)
{
gen.EmitLoadArg(0); // gen.Emit(OpCodes.Ldarg_0);
gen.Emit(OpCodes.Ldloc, locInitVal);
gen.EmitInt(1); // gen.Emit(OpCodes.Ldc_I4_1);
gen.EmitCall(Method_RT_nth); // gen.Emit(OpCodes.Call, Method_RT_nth);
gen.Emit(OpCodes.Castclass, typeof(object));
gen.EmitFieldSet(stateFB); // gen.Emit(OpCodes.Stfld, stateFB);
}
gen.Emit(OpCodes.Br_S, endLabel);
// No init found
gen.MarkLabel(noInitLabel);
gen.Emit(OpCodes.Pop);
EmitUnsupported(gen, initName);
gen.MarkLabel(endLabel);
}
//.........这里部分代码省略.........
示例12: EmitBaseClassCallCheckForProperties
/// <summary>
/// Emits code to check if the class has overridden this specific
/// function. For example:
///
/// MyDerivedType.SomeVirtualFunction = ...
/// or
///
/// class MyDerivedType(MyBaseType):
/// def SomeVirtualFunction(self, ...):
///
/// </summary>
private LocalBuilder EmitBaseClassCallCheckForProperties(ILGen il, MethodInfo baseMethod, string name) {
Label instanceCall = il.DefineLabel();
LocalBuilder callTarget = il.DeclareLocal(typeof(object));
// first lookup under the property name
il.EmitLoadArg(0);
EmitSymbolId(il, name);
il.Emit(OpCodes.Ldloca, callTarget);
il.EmitCall(typeof(UserTypeOps), "TryGetNonInheritedValueHelper");
il.Emit(OpCodes.Brtrue, instanceCall);
// then look up under the method name (get_Foo/set_Foo)
LocalBuilder methodTarget = EmitNonInheritedMethodLookup(baseMethod.Name, il);
Label instanceCallMethod = il.DefineLabel();
il.Emit(OpCodes.Brtrue, instanceCallMethod);
// method isn't overridden using either form
EmitBaseMethodDispatch(baseMethod, il);
// we're calling the get_/set_ method
il.MarkLabel(instanceCallMethod);
EmitClrCallStub(il, baseMethod, methodTarget);
il.Emit(OpCodes.Ret);
il.MarkLabel(instanceCall);
// we're accessing a property
return callTarget;
}
示例13: GenerateStatics
protected override void GenerateStatics(GenContext context)
{
if (IsDefType)
{
TypeBuilder tb = TypeBuilder;
// getBasis()
MethodBuilder mbg = tb.DefineMethod("getBasis", MethodAttributes.Public | MethodAttributes.Static, typeof(IPersistentVector), Type.EmptyTypes);
LambdaExpression lambda = Expression.Lambda(GenerateValue(_hintedFields));
lambda.CompileToMethod(mbg, context.IsDebuggable);
if (_fields.count() > _hintedFields.count())
{
// create(IPersistentMap)
MethodBuilder mbc = tb.DefineMethod("create", MethodAttributes.Public | MethodAttributes.Static, tb, new Type[] { typeof(IPersistentMap) });
ILGen gen = new ILGen(mbc.GetILGenerator());
LocalBuilder kwLocal = gen.DeclareLocal(typeof(Keyword));
List<LocalBuilder> locals = new List<LocalBuilder>();
for (ISeq s = RT.seq(_hintedFields); s != null; s = s.next())
{
string bName = ((Symbol)s.first()).Name;
Type t = Compiler.TagType(Compiler.TagOf(s.first()));
// local_kw = Keyword.intern(bname)
// local_i = arg_0.valAt(kw,null)
gen.EmitLoadArg(0);
gen.EmitString(bName);
gen.EmitCall(Compiler.Method_Keyword_intern_string);
gen.Emit(OpCodes.Dup);
gen.Emit(OpCodes.Stloc,kwLocal.LocalIndex);
gen.EmitNull();
gen.EmitCall(Compiler.Method_IPersistentMap_valAt2);
LocalBuilder lb = gen.DeclareLocal(t);
locals.Add(lb);
if ( t.IsPrimitive )
gen.EmitUnbox(t);
gen.Emit(OpCodes.Stloc, lb.LocalIndex);
// arg_0 = arg_0.without(local_kw);
gen.EmitLoadArg(0);
gen.Emit(OpCodes.Ldloc,kwLocal.LocalIndex);
gen.EmitCall(Compiler.Method_IPersistentMap_without);
gen.EmitStoreArg(0);
}
foreach (LocalBuilder lb in locals)
gen.Emit(OpCodes.Ldloc, lb.LocalIndex);
gen.EmitNull();
gen.EmitLoadArg(0);
gen.EmitCall(Compiler.Method_RT_seqOrElse);
gen.EmitNew(CtorInfo);
gen.Emit(OpCodes.Ret);
}
}
}
示例14: EmitNonInheritedMethodLookup
/// <summary>
/// Emits the call to lookup a member defined in the user's type. Returns
/// the local which stores the resulting value and leaves a value on the
/// stack indicating the success of the lookup.
/// </summary>
private LocalBuilder EmitNonInheritedMethodLookup(string name, ILGen il) {
LocalBuilder callTarget = il.DeclareLocal(typeof(object));
// emit call to helper to do lookup
il.EmitLoadArg(0);
EmitClassObjectFromInstance(il);
il.EmitLoadArg(0);
il.Emit(OpCodes.Ldstr, name);
il.Emit(OpCodes.Ldloca, callTarget);
il.EmitCall(NonInheritedMethodHelper());
return callTarget;
}
示例15: EmitBaseClassCallCheckForProperties
/// <summary>
/// Emits code to check if the class has overridden this specific
/// function. For example:
///
/// MyDerivedType.SomeVirtualFunction = ...
/// or
///
/// class MyDerivedType(MyBaseType):
/// def SomeVirtualFunction(self, ...):
///
/// </summary>
internal LocalBuilder EmitBaseClassCallCheckForProperties(ILGen il, MethodInfo baseMethod, string name) {
Label instanceCall = il.DefineLabel();
LocalBuilder callTarget = il.DeclareLocal(typeof(object));
il.EmitLoadArg(0);
EmitClassObjectFromInstance(il);
il.EmitLoadArg(0);
il.Emit(OpCodes.Ldstr, name);
il.Emit(OpCodes.Ldloca, callTarget);
il.EmitCall(NonInheritedValueHelper());
il.Emit(OpCodes.Brtrue, instanceCall);
EmitBaseMethodDispatch(baseMethod, il);
il.MarkLabel(instanceCall);
return callTarget;
}