本文整理汇总了C#中clojure.lang.CljCompiler.Ast.CljILGen.EmitLoadArg方法的典型用法代码示例。如果您正苦于以下问题:C# CljILGen.EmitLoadArg方法的具体用法?C# CljILGen.EmitLoadArg怎么用?C# CljILGen.EmitLoadArg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类clojure.lang.CljCompiler.Ast.CljILGen
的用法示例。
在下文中一共展示了CljILGen.EmitLoadArg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddIProxyMethods
private static FieldBuilder AddIProxyMethods(TypeBuilder proxyTB)
{
FieldBuilder fb = proxyTB.DefineField(
_methodMapFieldName,
typeof(IPersistentMap),
FieldAttributes.Private);
MethodBuilder initMb = proxyTB.DefineMethod(
"__initClojureFnMappings",
MethodAttributes.Public|MethodAttributes.Virtual|MethodAttributes.HideBySig,
typeof(void),
new Type[] { typeof(IPersistentMap) });
CljILGen gen = new CljILGen(initMb.GetILGenerator());
gen.EmitLoadArg(0); // gen.Emit(OpCodes.Ldarg_0);
gen.EmitLoadArg(1); // gen.Emit(OpCodes.Ldarg_1);
gen.EmitFieldSet(fb); // gen.Emit(OpCodes.Stfld, fb);
gen.Emit(OpCodes.Ret);
MethodBuilder updateTB = proxyTB.DefineMethod(
"__updateClojureFnMappings",
MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig,
typeof(void),
new Type[] { typeof(IPersistentMap) });
gen = new CljILGen(updateTB.GetILGenerator());
gen.EmitLoadArg(0); // gen.Emit(OpCodes.Ldarg_0);
gen.Emit(OpCodes.Dup);
gen.EmitFieldGet(fb); // gen.Emit(OpCodes.Ldfld, fb);
gen.Emit(OpCodes.Castclass, typeof(IPersistentMap));
gen.EmitLoadArg(1); // gen.Emit(OpCodes.Ldarg_1);
gen.EmitCall(Method_IPersistentMap_Cons); //gen.Emit(OpCodes.Call, Method_IPersistentCollection_Cons);
gen.EmitFieldSet(fb); // gen.Emit(OpCodes.Stfld, fb);
gen.Emit(OpCodes.Ret);
MethodBuilder getMb = proxyTB.DefineMethod(
"__getClojureFnMappings",
MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig,
typeof(IPersistentMap),
Type.EmptyTypes);
gen = new CljILGen(getMb.GetILGenerator());
gen.EmitLoadArg(0); // gen.Emit(OpCodes.Ldarg_0);
gen.EmitFieldGet(fb); // gen.Emit(OpCodes.Ldfld, fb);
gen.Emit(OpCodes.Ret);
return fb;
}
示例2: EmitLocal
internal void EmitLocal(CljILGen ilg, LocalBinding lb)
{
Type primType = lb.PrimitiveType;
if (Closes.containsKey(lb))
{
if (_fnMode == FnMode.Full)
{
ilg.Emit(OpCodes.Ldarg_0); // this
FieldBuilder fb = _closedOverFieldsMap[lb];
ilg.MaybeEmitVolatileOp(IsVolatile(lb));
ilg.Emit(OpCodes.Ldfld, fb);
if (primType != null)
HostExpr.EmitBoxReturn(this, ilg, primType);
// TODO: ONCEONLY?
}
else // FnMode.Light
{
ilg.Emit(OpCodes.Ldarg_0); // this
ilg.Emit(OpCodes.Castclass, typeof(IFnClosure));
ilg.EmitCall(Compiler.Method_IFnClosure_GetClosure);
ilg.EmitFieldGet(Compiler.Field_Closure_Locals);
ilg.EmitInt(lb.Index);
ilg.EmitLoadElement(typeof(Object));
}
}
else
{
if (lb.IsArg)
{
//int argOffset = IsStatic ? 1 : 0;
//ilg.Emit(OpCodes.Ldarg, lb.Index - argOffset);
ilg.EmitLoadArg(lb.Index);
}
else if (lb.IsThis)
{
ilg.EmitLoadArg(0);
}
else
{
ilg.Emit(OpCodes.Ldloc, lb.LocalVar);
}
if (primType != null)
HostExpr.EmitBoxReturn(this, ilg, primType);
}
}
示例3: EmitMain
static void EmitMain(GenContext context, TypeBuilder proxyTB, string mainName, FieldBuilder mainFB)
{
MethodBuilder cb = proxyTB.DefineMethod("Main",MethodAttributes.Public| MethodAttributes.Static,CallingConventions.Standard,typeof(void),new Type[] { typeof(String[]) });
CljILGen gen = new CljILGen(cb.GetILGenerator()); ;
Label noMainLabel = gen.DefineLabel();
Label endLabel = gen.DefineLabel();
EmitGetVar(gen, mainFB);
gen.Emit(OpCodes.Dup);
gen.Emit(OpCodes.Brfalse_S, noMainLabel);
gen.Emit(OpCodes.Castclass, typeof(IFn));
gen.EmitLoadArg(0); // gen.Emit(OpCodes.Ldarg_0);
gen.EmitCall(Method_RT_seq); // gen.Emit(OpCodes.Call, Method_RT_seq);
gen.EmitCall(Method_IFn_applyTo_Object_ISeq); // gen.Emit(OpCodes.Call, Method_IFn_applyTo_Object_ISeq);
gen.Emit(OpCodes.Pop);
gen.Emit(OpCodes.Br_S, endLabel);
// no main found
gen.MarkLabel(noMainLabel);
EmitUnsupported(gen, mainName);
gen.MarkLabel(endLabel);
gen.Emit(OpCodes.Ret);
//context.AssyBldr.SetEntryPoint(cb);
context.AssemblyBuilder.SetEntryPoint(cb);
}
示例4: EmitSwapThunk
void EmitSwapThunk(TypeBuilder tb)
{
MethodBuilder mb = tb.DefineMethod("swapThunk", MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.Virtual, typeof(void), new Type[] { typeof(int), typeof(ILookupThunk) });
CljILGen ilg = new CljILGen(mb.GetILGenerator());
Label endLabel = ilg.DefineLabel();
Label[] labels = new Label[KeywordCallsites.count()];
for (int i = 0; i < KeywordCallsites.count(); i++)
labels[i] = ilg.DefineLabel();
ilg.EmitLoadArg(1);
ilg.Emit(OpCodes.Switch, labels);
ilg.Emit(OpCodes.Br, endLabel);
for (int i = 0; i < KeywordCallsites.count(); i++)
{
ilg.MarkLabel(labels[i]);
ilg.EmitLoadArg(2);
ilg.EmitFieldSet(_thunkFields[i]);
ilg.Emit(OpCodes.Br, endLabel);
}
ilg.MarkLabel(endLabel);
ilg.Emit(OpCodes.Ret);
}
示例5: EmitUnboxedLocal
internal void EmitUnboxedLocal(CljILGen ilg, LocalBinding lb)
{
if (Closes.containsKey(lb))
{
ilg.Emit(OpCodes.Ldarg_0); // this
FieldBuilder fb = _closedOverFieldsMap[lb];
ilg.MaybeEmitVolatileOp(IsVolatile(lb));
ilg.Emit(OpCodes.Ldfld, fb);
}
else if (lb.IsArg)
{
//int argOffset = IsStatic ? 0 : 1;
//ilg.Emit(OpCodes.Ldarg, lb.Index + argOffset);
ilg.EmitLoadArg(lb.Index);
}
else if (lb.IsThis)
{
ilg.EmitLoadArg(0);
}
else
ilg.Emit(OpCodes.Ldloc, lb.LocalVar);
}
示例6: EmitConstructor
private ConstructorBuilder EmitConstructor(TypeBuilder fnTB, Type baseType)
{
ConstructorBuilder cb = fnTB.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis, CtorTypes());
CljILGen gen = new CljILGen(cb.GetILGenerator());
GenContext.EmitDebugInfo(gen, SpanMap);
//Call base constructor
ConstructorInfo baseCtorInfo = baseType.GetConstructor(BindingFlags.Instance|BindingFlags.NonPublic|BindingFlags.Public,null,Type.EmptyTypes,null);
if (baseCtorInfo == null)
throw new InvalidOperationException("Unable to find default constructor for " + baseType.FullName);
gen.EmitLoadArg(0);
gen.Emit(OpCodes.Call, baseCtorInfo);
// Store Meta
if (SupportsMeta)
{
gen.EmitLoadArg(0);
gen.EmitLoadArg(1);
gen.Emit(OpCodes.Castclass, typeof(IPersistentMap));
gen.EmitFieldSet(_metaField);
}
// store closed-overs in their fields
int a = 0;
int offset = !SupportsMeta ? 1 : 2;
for (ISeq s = RT.keys(Closes); s != null; s = s.next(), a++)
{
//LocalBinding lb = (LocalBinding)s.first();
FieldBuilder fb = _closedOverFields[a];
bool isVolatile = IsVolatile(_closedOverFieldsToBindingsMap[fb]);
gen.EmitLoadArg(0); // gen.Emit(OpCodes.Ldarg_0);
gen.EmitLoadArg(a + offset); // gen.Emit(OpCodes.Ldarg, a + 1);
gen.MaybeEmitVolatileOp(isVolatile);
gen.Emit(OpCodes.Stfld, fb);
}
gen.Emit(OpCodes.Ret);
return cb;
}
示例7: EmitMetaFunctions
private void EmitMetaFunctions(TypeBuilder fnTB)
{
// IPersistentMap meta()
MethodBuilder metaMB = fnTB.DefineMethod("meta", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.ReuseSlot, typeof(IPersistentMap), Type.EmptyTypes);
CljILGen gen = new CljILGen(metaMB.GetILGenerator());
if (SupportsMeta)
{
gen.EmitLoadArg(0);
gen.EmitFieldGet(_metaField);
}
else
gen.EmitNull();
gen.Emit(OpCodes.Ret);
// IObj withMeta(IPersistentMap)
MethodBuilder withMB = fnTB.DefineMethod("withMeta", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.ReuseSlot, typeof(IObj), new Type[] { typeof(IPersistentMap) });
gen = new CljILGen(withMB.GetILGenerator());
if (SupportsMeta)
{
gen.EmitLoadArg(1); // meta arg
foreach (FieldBuilder fb in _closedOverFields)
{
gen.EmitLoadArg(0);
gen.MaybeEmitVolatileOp(fb);
gen.EmitFieldGet(fb);
}
gen.EmitNew(_ctorInfo);
}
else
gen.EmitLoadArg(0); //this
gen.Emit(OpCodes.Ret);
}
示例8: EmitFieldOnlyConstructorWithoutHash
private void EmitFieldOnlyConstructorWithoutHash(TypeBuilder fnTB)
{
Type[] ctorTypes = CtorTypes();
Type[] altCtorTypes = new Type[ctorTypes.Length - 2];
for (int i = 0; i < altCtorTypes.Length; i++)
altCtorTypes[i] = ctorTypes[i];
ConstructorBuilder cb = fnTB.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis, altCtorTypes);
CljILGen gen = new CljILGen(cb.GetILGenerator());
//Call full constructor
gen.EmitLoadArg(0); // gen.Emit(OpCodes.Ldarg_0);
for (int i = 0; i < altCtorTypes.Length; i++)
gen.EmitLoadArg(i + 1);
gen.Emit(OpCodes.Ldc_I4_0); // __hash
gen.Emit(OpCodes.Ldc_I4_0); // __hasheq
gen.Emit(OpCodes.Call, CtorInfo);
gen.Emit(OpCodes.Ret);
}
示例9: EmitProto
void EmitProto(RHC rhc, ObjExpr objx, CljILGen ilg)
{
Label onLabel = ilg.DefineLabel();
Label callLabel = ilg.DefineLabel();
Label endLabel = ilg.DefineLabel();
Var v = ((VarExpr)_fexpr).Var;
Expr e = (Expr)_args.nth(0);
e.Emit(RHC.Expression, objx, ilg); // target
ilg.Emit(OpCodes.Dup); // target, target
LocalBuilder targetTemp = ilg.DeclareLocal(typeof(Object));
GenContext.SetLocalName(targetTemp, "target");
ilg.Emit(OpCodes.Stloc,targetTemp); // target
ilg.Emit(OpCodes.Call,Compiler.Method_Util_classOf); // class
ilg.EmitLoadArg(0); // class, this
ilg.EmitFieldGet(objx.CachedTypeField(_siteIndex)); // class, cached-class
ilg.Emit(OpCodes.Beq, callLabel); //
if (_protocolOn != null)
{
ilg.Emit(OpCodes.Ldloc,targetTemp); // target
ilg.Emit(OpCodes.Isinst, _protocolOn); // null or target
ilg.Emit(OpCodes.Ldnull); // (null or target), null
ilg.Emit(OpCodes.Cgt_Un); // (0 or 1)
ilg.Emit(OpCodes.Brtrue, onLabel);
}
ilg.Emit(OpCodes.Ldloc,targetTemp); // target
ilg.Emit(OpCodes.Call,Compiler.Method_Util_classOf); // class
LocalBuilder typeTemp = ilg.DeclareLocal(typeof(Type));
GenContext.SetLocalName(typeTemp, "type");
ilg.Emit(OpCodes.Stloc,typeTemp); // (typeType <= class)
ilg.EmitLoadArg(0); // this
ilg.Emit(OpCodes.Ldloc,typeTemp); // this, class
ilg.EmitFieldSet(objx.CachedTypeField(_siteIndex)); //
ilg.MarkLabel(callLabel);
objx.EmitVar(ilg,v); // var
ilg.Emit(OpCodes.Call,Compiler.Method_Var_getRawRoot); // proto-fn
ilg.Emit(OpCodes.Castclass, typeof(AFunction));
ilg.Emit(OpCodes.Ldloc,targetTemp); // proto-fn, target
EmitArgsAndCall(1,rhc,objx,ilg);
ilg.Emit(OpCodes.Br,endLabel);
ilg.MarkLabel(onLabel);
ilg.Emit(OpCodes.Ldloc,targetTemp); // target
if ( _protocolOn != null )
{
ilg.Emit(OpCodes.Castclass, _protocolOn);
MethodExpr.EmitTypedArgs(objx, ilg, _onMethod.GetParameters(), RT.subvec(_args, 1, _args.count()));
//if (rhc == RHC.Return)
//{
// ObjMethod2 method = (ObjMethod)Compiler.MethodVar.deref();
// method.EmitClearLocals(context);
//}
ilg.Emit(OpCodes.Callvirt, _onMethod);
HostExpr.EmitBoxReturn(objx, ilg, _onMethod.ReturnType);
}
ilg.MarkLabel(endLabel);
}
示例10: DefineBaseClassClosedOverConstructors
private void DefineBaseClassClosedOverConstructors(Type super, TypeBuilder tb)
{
// ctor that takes closed-overs and does nothing
if (CtorTypes().Length > 0)
{
ConstructorBuilder cb = tb.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis,CtorTypes());
CljILGen ilg = new CljILGen(cb.GetILGenerator());
ilg.EmitLoadArg(0);
ilg.Emit(OpCodes.Call, super.GetConstructor(Type.EmptyTypes));
// store closed-overs in their fields
int a = 0;
for (ISeq s = RT.keys(Closes); s != null; s = s.next(), a++)
{
FieldBuilder fb = ClosedOverFields[a];
bool isVolatile = IsVolatile(ClosedOverFieldsToBindingsMap[fb]);
ilg.EmitLoadArg(0); // gen.Emit(OpCodes.Ldarg_0);
ilg.EmitLoadArg(a + 1); // gen.Emit(OpCodes.Ldarg, a + 1);
ilg.MaybeEmitVolatileOp(isVolatile);
ilg.Emit(OpCodes.Stfld, fb);
}
ilg.Emit(OpCodes.Ret);
if (AltCtorDrops > 0)
{
Type[] ctorTypes = CtorTypes();
int newLen = ctorTypes.Length - AltCtorDrops;
if (newLen > 0)
{
Type[] altCtorTypes = new Type[newLen];
for (int i = 0; i < altCtorTypes.Length; i++)
altCtorTypes[i] = ctorTypes[i];
ConstructorBuilder cb2 = tb.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis, altCtorTypes);
CljILGen ilg2 = new CljILGen(cb2.GetILGenerator());
ilg2.EmitLoadArg(0);
for (int i = 0; i < newLen; i++)
ilg2.EmitLoadArg(i + 1);
for (int i = 0; i < AltCtorDrops; i++)
ilg2.EmitNull();
ilg2.Emit(OpCodes.Call, cb);
ilg2.Emit(OpCodes.Ret);
}
}
}
}
示例11: EmitStatics
protected override void EmitStatics(TypeBuilder tb)
{
if (IsDefType)
{
// getBasis()
{
MethodBuilder mbg = tb.DefineMethod("getBasis", MethodAttributes.Public | MethodAttributes.Static, typeof(IPersistentVector), Type.EmptyTypes);
CljILGen ilg = new CljILGen(mbg.GetILGenerator());
EmitValue(HintedFields, ilg);
ilg.Emit(OpCodes.Ret);
}
if (Fields.count() > HintedFields.count())
{
// create(IPersistentMap)
MethodBuilder mbc = tb.DefineMethod("create", MethodAttributes.Public | MethodAttributes.Static, tb, new Type[] { typeof(IPersistentMap) });
CljILGen gen = new CljILGen(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);
}
}
}
示例12: CompileStub
/***
* Current host interop uses reflection, which requires pre-existing classes
* Work around this by:
* Generate a stub class that has the same interfaces and fields as the class we are generating.
* Use it as a type hint for this, and bind the simple name of the class to this stub (in resolve etc)
* Unmunge the name (using a magic prefix) on any code gen for classes
*/
// TODO: Preparse method heads to pick up signatures, implement those methods as abstract or as NotImpelmented so that Reflection can pick up calls during compilation and avoide a callsite.
static Type CompileStub(GenContext context, Type super, NewInstanceExpr ret, Type[] interfaces, Object frm)
{
//GenContext context = Compiler.CompilerContextVar.get() as GenContext ?? GenContext.CreateWithExternalAssembly("stub" + RT.nextID().ToString(), ".dll", false);
//GenContext context = Compiler.IsCompiling ? Compiler.CompilerContextVar.get() as GenContext : GenContext.CreateWithExternalAssembly("stub" + RT.nextID().ToString(), ".dll", false);
//context = GenContext.CreateWithExternalAssembly("stub" + RT.nextID().ToString(), ".dll", false);
TypeBuilder tb = context.ModuleBuilder.DefineType(Compiler.CompileStubPrefix + "." + ret.InternalName + RT.nextID(), TypeAttributes.Public | TypeAttributes.Abstract, super, interfaces);
tb.DefineDefaultConstructor(MethodAttributes.Public);
// instance fields for closed-overs
for (ISeq s = RT.keys(ret.Closes); s != null; s = s.next())
{
LocalBinding lb = (LocalBinding)s.first();
FieldAttributes access = FieldAttributes.Public;
// TODO: FIgure out Volatile
if (!ret.IsVolatile(lb))
access |= FieldAttributes.InitOnly;
if (lb.PrimitiveType != null)
tb.DefineField(lb.Name, lb.PrimitiveType, access);
else
tb.DefineField(lb.Name, typeof(Object), access);
}
// ctor that takes closed-overs and does nothing
if (ret.CtorTypes().Length > 0)
{
ConstructorBuilder cb = tb.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis, ret.CtorTypes());
CljILGen ilg = new CljILGen(cb.GetILGenerator());
ilg.EmitLoadArg(0);
ilg.Emit(OpCodes.Call, super.GetConstructor(Type.EmptyTypes));
ilg.Emit(OpCodes.Ret);
if (ret._altCtorDrops > 0)
{
Type[] ctorTypes = ret.CtorTypes();
int newLen = ctorTypes.Length - ret._altCtorDrops;
if (newLen > 0)
{
Type[] altCtorTypes = new Type[newLen];
for (int i = 0; i < altCtorTypes.Length; i++)
altCtorTypes[i] = ctorTypes[i];
ConstructorBuilder cb2 = tb.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis, altCtorTypes);
CljILGen ilg2 = new CljILGen(cb2.GetILGenerator());
ilg2.EmitLoadArg(0);
for (int i = 0; i < newLen; i++)
ilg2.EmitLoadArg(i + 1);
for (int i = 0; i < ret._altCtorDrops; i++)
ilg2.EmitNull();
ilg2.Emit(OpCodes.Call, cb);
ilg2.Emit(OpCodes.Ret);
}
}
}
Type t = tb.CreateType();
//Compiler.RegisterDuplicateType(t);
return t;
}
示例13: DoEmitPrimOrStatic
private void DoEmitPrimOrStatic(ObjExpr fn, TypeBuilder tb, bool isStatic)
{
MethodAttributes attribs = isStatic
? MethodAttributes.Static | MethodAttributes.Public
: MethodAttributes.ReuseSlot | MethodAttributes.Public | MethodAttributes.Virtual;
string methodName = isStatic ? "invokeStatic" : "invokePrim";
MethodBuilder baseMB = tb.DefineMethod(methodName, attribs, GetReturnType(), _argTypes);
if ( ! isStatic )
SetCustomAttributes(baseMB);
CljILGen baseIlg = new CljILGen(baseMB.GetILGenerator());
try
{
Label loopLabel = baseIlg.DefineLabel();
Var.pushThreadBindings(RT.map(Compiler.LoopLabelVar,loopLabel,Compiler.MethodVar,this));
GenContext.EmitDebugInfo(baseIlg, SpanMap);
baseIlg.MarkLabel(loopLabel);
EmitBody(Objx, baseIlg, _retType, _body);
if ( _body.HasNormalExit() )
baseIlg.Emit(OpCodes.Ret);
}
finally
{
Var.popThreadBindings();
}
// Generate the regular invoke, calling the static or prim method
MethodBuilder regularMB = tb.DefineMethod(GetMethodName(), MethodAttributes.ReuseSlot | MethodAttributes.Public | MethodAttributes.Virtual, typeof(Object), GetArgTypes());
SetCustomAttributes(regularMB);
CljILGen regIlg = new CljILGen(regularMB.GetILGenerator());
if ( ! isStatic )
regIlg.Emit(OpCodes.Ldarg_0);
for(int i = 0; i < _argTypes.Length; i++)
{
regIlg.EmitLoadArg(i+1);
HostExpr.EmitUnboxArg(fn, regIlg, _argTypes[i]);
}
regIlg.Emit(OpCodes.Call,baseMB);
if ( GetReturnType().IsValueType)
regIlg.Emit(OpCodes.Box,GetReturnType());
regIlg.Emit(OpCodes.Ret);
}
示例14: EmitUnboxedLocal
internal void EmitUnboxedLocal(CljILGen ilg, LocalBinding lb)
{
if (Closes.containsKey(lb))
{
if (_fnMode == FnMode.Full)
{
ilg.Emit(OpCodes.Ldarg_0); // this
FieldBuilder fb = _closedOverFieldsMap[lb];
ilg.MaybeEmitVolatileOp(IsVolatile(lb));
ilg.Emit(OpCodes.Ldfld, fb);
}
else
{
ilg.Emit(OpCodes.Ldarg_0); // this
ilg.Emit(OpCodes.Castclass, typeof(IFnClosure));
ilg.EmitCall(Compiler.Method_IFnClosure_GetClosure);
ilg.EmitFieldGet(Compiler.Field_Closure_Locals);
ilg.EmitInt(lb.Index);
ilg.EmitLoadElement(typeof(Object));
if (lb.PrimitiveType != null)
ilg.Emit(OpCodes.Unbox, lb.PrimitiveType);
}
}
else if (lb.IsArg)
{
//int argOffset = IsStatic ? 0 : 1;
//ilg.Emit(OpCodes.Ldarg, lb.Index + argOffset);
ilg.EmitLoadArg(lb.Index);
}
else if (lb.IsThis)
{
ilg.EmitLoadArg(0);
}
else
ilg.Emit(OpCodes.Ldloc, lb.LocalVar);
}
示例15: DefineCtor
private static void DefineCtor(TypeBuilder proxyTB, ConstructorInfo ctor)
{
ParameterInfo[] pinfos = ctor.GetParameters();
Type[] paramTypes = new Type[pinfos.Length];
for (int i = 0; i < pinfos.Length; i++)
paramTypes[i] = pinfos[i].ParameterType;
ConstructorBuilder cb = proxyTB.DefineConstructor(ctor.Attributes, CallingConventions.HasThis, paramTypes);
// Call base class ctor on all the args
CljILGen gen = new CljILGen(cb.GetILGenerator());
gen.EmitLoadArg(0); // gen.Emit(OpCodes.Ldarg_0);
for (int i = 0; i < pinfos.Length; i++)
gen.EmitLoadArg(i + 1); // gen.Emit(OpCodes.Ldarg, i + 1);
gen.Emit(OpCodes.Call, ctor);
gen.Emit(OpCodes.Ret);
}