Example #1
0
 public static void Run(ref mdr.DValue i0, int i1)
 {
     switch (i0.ValueType)
     {
         case mdr.ValueTypes.Double:
             {
                 double oldValue = i0.DoubleValue;
                 double newValue = oldValue + i1;
                 i0.DoubleValue = newValue;
                 //i0.Set(newValue);
                 break;
             }
         case mdr.ValueTypes.Int32:
             {
                 int oldValue = i0.IntValue;
                 int newValue = oldValue + i1;
                 i0.IntValue = newValue;
                 //i0.Set(newValue);
                 break;
             }
         case mdr.ValueTypes.Boolean:
             {
                 int oldValue = i0.BooleanValue ? 1 : 0;
                 int newValue = oldValue + i1;
                 i0.Set(newValue);
                 break;
             }
         default:
             {
                 double oldValue = i0.AsDouble();
                 double newValue = oldValue + i1;
                 i0.Set(newValue);
                 break;
             }
     }
 }
Example #2
0
        //public static mdr.DValue IncDec(ref mdr.DValue i0, int i1)
        //{
        //    var result = new mdr.DValue();
        //    switch (i0.ValueType)
        //    {
        //        case mdr.ValueTypes.Int:
        //            {
        //                int oldValue = i0.IntValue;
        //                int newValue = oldValue + i1;
        //                result.Set(newValue);
        //                break;
        //            }
        //        case mdr.ValueTypes.Boolean:
        //            {
        //                int oldValue = i0.BoolValue ? 1 : 0;
        //                int newValue = oldValue + i1;
        //                result.Set(newValue);
        //                break;
        //            }
        //        default:
        //            {
        //                double oldValue = i0.ToDouble();
        //                double newValue = oldValue + i1;
        //                result.Set(newValue);
        //                break;
        //            }
        //    }
        //    return result;
        //}

        /// <summary>
        /// The following is used for inc/dec that involves DValue. To handle arrays and properties well, we will have a separate object for 
        /// reading the value, and another for setting. To make the inc/dec and assign, etc. uniform, we should consider that on the stack 
        /// we have all the paramertes always for all kinds of values (symbols, arrays, properties, ...)
        /// 
        /// followings:
        ///     dest for writing
        ///     DObject  for setting (for array/property will be a member of the object itself)
        ///     DObject  for reading (for array/property may be a member of the object's prototype)
        /// </summary>
        /// <param name="result">for returing the value that is used in the next instruction.</param>
        /// <param name="dest">For updating the source itself</param>
        /// <param name="i0">the source for reading the value</param>
        /// <param name="i1">1 for inc and -1 for dec</param>
        /// <param name="isPostfix"></param>
        /// <returns></returns>
        public static void AddConst(ref mdr.DValue dest, /*const*/ ref mdr.DValue i0, int i1, bool isPostfix, ref mdr.DValue result)
        {
            switch (i0.ValueType)
            {
                case mdr.ValueTypes.Int32:
                    {
                        int oldValue = i0.IntValue;
                        int newValue = oldValue + i1;
                        dest.Set(newValue);
                        result.Set(isPostfix ? oldValue : newValue);
                        break;
                    }
                case mdr.ValueTypes.Boolean:
                    {
                        int oldValue = i0.BooleanValue ? 1 : 0;
                        int newValue = oldValue + i1;
                        dest.Set(newValue);
                        result.Set(isPostfix ? oldValue : newValue);
                        break;
                    }
                default:
                    {
                        double oldValue = i0.AsDouble();
                        double newValue = oldValue + i1;
                        dest.Set(newValue);
                        result.Set(isPostfix ? oldValue : newValue);
                        break;
                    }
            }
        }