예제 #1
0
        public static void StoreVariable(mdr.DObject context, int fieldId, int ancestorDistance, bool pushBackResult, ref Stack stack)
        {
            var valueIndex = stack.Sp - 1;

            //TODO: If we do not create a prototype for GlobalContext, the following code would have been enough!
            //var pd = context.Map.GetPropertyDescriptorByFieldId(fieldId);
            //if (pd != null)
            //    pd.Set(context, ref stack.Items[stack.Sp - 1]);
            //else
            //    mdr.Runtime.Instance.GlobalContext.SetFieldByFieldId(fieldId, ref stack.Items[stack.Sp - 1]); //DOTO: this is very expensive!

            mdr.PropertyDescriptor pd = null;

            if (ancestorDistance < 0)
            {//We are dealing with unknown symbol type
             //while (context != mdr.Runtime.Instance.GlobalContext)
             //{
             //    pd = context.Map.GetCachedOwnPropertyDescriptorByFieldId(fieldId);
             //    if (pd != null)
             //        break;
             //    context = context.Prototype;
             //}
             //if (pd != null)
             //    pd.Set(context, ref stack.Items[stack.Sp - 1]);
             //else
             //    context.SetFieldByFieldId(fieldId, ref stack.Items[stack.Sp - 1]);

                pd = context.Map.GetPropertyDescriptorByFieldId(fieldId);
                if (pd != null && !pd.IsUndefined)
                {
                    pd.Set(context, ref stack.Items[valueIndex]);
                }
                else
                {
                    mdr.Runtime.Instance.GlobalContext.SetFieldByFieldId(fieldId, ref stack.Items[valueIndex]);
                }
            }
            else
            {//we are dealing with known symbol type
                for (var i = 0; i < ancestorDistance && context != mdr.Runtime.Instance.GlobalContext; ++i)
                {
                    context = context.Prototype;
                }
                pd = context.Map.GetPropertyDescriptorByFieldId(fieldId);
                Debug.Assert(pd != null && pd.IsDataDescriptor, "Invalid situation, variable is undeclared in current context");
                pd.Set(context, ref stack.Items[valueIndex]);
            }

            if (!pushBackResult)
            {
                stack.Sp = valueIndex;
            }
        }
예제 #2
0
 public DForwardingProperty(DObject receiver, string field)
 {
     Receiver   = receiver;
     ReceiverPD = Receiver.Map.GetPropertyDescriptor(field);
     Debug.Assert(ReceiverPD != null, "receiver field has null descriptor: " + field);
     OnGetDValue = (DObject This, ref DValue v) =>
     {
         ReceiverPD.Get(Receiver, ref v);
     };
     OnSetDValue = (DObject This, ref DValue v) =>
     {
         ReceiverPD.Set(Receiver, ref v);
     };
 }
예제 #3
0
 public DForwardingProperty (DObject receiver, string field)
 {
     Receiver = receiver;
     ReceiverPD = Receiver.Map.GetPropertyDescriptor(field);
     Debug.Assert(ReceiverPD != null, "receiver field has null descriptor: " + field);
     OnGetDValue = (DObject This, ref DValue v) =>
     {
         ReceiverPD.Get(Receiver, ref v);
     };
     OnSetDValue = (DObject This, ref DValue v) =>
     {
         ReceiverPD.Set(Receiver, ref v);
     };
 }