示例#1
0
        private NamespaceDictionary CreateNamespaceDictionary(IDictionary <object, object> dict)
        {
            string[]   names    = (string[])this.type.GetField(NewTypeMaker.VtableNamesField).GetValue(null);
            SymbolId[] symNames = new SymbolId[names.Length];
            for (int i = 0; i < symNames.Length; i++)
            {
                symNames[i] = SymbolTable.StringToId(names[i]);
            }
            NamespaceDictionary ret = NamespaceDictionary.Make(symNames, bases);

            foreach (KeyValuePair <object, object> kv in dict)
            {
                PythonFunction func = kv.Value as PythonFunction;
                if (func != null && func.Name != "__new__")
                {
                    ret.AsObjectKeyedDictionary()[kv.Key] = new Method(func, null, this);
                }
                else
                {
                    ret.AsObjectKeyedDictionary()[kv.Key] = kv.Value;
                }
            }
            //!!! need invalidation, inheritance, all that good stuff
            return(ret);
        }
示例#2
0
 private void PropagateInheritedKey(int from, int to, NamespaceDictionary parent)
 {
     if (!parent.isInherited[from] && isInherited[to])
     {
         // our parent didn't has an override, so we get
         // their override too.  Both are user defined functions
         // so we clear isInherited for this slot.
         values[to]      = parent.values[to];
         isInherited[to] = false;
     }
 }
示例#3
0
 protected NamespaceDictionary(SymbolId[] knownKeys, Tuple bases)
     : this(knownKeys) {
     this.bases = bases;
     for (int i = 0; i < bases.Count; i++)
     {
         UserType ut = bases[i] as UserType;
         if (ut != null)
         {
             NamespaceDictionary nd = ut.dict as NamespaceDictionary;
             if (nd != null)
             {
                 PropagateKeys(nd);
             }
         }
     }
 }
示例#4
0
 private void PropagateKeys(NamespaceDictionary nd)
 {
     for (int i = 0; i < keys.Length && i < nd.keys.Length; i++)
     {
         if (nd.keys[i] == keys[i])
         {
             // common case: our layout matches our parents
             PropagateInheritedKey(i, i, nd);
         }
         else
         {
             // uncommon case - multiple inheritance only (maybe?)
             for (int j = 0; j < keys.Length; j++)
             {
                 if (nd.keys[i] == keys[j])
                 {
                     PropagateInheritedKey(j, i, nd);
                 }
             }
         }
     }
 }