Example #1
0
    public static void LoadVariable(mdr.DObject context, int fieldId, int ancestorDistance, ref Stack stack)
    {
      mdr.PropertyDescriptor pd = null;

      //TODO: If we do not create a prototype for GlobalContext, the following code would have been enough!
      //var pd = context.GetPropertyDescriptorByLineId(fieldId);
      //pd.Get(context, ref stack.Items[stack.Sp++]);

      if (ancestorDistance < 0)
      {//We are dealing with unknown symbol type
        while (context != mdr.Runtime.Instance.GlobalContext)
        {
          pd = context.Map.GetPropertyDescriptorByFieldId(fieldId);
          if (pd != null)
            break;
          context = context.Prototype;
        }
      }
      else
      {//we are dealing with known symbol type
        for (var i = 0; i < ancestorDistance && context != mdr.Runtime.Instance.GlobalContext; ++i)
        {
          context = context.Prototype;
        }
      }
      if (pd == null)
        pd = context.GetPropertyDescriptorByFieldId(fieldId);
      pd.Get(context, ref stack.Items[stack.Sp++]);
    }