Beispiel #1
0
            internal override PythonTuple GetBufferInfo()
            {
                var shape = Shape;

                return(PythonTuple.MakeTuple(
                           NativeType.TypeFormat,
                           shape.Count,
                           PythonTuple.Make(shape)
                           ));
            }
        internal static PythonTuple MroToPython(IList <PythonType> types)
        {
            List <object> res = new List <object>(types.Count);

            foreach (PythonType dt in types)
            {
                if (dt.UnderlyingSystemType == typeof(ValueType))
                {
                    continue;                                               // hide value type
                }
                res.Add(dt);
            }

            return(PythonTuple.Make(res));
        }
Beispiel #3
0
            internal override PythonTuple GetBufferInfo()
            {
                INativeType   elemType   = ElementType;
                int           dimensions = 1;
                List <object> shape      = new List <object>();

                shape.Add((BigInteger)__len__());
                while (elemType is ArrayType)
                {
                    dimensions++;
                    shape.Add((BigInteger)((ArrayType)elemType).Length);
                    elemType = ((ArrayType)elemType).ElementType;
                }


                return(PythonTuple.MakeTuple(
                           NativeType.TypeFormat,
                           dimensions,
                           PythonTuple.Make(shape)
                           ));
            }
Beispiel #4
0
        internal bool TryGetBoundCustomMember(CodeContext context, string name, out object value)
        {
            if (name == "__bases__")
            {
                value = PythonTuple.Make(_bases); return(true);
            }
            if (name == "__name__")
            {
                value = _name; return(true);
            }
            if (name == "__dict__")
            {
                //!!! user code can modify __del__ property of __dict__ behind our back
                HasDelAttr = HasSetAttr = true;  // pessimisticlly assume the user is setting __setattr__ in the dict
                value      = _dict; return(true);
            }

            if (TryLookupSlot(name, out value))
            {
                value = GetOldStyleDescriptor(context, value, null, this);
                return(true);
            }
            return(false);
        }
            public override void __init__(params object[] args)
            {
                base.__init__(args);

                if (args != null && args.Length != 0)
                {
                    msg = args[0];

                    // (msg, (filename, lineno, offset, text))
                    if (args.Length == 2)
                    {
                        var locationInfo = PythonTuple.Make(args[1]);
                        if (locationInfo.__len__() != 4)
                        {
                            throw PythonOps.IndexError("tuple index out of range");
                        }

                        filename = locationInfo[0];
                        lineno   = locationInfo[1];
                        offset   = locationInfo[2];
                        text     = locationInfo[3];
                    }
                }
            }
Beispiel #6
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);
            }
Beispiel #7
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);
            }
Beispiel #8
0
 public static bool operator <=(floatinfo stat, IList o)
 {
     return(stat.MakeTuple() >= PythonTuple.Make(o));
 }
Beispiel #9
0
 public static struct_time __new__(CodeContext context, PythonType cls, [NotNull] IEnumerable sequence)
 {
     return(__new__(context, cls, PythonTuple.Make(sequence)));
 }
Beispiel #10
0
 public static object DoErrorCheck(object errCheckFunc, object result, object func, object[] arguments)
 {
     return(PythonCalls.Call(errCheckFunc, result, func, PythonTuple.Make(arguments)));
 }