예제 #1
0
            public object ReadObject()
            {
                while (_myBytes.MoveNext())
                {
                    byte   cur = _myBytes.Current;
                    object res;
                    switch ((char)cur)
                    {
                    case '(': PushStack(StackType.Tuple); break;

                    case '[': PushStack(StackType.List); break;

                    case '{': PushStack(StackType.Dict); break;

                    case '<': PushStack(StackType.Set); break;

                    case '>': PushStack(StackType.FrozenSet); break;

                    case '0':
                        // end of dictionary
                        if (_stack == null || _stack.Count == 0)
                        {
                            throw PythonOps.ValueError("bad marshal data");
                        }
                        _stack.Peek().StackCount = 0;
                        break;

                    // case 'c': break;
                    default:
                        res = YieldSimple();
                        if (_stack == null)
                        {
                            return(res);
                        }

                        do
                        {
                            res = UpdateStack(res);
                        } while (res != null && _stack.Count > 0);

                        if (_stack.Count == 0)
                        {
                            return(_result);
                        }

                        continue;
                    }

                    // handle empty lists/tuples...
                    if (_stack != null && _stack.Count > 0 && _stack.Peek().StackCount == 0)
                    {
                        ProcStack ps = _stack.Pop();
                        res = ps.StackObj;

                        if (ps.StackType == StackType.Tuple)
                        {
                            res = PythonTuple.Make(res);
                        }
                        else if (ps.StackType == StackType.FrozenSet)
                        {
                            res = FrozenSetCollection.Make(TypeCache.FrozenSet, res);
                        }

                        if (_stack.Count > 0)
                        {
                            // empty list/tuple
                            do
                            {
                                res = UpdateStack(res);
                            } while (res != null && _stack.Count > 0);
                            if (_stack.Count == 0)
                            {
                                break;
                            }
                        }
                        else
                        {
                            _result = res;
                            break;
                        }
                    }
                }

                return(_result);
            }
예제 #2
0
            private object UpdateStack(object res)
            {
                ProcStack curStack = _stack.Peek();

                switch (curStack.StackType)
                {
                case StackType.Dict:
                    PythonDictionary od = curStack.StackObj as PythonDictionary;
                    if (curStack.HaveKey)
                    {
                        od[curStack.Key] = res;
                        curStack.HaveKey = false;
                    }
                    else
                    {
                        curStack.HaveKey = true;
                        curStack.Key     = res;
                    }
                    break;

                case StackType.Tuple:
                    List <object> objs = curStack.StackObj as List <object>;
                    objs.Add(res);
                    curStack.StackCount--;
                    if (curStack.StackCount == 0)
                    {
                        _stack.Pop();
                        object tuple = PythonTuple.Make(objs);
                        if (_stack.Count == 0)
                        {
                            _result = tuple;
                        }
                        return(tuple);
                    }
                    break;

                case StackType.List:
                    PythonList ol = curStack.StackObj as PythonList;
                    ol.AddNoLock(res);
                    curStack.StackCount--;
                    if (curStack.StackCount == 0)
                    {
                        _stack.Pop();
                        if (_stack.Count == 0)
                        {
                            _result = ol;
                        }
                        return(ol);
                    }
                    break;

                case StackType.Set:
                    SetCollection os = curStack.StackObj as SetCollection;
                    os.add(res);
                    curStack.StackCount--;
                    if (curStack.StackCount == 0)
                    {
                        _stack.Pop();
                        if (_stack.Count == 0)
                        {
                            _result = os;
                        }
                        return(os);
                    }
                    break;

                case StackType.FrozenSet:
                    List <object> ofs = curStack.StackObj as List <object>;
                    ofs.Add(res);
                    curStack.StackCount--;
                    if (curStack.StackCount == 0)
                    {
                        _stack.Pop();
                        object frozenSet = FrozenSetCollection.Make(TypeCache.FrozenSet, ofs);
                        if (_stack.Count == 0)
                        {
                            _result = frozenSet;
                        }
                        return(frozenSet);
                    }
                    break;
                }
                return(null);
            }
예제 #3
0
 public FrozenSetCollection intersection([NotNull] FrozenSetCollection set)
 {
     return(Make(SetStorage.Intersection(_items, set._items)));
 }
예제 #4
0
 public bool issuperset([NotNull] FrozenSetCollection set)
 {
     return(set._items.IsSubset(_items));
 }
예제 #5
0
 public bool isdisjoint([NotNull] FrozenSetCollection set)
 {
     return(_items.IsDisjoint(set._items));
 }
예제 #6
0
파일: Set.cs 프로젝트: slozier/ironpython3
 public FrozenSetCollection union([NotNone] FrozenSetCollection set)
 {
     return(Make(SetStorage.Union(_items, set._items)));
 }
예제 #7
0
파일: Set.cs 프로젝트: slozier/ironpython3
 public bool issubset([NotNone] FrozenSetCollection set)
 {
     return(_items.IsSubset(set._items));
 }