Ejemplo n.º 1
0
		public FluentEmitter Div(MagicNumberArgument divisor)
		{
			if (divisor.IsZero)
				throw new DivideByZeroException("this instruction will cause a DivideByZeroException");

			return divisor.EmitLdc(this)
				.Emit(OpCodes.Div);
		}
Ejemplo n.º 2
0
        public FluentEmitter DivUn(MagicNumberArgument divisor)
        {
            if (divisor.IsZero)
            {
                throw new DivideByZeroException("this instruction will cause a DivideByZeroException");
            }

            return(divisor.EmitLdc(this)
                   .Emit(OpCodes.Div_Un));
        }
Ejemplo n.º 3
0
        public FluentEmitter Starg(MagicNumberArgument value, params string[] names)
        {
            if (names == null)
            {
                throw new ArgumentNullException(nameof(names));
            }

            var count = names.Length;

            var paramgroups = names
                              .Select(GetParameter)
                              .GroupBy(p => p.ParameterType.GetILType())
                              .OrderBy(pgroup => pgroup.Sum(p => p.Index));

            foreach (var paramgroup in paramgroups)
            {
                var isfirst = true;
                foreach (var param in paramgroup.OrderBy(p => p.Index))
                {
                    if (isfirst)
                    {
                        switch (param.ParameterType.GetILType())
                        {
                        case ILType.I4: value.EmitLdcI4(this); break;

                        case ILType.I8: value.EmitLdcI8(this); break;

                        case ILType.R8: value.EmitLdcR8(this); break;

                        case ILType.R4: value.EmitLdcR4(this); break;

                        default:
                            throw new NotSupportedException(
                                      "variable type must be primitive valuetype in system namespace and convertible to I4, I8, R4 or R8");
                        }
                        isfirst = false;
                    }
                    else
                    {
                        Dup();
                    }
                }
                foreach (var param in paramgroup)
                {
                    Starg((uint)param.Index);
                }
            }

            return(this);
        }
Ejemplo n.º 4
0
		public FluentEmitter Ret(MagicNumberArgument value)
		{
		    // ReSharper disable once SwitchStatementMissingSomeCases
			switch (ReturnType.GetILType())
			{
				case ILType.I4: value.EmitLdcI4(this); break;
				case ILType.I8: value.EmitLdcI8(this); break;
				case ILType.R8: value.EmitLdcR8(this); break;
				case ILType.R4: value.EmitLdcR4(this); break;
				default:
					throw new NotSupportedException(
						"return type must be primitive valuetype and convertible to I4, I8, R4 or R8");
			}
			return Ret();
		}
Ejemplo n.º 5
0
        public FluentEmitter Ret(MagicNumberArgument value)
        {
            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (ReturnType.GetILType())
            {
            case ILType.I4: value.EmitLdcI4(this); break;

            case ILType.I8: value.EmitLdcI8(this); break;

            case ILType.R8: value.EmitLdcR8(this); break;

            case ILType.R4: value.EmitLdcR4(this); break;

            default:
                throw new NotSupportedException(
                          "return type must be primitive valuetype and convertible to I4, I8, R4 or R8");
            }
            return(Ret());
        }
Ejemplo n.º 6
0
		public FluentEmitter Mul(MagicNumberArgument arg)
		{
			return arg.EmitLdc(this)
				.Emit(OpCodes.Mul);
		}
Ejemplo n.º 7
0
		public FluentEmitter Sub(MagicNumberArgument arg)
		{
			return arg.EmitLdc(this)
				.Emit(OpCodes.Sub);
		}
Ejemplo n.º 8
0
		public FluentEmitter RemUn(MagicNumberArgument divisor)
		{
			return divisor.EmitLdc(this)
				.Emit(OpCodes.Rem_Un);
		}
Ejemplo n.º 9
0
		public FluentEmitter Starg(MagicNumberArgument value, params string[] names)
		{
			if (names == null)
				throw new ArgumentNullException(nameof(names));

			var count = names.Length;

			var paramgroups = names
				.Select(GetParameter)
				.GroupBy(p => p.ParameterType.GetILType())
				.OrderBy(pgroup => pgroup.Sum(p => p.Index));

			foreach (var paramgroup in paramgroups)
			{
				var isfirst = true;
				foreach (var param in paramgroup.OrderBy(p => p.Index))
				{
					if (isfirst)
					{
						switch (param.ParameterType.GetILType())
						{
							case ILType.I4: value.EmitLdcI4(this); break;
							case ILType.I8: value.EmitLdcI8(this); break;
							case ILType.R8: value.EmitLdcR8(this); break;
							case ILType.R4: value.EmitLdcR4(this); break;
							default:
								throw new NotSupportedException(
							   "variable type must be primitive valuetype in system namespace and convertible to I4, I8, R4 or R8");
						}
						isfirst = false;
					}
					else
						Dup();
				}
				foreach (var param in paramgroup)
				{
					Starg((uint)param.Index);
				}
			}

			return this;
		}
Ejemplo n.º 10
0
 public FluentEmitter Mul(MagicNumberArgument arg)
 {
     return(arg.EmitLdc(this)
            .Emit(OpCodes.Mul));
 }
Ejemplo n.º 11
0
 public FluentEmitter RemUn(MagicNumberArgument divisor)
 {
     return(divisor.EmitLdc(this)
            .Emit(OpCodes.Rem_Un));
 }