示例#1
0
文件: PyBool.cs 项目: bamyazi/cloaca
        public static PyObject __xor__(PyObject self, PyObject other)
        {
            var orded = extractInt(self) ^ extractInt(other);

            return(orded > 0 ? PyBool.True : PyBool.False);
        }
示例#2
0
文件: PyBool.cs 项目: bamyazi/cloaca
 public static PyBool __ne__(PyObject self, PyObject other)
 {
     return(extractInt(self) != extractInt(other));
 }
示例#3
0
 public static void append(PyList self, PyObject toAdd)
 {
     self.list.Add(toAdd);
 }
示例#4
0
文件: PyBool.cs 项目: bamyazi/cloaca
        public static PyObject __and__(PyObject self, PyObject other)
        {
            var anded = extractInt(self) & extractInt(other);

            return(anded > 0 ? PyBool.True : PyBool.False);
        }
示例#5
0
 public static new PyString __repr__(PyObject self)
 {
     return(PyString.Create(((PyString)self).ToString()));
 }
示例#6
0
 public PyBool __eq__(PyObject other)
 {
     return(Equals(other));
 }
示例#7
0
        public static PyInteger __len__(IInterpreter interpreter, FrameContext context, PyObject self)
        {
            var asDict = (PyDict)self;

            return(PyInteger.Create(asDict.InternalDict.Count));
        }
示例#8
0
文件: PyBool.cs 项目: bamyazi/cloaca
        public static PyObject __floordiv__(PyObject self, PyObject other)
        {
            var newPyInteger = PyInteger.Create((BigInteger)((decimal)extractInt(self) / PyFloatClass.ExtractAsDecimal(other)));

            return(newPyInteger);
        }
示例#9
0
 public static Task <PyString> __str__(IInterpreter interpreter, FrameContext context, PyObject self)
 {
     return(__repr__(interpreter, context, self));
 }
示例#10
0
        public static async Task <PyString> __repr__(IInterpreter interpreter, FrameContext context, PyObject self)
        {
            var      asDict  = (PyDict)self;
            PyString retStr  = PyString.Create("{");
            int      visited = 0;

            foreach (var mapping in asDict.dict)
            {
                var key_repr = await __visit_repr((PyObject)mapping.Key, interpreter, context);

                retStr = (PyString)PyStringClass.__add__(retStr, key_repr);
                retStr = (PyString)PyStringClass.__add__(retStr, PyString.Create(": "));

                var val_repr = await __visit_repr((PyObject)mapping.Value, interpreter, context);

                retStr = (PyString)PyStringClass.__add__(retStr, val_repr);

                // Appending commas except on last paring
                if (visited < asDict.dict.Count - 1)
                {
                    retStr = (PyString)PyStringClass.__add__(retStr, PyString.Create(", "));
                }

                visited += 1;
            }
            return((PyString)PyStringClass.__add__(retStr, PyString.Create("}")));
        }
示例#11
0
 public static void __setitem__(PyList self, PyInteger i, PyObject value)
 {
     __setitem__(self, (int)i.number, value);
 }
示例#12
0
        public static async Task <PyString> __repr__(IInterpreter interpreter, FrameContext context, PyObject self)
        {
            var      asList = (PyList)self;
            PyString retStr = PyString.Create("[");

            for (int i = 0; i < asList.list.Count; ++i)
            {
                var pyObj = asList.list[i];

                var __repr__      = pyObj.__getattribute__(PyClass.__REPR__);
                var functionToRun = __repr__ as IPyCallable;

                var returned = await functionToRun.Call(interpreter, context, new object[0]);

                if (returned != null)
                {
                    var asPyString = (PyString)returned;
                    retStr = (PyString)PyStringClass.__add__(retStr, asPyString);
                }

                // Appending commas except on last index
                if (i < asList.list.Count - 1)
                {
                    retStr = (PyString)PyStringClass.__add__(retStr, PyString.Create(", "));
                }
            }
            return((PyString)PyStringClass.__add__(retStr, PyString.Create("]")));
        }
示例#13
0
 public static void prepend(PyList self, PyObject toAdd)
 {
     self.list.Insert(0, toAdd);
 }
示例#14
0
文件: PyBool.cs 项目: bamyazi/cloaca
        public static PyObject __lshift__(PyObject self, PyObject other)
        {
            var orded = (int)PyBoolClass.extractInt(self) << (int)PyBoolClass.extractInt(other);

            return(PyInteger.Create(orded));
        }
示例#15
0
        public static PyObject __iter__(PyObject self)
        {
            var asDict = self as PyDict;

            return(PyKeyIterator.Create(asDict));
        }
示例#16
0
文件: PyBool.cs 项目: bamyazi/cloaca
        public static PyObject __truediv__(PyObject self, PyObject other)
        {
            var newPyFloat = PyFloat.Create((decimal)extractInt(self) / PyFloatClass.ExtractAsDecimal(other));

            return(newPyFloat);
        }
示例#17
0
        public static PyObject __iter__(PyObject self)
        {
            var asDict = self as PyDict_Items;

            return(PyDictItemsIterator.Create(asDict.Dict));
        }
示例#18
0
 public static new PyString __str__(PyObject self)
 {
     return(__repr__(self));
 }
示例#19
0
        public static PyObject __iter__(PyObject self)
        {
            var asPyRange = self as PyRange;

            return(PyRangeIterator.Create(asPyRange));
        }
示例#20
0
 public static PyObject __div__(PyObject self, PyObject other)
 {
     // TODO: TypeError: unsupported operand type(s) for /: '[self type]' and '[other type]'
     throw new Exception("Strings do not support division");
 }
示例#21
0
        public static PyInteger __len__(IInterpreter interpreter, FrameContext context, PyObject self)
        {
            var asPyRange = (PyRange)self;

            return(PyInteger.Create(Math.Abs((asPyRange.Max - asPyRange.Min) / asPyRange.Step)));
        }
示例#22
0
 public PyBool __ne__(PyObject other)
 {
     return(!Equals(other));
 }
示例#23
0
 public static PyBool __ne__(PyList self, PyObject other)
 {
     return(!__eq__(self, other));
 }