本文整理汇总了C#中clojure.lang.CljCompiler.Ast.CljILGen.EmitType方法的典型用法代码示例。如果您正苦于以下问题:C# CljILGen.EmitType方法的具体用法?C# CljILGen.EmitType怎么用?C# CljILGen.EmitType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类clojure.lang.CljCompiler.Ast.CljILGen
的用法示例。
在下文中一共展示了CljILGen.EmitType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
//.........这里部分代码省略.........
示例2: LightEmit
void LightEmit(RHC rhc, ObjExpr objx, CljILGen ilg)
{
//emitting a Fn means constructing an instance, feeding closed-overs from enclosing scope, if any
//objx arg is enclosing objx, not this
// Create the function instance
LocalBuilder fnLocal = ilg.DeclareLocal(CompiledType);
if (CompiledType == typeof(RestFnImpl))
{
ilg.EmitInt(_variadicMethod.RequiredArity);
ilg.EmitNew(Compiler.Ctor_RestFnImpl_1);
}
else
{
ilg.EmitNew(Compiler.Ctor_AFnImpl);
}
ilg.Emit(OpCodes.Stloc, fnLocal);
//ilg.EmitString(String.Format("Creating fn {0}", Name));
//ilg.Emit(OpCodes.Call, typeof(System.Console).GetMethod("WriteLine", new Type[] { typeof(string) }));
// Set up the methods
for (ISeq s = RT.seq(_methods); s != null; s = s.next())
{
FnMethod method = (FnMethod)s.first();
int key = GetMethodKey(method);
string fieldName = IsVariadic && method.IsVariadic
? "_fnDo" + (key - 1) // because key is arity+1 for variadic
: "_fn" + key;
FieldInfo fi = CompiledType.GetField(fieldName);
ilg.Emit(OpCodes.Ldloc, fnLocal);
EmitGetDynMethod(key, ilg);
ilg.EmitType(fi.FieldType);
ilg.Emit(OpCodes.Ldloc, fnLocal);
ilg.Emit(OpCodes.Callvirt, Method_DynamicMethod_CreateDelegate);
ilg.Emit(OpCodes.Castclass, fi.FieldType);
ilg.EmitFieldSet(fi);
}
// setup the constants and locals
ilg.Emit(OpCodes.Ldloc, fnLocal);
if (Constants.count() > 0)
{
EmitGetCompiledConstants(ilg);
}
else
{
ilg.EmitInt(0);
ilg.EmitArray(typeof(Object[]));
}
if (Closes.count() > 0)
{
int maxIndex = Closes.Max(c => ((LocalBinding)c.key()).Index);
ilg.EmitInt(maxIndex + 1);
ilg.Emit(OpCodes.Newarr, typeof(object));
for (ISeq s = RT.keys(Closes); s != null; s = s.next())
{
LocalBinding lb = (LocalBinding)s.first();
ilg.Emit(OpCodes.Dup);
ilg.EmitInt(lb.Index);
objx.EmitLocal(ilg, lb);
ilg.EmitStoreElement(typeof(object));
}
}
else
{
ilg.EmitInt(0);
ilg.EmitArray(typeof(Object[]));
}
// Create the closure
ilg.EmitNew(Compiler.Ctor_Closure_2);
// Assign the clojure
ilg.EmitCall(Compiler.Method_IFnClosure_SetClosure);
// Leave the instance on the stack.
ilg.Emit(OpCodes.Ldloc, fnLocal);
}