Example #1
0
            public void PopAssignableTo(Opcode opcode, Type targetType)
            {
                Contract.Requires(opcode != null);
                Contract.Requires(targetType != null);

                if (entries.Count == 0)
                {
                    throw Error("{0} expects a stack operand of type {1}, but the stack is empty.", opcode.Name, targetType.FullName);
                }

                var poppedEntry = Pop(opcode);

                if (poppedEntry.CtsType == null)
                {
                    if (targetType.IsValueType)
                    {
                        throw Error("{0} expects a stack operand of type {1}, but the top of the stack is a null value.", opcode.Name, targetType.FullName);
                    }
                }
                else if (!targetType.IsAssignableFrom(poppedEntry.CtsType))
                {
                    var targetDataType = DataTypeEnum.FromCtsType(targetType);
                    if (targetDataType.ToStackType() != poppedEntry.DataType ||
                        targetDataType == DataType.ValueType ||
                        targetDataType == DataType.ObjectReference)
                    {
                        throw Error("{0} expects a stack operand of type {1} but the stack top has type {2}.",
                                    opcode.Name, targetType.FullName, poppedEntry.CtsType.FullName);
                    }
                }
            }
Example #2
0
 public void StoreIndirect(Type type)
 {
     Contract.Requires(type != null);
     if (type.IsValueType)
     {
         Instruction(Opcode.Stobj, type);
     }
     else
     {
         base.StoreIndirect(DataTypeEnum.FromCtsType(type));
     }
 }
Example #3
0
            public void Push(Type ctsType)
            {
                Contract.Requires(ctsType != null);

                var dataType = DataTypeEnum.FromCtsType(ctsType);

                if (!dataType.IsStackType())
                {
                    dataType = dataType.ToStackType();
                    ctsType  = dataType.ToCtsType() ?? ctsType;
                }

                Push(new StackEntry(dataType, ctsType));
            }