本文整理汇总了C#中clojure.lang.CljCompiler.Ast.CljILGen.EmitCall方法的典型用法代码示例。如果您正苦于以下问题:C# CljILGen.EmitCall方法的具体用法?C# CljILGen.EmitCall怎么用?C# CljILGen.EmitCall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类clojure.lang.CljCompiler.Ast.CljILGen
的用法示例。
在下文中一共展示了CljILGen.EmitCall方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Emit
public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
{
_expr.Emit(RHC.Expression, objx, ilg);
ilg.Emit(OpCodes.Castclass, typeof(IObj));
_meta.Emit(RHC.Expression, objx, ilg);
ilg.Emit(OpCodes.Castclass, typeof(IPersistentMap));
ilg.EmitCall(Compiler.Method_IObj_withMeta);
if (rhc == RHC.Statement)
ilg.Emit(OpCodes.Pop);
}
示例2: EmitGetVar
static void EmitGetVar(CljILGen gen, FieldBuilder fb)
{
Label falseLabel = gen.DefineLabel();
Label endLabel = gen.DefineLabel();
gen.EmitFieldGet(fb); // gen.Emit(OpCodes.Ldsfld,fb);
gen.Emit(OpCodes.Dup);
gen.EmitCall(Method_Var_isBound); // gen.Emit(OpCodes.Call, Method_Var_IsBound);
gen.Emit(OpCodes.Brfalse_S,falseLabel);
gen.Emit(OpCodes.Call,Method_Var_get);
gen.Emit(OpCodes.Br_S,endLabel);
gen.MarkLabel(falseLabel);
gen.Emit(OpCodes.Pop);
gen.EmitNull(); // gen.Emit(OpCodes.Ldnull);
gen.MarkLabel(endLabel);
}
示例3: EmitForwardingMethod
private static void EmitForwardingMethod(TypeBuilder proxyTB,
bool isStatic,
FieldBuilder regularFB,
FieldBuilder overloadFB,
MethodSignature sig,
ElseGenDelegate elseGen)
{
MethodAttributes attributes;
CallingConventions conventions;
if (isStatic)
{
attributes = MethodAttributes.Public | MethodAttributes.Static;
conventions = CallingConventions.Standard;
}
else
{
attributes = MethodAttributes.Public | MethodAttributes.Virtual;
conventions = CallingConventions.HasThis;
}
MethodBuilder mb = proxyTB.DefineMethod(sig.Name, attributes, conventions, sig.ReturnType, sig.ParamTypes);
CljILGen gen = new CljILGen(mb.GetILGenerator());
Label foundLabel = gen.DefineLabel();
Label elseLabel = gen.DefineLabel();
Label endLabel = gen.DefineLabel();
if (sig.ParamTypes.Length > 18)
elseGen(gen);
else
{
if (overloadFB != null)
{
EmitGetVar(gen, overloadFB);
gen.Emit(OpCodes.Dup);
gen.Emit(OpCodes.Brtrue_S, foundLabel);
gen.Emit(OpCodes.Pop);
}
EmitGetVar(gen, regularFB);
gen.Emit(OpCodes.Dup);
gen.Emit(OpCodes.Brfalse_S, elseLabel);
if (overloadFB != null)
gen.MarkLabel(foundLabel);
gen.Emit(OpCodes.Castclass, typeof(IFn));
if (!isStatic)
gen.EmitLoadArg(0); // gen.Emit(OpCodes.Ldarg_0);
for (int i = 0; i < sig.ParamTypes.Length; i++)
{
gen.EmitLoadArg(isStatic ? i : i + 1); // gen.Emit(OpCodes.Ldarg, i + 1);
if (sig.ParamTypes[i].IsValueType)
gen.Emit(OpCodes.Box, sig.ParamTypes[i]);
}
gen.EmitCall(Compiler.Methods_IFn_invoke[sig.ParamTypes.Length + (isStatic ? 0 : 1)]);
//gen.Emit(OpCodes.Call, Compiler.Methods_IFn_invoke[sig.ParamTypes.Length + (isStatic ? 0 : 1)]);
if (sig.ReturnType == typeof(void))
gen.Emit(OpCodes.Pop);
else if (sig.ReturnType.IsValueType)
gen.Emit(OpCodes.Unbox_Any,sig.ReturnType);
gen.Emit(OpCodes.Br_S, endLabel);
gen.MarkLabel(elseLabel);
gen.Emit(OpCodes.Pop);
elseGen(gen);
gen.MarkLabel(endLabel);
gen.Emit(OpCodes.Ret);
}
}
示例4: DefineStaticCtor
/// <summary>
/// Set up Var fields and (maybe) load assembly for the namespace.
/// </summary>
/// <param name="proxyTB"></param>
/// <param name="varMap"></param>
/// <param name="loadImplNameSpace"></param>
/// <param name="implNamespace"></param>
private static void DefineStaticCtor(TypeBuilder proxyTB, string prefix, Dictionary<string, FieldBuilder> varMap, bool loadImplNameSpace, string implNamespace, string implCname)
{
ConstructorBuilder cb = proxyTB.DefineConstructor(MethodAttributes.Static, CallingConventions.Standard,Type.EmptyTypes);
CljILGen gen = new CljILGen(cb.GetILGenerator());
foreach (KeyValuePair<string, FieldBuilder> pair in varMap)
{
gen.EmitString(implNamespace); // gen.Emit(OpCodes.Ldstr, implNamespace);
gen.EmitString(prefix + pair.Key); // gen.Emit(OpCodes.Ldstr, prefix + pair.Key);
gen.EmitCall(Method_Var_internPrivate); // gen.Emit(OpCodes.Call, Method_Var_internPrivate);
gen.Emit(OpCodes.Stsfld, pair.Value);
}
if (loadImplNameSpace)
{
gen.EmitString("clojure.core"); // gen.Emit(OpCodes.Ldstr, "clojure.core");
gen.EmitString("load"); // gen.Emit(OpCodes.Ldstr, "load");
gen.EmitCall(Method_RT_var2); // gen.Emit(OpCodes.Call, Method_RT_var2);
gen.EmitString("/" + implCname); // gen.Emit(OpCodes.Ldstr, "/" + implCname);
gen.EmitCall(Compiler.Methods_IFn_invoke[1]); // gen.Emit(OpCodes.Call, Compiler.Methods_IFn_invoke[1]);
gen.Emit(OpCodes.Pop);
}
gen.Emit(OpCodes.Ret);
}
示例5: DefineCtors
static void DefineCtors(TypeBuilder proxyTB,
Type superClass,
string initName,
string postInitName,
ISeq ctors,
ISeq ctorTypes,
FieldBuilder initFB,
FieldBuilder postInitFB,
FieldBuilder stateFB,
string factoryName)
{
ISeq s1 = ctors;
for (ISeq s = ctorTypes; s != null; s = s.next())
{
// TODO: Get rid of this mess by making sure the metadata on the keys of the constructors map gets copied to the constructor-types map. Sigh.
IPersistentMap ctorAttributes = GenInterface.ExtractAttributes(RT.meta(((IMapEntry)s1.first()).key()));
s1 = s1.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);
GenInterface.SetCustomAttributes(cb, ctorAttributes);
CljILGen gen = new CljILGen(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);
//.........这里部分代码省略.........
示例6: Emit
public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
{
bool allKeysConstant = true;
bool allConstantKeysUnique = true;
IPersistentSet constantKeys = PersistentHashSet.EMPTY;
for (int i = 0; i < _keyvals.count(); i += 2)
{
Expr k = (Expr)_keyvals.nth(i);
if (k is LiteralExpr)
{
object kval = k.Eval();
if (constantKeys.contains(kval))
allConstantKeysUnique = false;
else
constantKeys = (IPersistentSet)constantKeys.cons(kval);
}
else
{
allKeysConstant = false;
}
}
MethodExpr.EmitArgsAsArray(_keyvals, objx, ilg);
if ((allKeysConstant && allConstantKeysUnique) || (_keyvals.count() <= 2))
ilg.EmitCall(Compiler.Method_RT_mapUniqueKeys);
else
ilg.EmitCall(Compiler.Method_RT_map);
if (rhc == RHC.Statement)
ilg.Emit(OpCodes.Pop);
}
示例7: EmitValue
protected void EmitValue(object value, CljILGen ilg)
{
bool partial = true;
if (value == null)
ilg.Emit(OpCodes.Ldnull);
else if (value is String)
ilg.Emit(OpCodes.Ldstr, (String)value);
else if (value is Boolean)
{
ilg.EmitBoolean((Boolean)value);
ilg.Emit(OpCodes.Box,typeof(bool));
}
else if (value is Int32)
{
ilg.EmitInt((int)value);
ilg.Emit(OpCodes.Box, typeof(int));
}
else if (value is Int64)
{
ilg.EmitLong((long)value);
ilg.Emit(OpCodes.Box, typeof(long));
}
else if (value is Double)
{
ilg.EmitDouble((double)value);
ilg.Emit(OpCodes.Box, typeof(double));
}
else if (value is Char)
{
ilg.EmitChar((char)value);
ilg.Emit(OpCodes.Box,typeof(char));
}
else if (value is Type)
{
Type t = (Type)value;
if (t.IsValueType)
ilg.EmitType(t);
else
{
//ilg.EmitString(Compiler.DestubClassName(((Type)value).FullName));
ilg.EmitString(((Type)value).FullName);
ilg.EmitCall(Compiler.Method_RT_classForName);
}
}
else if (value is Symbol)
{
Symbol sym = (Symbol)value;
if (sym.Namespace == null)
ilg.EmitNull();
else
ilg.EmitString(sym.Namespace);
ilg.EmitString(sym.Name);
ilg.EmitCall(Compiler.Method_Symbol_intern2);
}
else if (value is Keyword)
{
Keyword keyword = (Keyword)value;
if (keyword.Namespace == null)
ilg.EmitNull();
else
ilg.EmitString(keyword.Namespace);
ilg.EmitString(keyword.Name);
ilg.EmitCall(Compiler.Method_RT_keyword);
}
else if (value is Var)
{
Var var = (Var)value;
ilg.EmitString(var.Namespace.Name.ToString());
ilg.EmitString(var.Symbol.Name.ToString());
ilg.EmitCall(Compiler.Method_RT_var2);
}
else if (value is IType)
{
IPersistentVector fields = (IPersistentVector)Reflector.InvokeStaticMethod(value.GetType(), "getBasis", Type.EmptyTypes);
for (ISeq s = RT.seq(fields); s != null; s = s.next())
{
Symbol field = (Symbol)s.first();
Type k = Compiler.TagType(Compiler.TagOf(field));
object val = Reflector.GetInstanceFieldOrProperty(value, field.Name);
EmitValue(val, ilg);
if (k.IsPrimitive)
{
ilg.Emit(OpCodes.Castclass, k);
}
}
ConstructorInfo cinfo = value.GetType().GetConstructors()[0];
ilg.EmitNew(cinfo);
}
else if (value is IRecord)
{
//MethodInfo[] minfos = value.GetType().GetMethods(BindingFlags.Static | BindingFlags.Public);
EmitValue(PersistentArrayMap.create((IDictionary)value), ilg);
MethodInfo createMI = value.GetType().GetMethod("create", BindingFlags.Static | BindingFlags.Public, null, CallingConventions.Standard, new Type[] { typeof(IPersistentMap) }, null);
ilg.EmitCall(createMI);
}
//.........这里部分代码省略.........
示例8: GenerateProxyMethod
private static void GenerateProxyMethod(
TypeBuilder proxyTB,
FieldBuilder mapField,
MethodInfo m,
HashSet<MethodBuilder> specialMethods)
{
MethodAttributes attribs = m.Attributes;
bool callBaseMethod;
if ( (attribs & MethodAttributes.Abstract) == MethodAttributes.Abstract )
{
attribs &= ~MethodAttributes.Abstract;
callBaseMethod = false;
}
else
{
callBaseMethod = true;
}
attribs &= ~MethodAttributes.NewSlot;
attribs |= MethodAttributes.Virtual | MethodAttributes.HideBySig | MethodAttributes.Public;
//Console.Write("Generating proxy method {0}(", m.Name);
//foreach (ParameterInfo p in m.GetParameters())
// Console.Write("{0}, ", p.ParameterType.FullName);
//Console.Write(") ");
//Console.WriteLine(attribs.ToString());
MethodBuilder proxym = proxyTB.DefineMethod(
m.Name,
attribs,
m.CallingConvention,
m.ReturnType,
m.GetParameters().Select<ParameterInfo, Type>(p => p.ParameterType).ToArray<Type>());
if (m.IsSpecialName)
specialMethods.Add(proxym);
CljILGen gen = new CljILGen(proxym.GetILGenerator());
Label elseLabel = gen.DefineLabel();
Label endLabel = gen.DefineLabel();
//// Print a little message, for debugging purposes
//gen.Emit(OpCodes.Ldstr, String.Format("Calling {0} / {1}", proxyTB.FullName, m.ToString()));
//gen.Emit(OpCodes.Call, typeof(Console).GetMethod("WriteLine",
// new Type[] { typeof(string) }));
//gen.Emit(OpCodes.Call, typeof(Console).GetMethod("get_Out"));
//gen.Emit(OpCodes.Call, typeof(System.IO.TextWriter).GetMethod("Flush"));
// Lookup method name in map
gen.EmitLoadArg(0); // gen.Emit(OpCodes.Ldarg_0);
gen.EmitFieldGet(mapField); // gen.Emit(OpCodes.Ldfld, mapField);
gen.EmitString(m.Name); // gen.Emit(OpCodes.Ldstr, m.Name);
gen.EmitCall(Method_RT_get); // gen.Emit(OpCodes.Call, Method_RT_get);
gen.Emit(OpCodes.Dup);
gen.EmitNull(); // gen.Emit(OpCodes.Ldnull);
gen.Emit(OpCodes.Beq_S, elseLabel);
// map entry found
ParameterInfo[] pinfos = m.GetParameters();
gen.Emit(OpCodes.Castclass, typeof(IFn));
gen.EmitLoadArg(0); // gen.Emit(OpCodes.Ldarg_0); // push implicit 'this' arg.
for (int i = 0; i < pinfos.Length; i++)
{
gen.EmitLoadArg(i + 1); // gen.Emit(OpCodes.Ldarg, i + 1);
if (m.GetParameters()[i].ParameterType.IsValueType)
gen.Emit(OpCodes.Box,pinfos[i].ParameterType);
}
int parmCount = pinfos.Length;
gen.EmitCall(GetIFnInvokeMethodInfo(parmCount+1)); // gen.Emit(OpCodes.Call, GetIFnInvokeMethodInfo(parmCount + 1));
if (m.ReturnType == typeof(void))
gen.Emit(OpCodes.Pop);
else
gen.Emit(OpCodes.Unbox_Any, m.ReturnType);
gen.Emit(OpCodes.Br_S,endLabel);
// map entry not found
gen.MarkLabel(elseLabel);
gen.Emit(OpCodes.Pop); // get rid of null leftover from the 'get'
if ( callBaseMethod )
{
gen.EmitLoadArg(0); // gen.Emit(OpCodes.Ldarg_0);
for (int i = 0; i < parmCount; i++)
gen.EmitLoadArg(i + 1); // gen.Emit(OpCodes.Ldarg, i + 1);
gen.Emit(OpCodes.Call, m); // gen.EmitCall(m) improperly emits a callvirt in some cases
}
else
{
gen.EmitString(m.Name); // gen.Emit(OpCodes.Ldstr, m.Name);
gen.EmitNew(CtorInfo_NotImplementedException_1); // gen.Emit(OpCodes.Newobj, CtorInfo_NotImplementedException_1);
gen.Emit(OpCodes.Throw);
}
gen.MarkLabel(endLabel);
//.........这里部分代码省略.........
示例9: Emit
public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
{
if (objx.FnMode == FnMode.Light)
{
// This will emit a plain Keyword reference, rather than a callsite.
InvokeExpr ie = new InvokeExpr(_source, _spanMap, (Symbol)_tag, _kw, RT.vector(_target));
ie.Emit(rhc, objx, ilg);
}
else
{
Label endLabel = ilg.DefineLabel();
Label faultLabel = ilg.DefineLabel();
GenContext.EmitDebugInfo(ilg, _spanMap);
LocalBuilder thunkLoc = ilg.DeclareLocal(typeof(ILookupThunk));
LocalBuilder targetLoc = ilg.DeclareLocal(typeof(Object));
LocalBuilder resultLoc = ilg.DeclareLocal(typeof(Object));
GenContext.SetLocalName(thunkLoc, "thunk");
GenContext.SetLocalName(targetLoc, "target");
GenContext.SetLocalName(resultLoc, "result");
// TODO: Debug info
// pseudo-code:
// ILookupThunk thunk = objclass.ThunkField(i)
// object target = ...code...
// object val = thunk.get(target)
// if ( val != thunk )
// return val
// else
// KeywordLookupSite site = objclass.SiteField(i)
// thunk = site.fault(target)
// objclass.ThunkField(i) = thunk
// val = thunk.get(target)
// return val
ilg.EmitFieldGet(objx.ThunkField(_siteIndex)); // thunk
ilg.Emit(OpCodes.Stloc, thunkLoc); // (thunkLoc <= thunk)
_target.Emit(RHC.Expression, objx, ilg); // target
ilg.Emit(OpCodes.Stloc, targetLoc); // (targetLoc <= target)
ilg.Emit(OpCodes.Ldloc, thunkLoc);
ilg.Emit(OpCodes.Ldloc, targetLoc);
ilg.EmitCall(Compiler.Method_ILookupThunk_get); // result
ilg.Emit(OpCodes.Stloc, resultLoc); // (resultLoc <= result)
ilg.Emit(OpCodes.Ldloc, thunkLoc);
ilg.Emit(OpCodes.Ldloc, resultLoc);
ilg.Emit(OpCodes.Beq, faultLabel);
ilg.Emit(OpCodes.Ldloc, resultLoc); // result
ilg.Emit(OpCodes.Br, endLabel);
ilg.MarkLabel(faultLabel);
ilg.EmitFieldGet(objx.KeywordLookupSiteField(_siteIndex)); // site
ilg.Emit(OpCodes.Ldloc, targetLoc); // site, target
ilg.EmitCall(Compiler.Method_ILookupSite_fault); // new-thunk
ilg.Emit(OpCodes.Dup); // new-thunk, new-thunk
ilg.EmitFieldSet(objx.ThunkField(_siteIndex)); // new-thunk
ilg.Emit(OpCodes.Ldloc, targetLoc); // new-thunk, target
ilg.EmitCall(Compiler.Method_ILookupThunk_get); // result
ilg.MarkLabel(endLabel); // result
if (rhc == RHC.Statement)
ilg.Emit(OpCodes.Pop);
}
}
示例10: Emit
public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
{
MethodExpr.EmitArgsAsArray(_keyvals, objx, ilg);
ilg.EmitCall(Compiler.Method_RT_map);
if (rhc == RHC.Statement)
ilg.Emit(OpCodes.Pop);
}
示例11: 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);
}
示例12: 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);
}
}
示例13: EmitConstant
internal void EmitConstant(CljILGen ilg, int id, object val)
{
if (_fnMode == Ast.FnMode.Light)
{
if (val == null)
{
ilg.EmitNull();
}
if (val.GetType().IsPrimitive)
{
EmitPrimitive(ilg, val);
ilg.Emit(OpCodes.Box,val.GetType());
}
else
{
ilg.Emit(OpCodes.Ldarg_0); // this
ilg.Emit(OpCodes.Castclass, typeof(IFnClosure));
ilg.EmitCall(Compiler.Method_IFnClosure_GetClosure);
ilg.EmitFieldGet(Compiler.Field_Closure_Constants);
ilg.EmitInt(id);
ilg.EmitLoadElement(typeof(Object));
ilg.Emit(OpCodes.Castclass, ConstantType(id));
}
}
else
{
FieldBuilder fb = null;
if (_fnMode == FnMode.Full && ConstantFields != null && ConstantFields.TryGetValue(id, out fb))
{
ilg.MaybeEmitVolatileOp(fb);
ilg.Emit(OpCodes.Ldsfld, fb);
}
else
EmitValue(val, ilg);
}
}
示例14: EmitUnboxed
public void EmitUnboxed(RHC rhc, ObjExpr objx, CljILGen ilg)
{
if (_variadic)
{
ParameterInfo[] pinfos = _method.GetParameters();
for (int i =0; i< pinfos.Length-1; i++ )
{
Expr e = (Expr)_args.nth(i);
if (Compiler.MaybePrimitiveType(e) == pinfos[i].ParameterType)
((MaybePrimitiveExpr)e).EmitUnboxed(RHC.Expression, objx, ilg);
else
{
e.Emit(RHC.Expression, objx, ilg);
HostExpr.EmitUnboxArg(objx, ilg, pinfos[i].ParameterType);
}
}
IPersistentVector restArgs = RT.subvec(_args, pinfos.Length - 1, _args.count());
MethodExpr.EmitArgsAsArray(restArgs, objx, ilg);
ilg.EmitCall(Compiler.Method_ArraySeq_create);
}
else
MethodExpr.EmitTypedArgs(objx, ilg, _method.GetParameters(), _args);
ilg.EmitCall(_method);
}
示例15: 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);
}