Exemplo n.º 1
0
        public static PyObject __mod__(PyObject self, PyObject other)
        {
            PyInteger a, b;

            castOperands(self, other, out a, out b, "modulo");
            var newPyInteger = PyInteger.Create(a.InternalValue % b.InternalValue);

            return(newPyInteger);
        }
Exemplo n.º 2
0
        public static PyObject __floordiv__(PyObject self, PyObject other)
        {
            PyInteger a, b;

            castOperands(self, other, out a, out b, "floor division");
            var newPyInteger = PyInteger.Create(a.InternalValue / b.InternalValue);

            return(newPyInteger);
        }
Exemplo n.º 3
0
        public static PyObject __sub__(PyObject self, PyObject other)
        {
            PyInteger a, b;

            castOperands(self, other, out a, out b, "subtraction");
            var newPyInteger = PyInteger.Create(a.number - b.number);

            return(newPyInteger);
        }
Exemplo n.º 4
0
        public static PyObject __mul__(PyObject self, PyObject other)
        {
            PyInteger a, b;

            castOperands(self, other, out a, out b, "multiplication");
            var newPyInteger = PyInteger.Create(a.InternalValue * b.InternalValue);

            return(newPyInteger);
        }
Exemplo n.º 5
0
        public static PyObject __pow__(PyObject self, PyObject other)
        {
            PyInteger a, b;

            castOperands(self, other, out a, out b, "exponent");
            double doubleExp    = Math.Pow((double)a.InternalValue, (double)b.InternalValue);
            var    newPyInteger = PyInteger.Create((BigInteger)doubleExp);

            return(newPyInteger);
        }
Exemplo n.º 6
0
        public static PyObject __sub__(PyObject self, PyObject other)
        {
            // TODO [INTEGERS WITH FLOATS] Handle mixing of PyFloat and PyInteger(PyBool?) with basic arithmetic operators; 2 - 1.0 shouldn't fail.
            PyInteger a, b;

            castOperands(self, other, out a, out b, "subtraction");
            var newPyInteger = PyInteger.Create(a.InternalValue - b.InternalValue);

            return(newPyInteger);
        }
Exemplo n.º 7
0
 public static PyObject __sub__(PyObject self, PyObject other)
 {
     if (other is PyInteger)
     {
         return(PyInteger.Create(extractInt(self) - extractInt(other)));
     }
     else
     {
         return(PyFloat.Create(PyFloatClass.ExtractAsDecimal(self) - PyFloatClass.ExtractAsDecimal(other)));
     }
 }
Exemplo n.º 8
0
 public static object __getitem__(PyList self, PyInteger i)
 {
     try
     {
         return(self.list[(int)i.InternalValue]);
     }
     catch (IndexOutOfRangeException)
     {
         // TODO: Represent as a more natural Python exception;
         throw new Exception("IndexError: list index out of range");
     }
 }
Exemplo n.º 9
0
 public static void __delitem__(PyList self, PyInteger i)
 {
     try
     {
         self.list.RemoveAt((int)i.InternalValue);
     }
     catch (IndexOutOfRangeException)
     {
         // TODO: Represent as a more natural Python exception;
         throw new Exception("IndexError: list assignment index out of range");
     }
 }
Exemplo n.º 10
0
 public static PyObject __getitem__(PyTuple self, PyInteger i)
 {
     try
     {
         return(self.Values[(int)i.number]);
     }
     catch (IndexOutOfRangeException)
     {
         // TODO: Represent as a more natural Python exception;
         throw new Exception("IndexError: tuple index out of range");
     }
 }
Exemplo n.º 11
0
 // TODO [INTEGERS WITH FLOATS] Handle mixing of PyFloat and PyInteger(PyBool?) with basic arithmetic operators; 2 - 1.0 shouldn't fail.
 private static void castOperands(PyObject self, PyObject other, out PyInteger selfOut, out PyInteger otherOut, string operation)
 {
     selfOut  = self as PyInteger;
     otherOut = other as PyInteger;
     if (selfOut == null)
     {
         throw new Exception("Tried to use a non-PyInteger for lvalue of: " + operation);
     }
     if (otherOut == null)
     {
         throw new Exception("Tried to use a non-PyInteger for rvalue of: " + operation);
     }
 }
Exemplo n.º 12
0
        public static object __next__(PyObject self)
        {
            var asIterator = self as PyRangeIterator;

            if (asIterator.Current >= asIterator.Max)
            {
                throw new StopIterationException();
            }
            else
            {
                var toReturn = PyInteger.Create(asIterator.Current);
                asIterator.Current += asIterator.Step;
                return(toReturn);
            }
        }
Exemplo n.º 13
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)));
        }
Exemplo n.º 14
0
 public static PyInteger __neg__(PyObject self)
 {
     return(PyInteger.Create(-((PyInteger)self).InternalValue));
 }
Exemplo n.º 15
0
        public static PyObject __lshift__(PyObject self, PyObject other)
        {
            var orded = (int)PyBoolClass.extractInt(self) << (int)PyBoolClass.extractInt(other);

            return(PyInteger.Create(orded));
        }
Exemplo n.º 16
0
        public static PyObject __xor__(PyObject self, PyObject other)
        {
            var orded = PyBoolClass.extractInt(self) ^ PyBoolClass.extractInt(other);

            return(PyInteger.Create(orded));
        }
Exemplo n.º 17
0
        public static PyObject __and__(PyObject self, PyObject other)
        {
            var anded = PyBoolClass.extractInt(self) & PyBoolClass.extractInt(other);

            return(PyInteger.Create(anded));
        }
Exemplo n.º 18
0
        public static PyInteger __len__(IInterpreter interpreter, FrameContext context, PyObject self)
        {
            var asStr = (PyString)self;

            return(PyInteger.Create(asStr.InternalValue.Length));
        }
Exemplo n.º 19
0
        public static PyInteger __len__(IInterpreter interpreter, FrameContext context, PyObject self)
        {
            var asTuple = (PyTuple)self;

            return(PyInteger.Create(asTuple.Values.Length));
        }
Exemplo n.º 20
0
 public static void __setitem__(PyList self, PyInteger i, PyObject value)
 {
     __setitem__(self, (int)i.InternalValue, value);
 }
Exemplo n.º 21
0
        public static PyInteger __len__(IInterpreter interpreter, FrameContext context, PyObject self)
        {
            var asDict = (PyDict)self;

            return(PyInteger.Create(asDict.InternalDict.Count));
        }
Exemplo n.º 22
0
        public static PyInteger __len__(IInterpreter interpreter, FrameContext context, PyObject self)
        {
            var asList = (PyList)self;

            return(PyInteger.Create(asList.list.Count));
        }
Exemplo n.º 23
0
        public static PyObject __floordiv__(PyObject self, PyObject other)
        {
            var newPyInteger = PyInteger.Create((BigInteger)((decimal)extractInt(self) / PyFloatClass.ExtractAsDecimal(other)));

            return(newPyInteger);
        }