Пример #1
0
        internal void LazyEmitUnboxSpecial(Type type)
        {
            BoxExpr box = PeekStack() as BoxExpr;

            if (box != null)
            {
                PopStack();
                // the unbox and lazy box cancel each other out
                PushStackMayBeNull(box.Expr);
            }
            else
            {
                // NOTE if the reference is null, we treat it as a default instance of the value type.
                Emit(OpCodes.Dup);
                CodeEmitterLabel label1 = DefineLabel();
                Emit(OpCodes.Brtrue_S, label1);
                Emit(OpCodes.Pop);
                Emit(OpCodes.Ldloc, DeclareLocal(type));
                CodeEmitterLabel label2 = DefineLabel();
                Emit(OpCodes.Br_S, label2);
                MarkLabel(label1);
                Emit(OpCodes.Unbox, type);
                Emit(OpCodes.Ldobj, type);
                MarkLabel(label2);
            }
        }
Пример #2
0
        internal void LazyEmitUnbox(Type type)
        {
            BoxExpr box = PeekStack() as BoxExpr;

            if (box != null)
            {
                PopStack();
                PushStack(new BoxUnboxExpr(box.Expr, type));
            }
            else
            {
                PushStack(new UnboxExpr(PopStack(), type));
            }
        }