本文整理汇总了C#中ILGen.TryEmitConstant方法的典型用法代码示例。如果您正苦于以下问题:C# ILGen.TryEmitConstant方法的具体用法?C# ILGen.TryEmitConstant怎么用?C# ILGen.TryEmitConstant使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILGen
的用法示例。
在下文中一共展示了ILGen.TryEmitConstant方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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)
{
//.........这里部分代码省略.........