summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1991-10-24 14:59:31 (GMT)
committerGuido van Rossum <guido@python.org>1991-10-24 14:59:31 (GMT)
commit7928cd7636060c09da613d6f226a54903b86740a (patch)
treea098fc51fb6d3beb0efc3a7905c762190443b183 /Python/ceval.c
parent7a6dfa7d79597f29866033ecf648457fe7572a8f (diff)
downloadcpython-7928cd7636060c09da613d6f226a54903b86740a.zip
cpython-7928cd7636060c09da613d6f226a54903b86740a.tar.gz
cpython-7928cd7636060c09da613d6f226a54903b86740a.tar.bz2
Added shift and mask ops.
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c170
1 files changed, 170 insertions, 0 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 76869ff..7399623 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -51,6 +51,12 @@ static object *rem();
static object *neg();
static object *pos();
static object *not();
+static object *invert();
+static object *lshift();
+static object *rshift();
+static object *and();
+static object *xor();
+static object *or();
static object *call_builtin();
static object *call_function();
static object *apply_subscript();
@@ -273,6 +279,13 @@ eval_code(co, globals, locals, arg)
DECREF(v);
PUSH(x);
break;
+
+ case UNARY_INVERT:
+ v = POP();
+ x = invert(v);
+ DECREF(v);
+ PUSH(x);
+ break;
case BINARY_MULTIPLY:
w = POP();
@@ -340,6 +353,51 @@ eval_code(co, globals, locals, arg)
PUSH(x);
break;
+ case BINARY_LSHIFT:
+ w = POP();
+ v = POP();
+ x = lshift(v, w);
+ DECREF(v);
+ DECREF(w);
+ PUSH(x);
+ break;
+
+ case BINARY_RSHIFT:
+ w = POP();
+ v = POP();
+ x = rshift(v, w);
+ DECREF(v);
+ DECREF(w);
+ PUSH(x);
+ break;
+
+ case BINARY_AND:
+ w = POP();
+ v = POP();
+ x = and(v, w);
+ DECREF(v);
+ DECREF(w);
+ PUSH(x);
+ break;
+
+ case BINARY_XOR:
+ w = POP();
+ v = POP();
+ x = xor(v, w);
+ DECREF(v);
+ DECREF(w);
+ PUSH(x);
+ break;
+
+ case BINARY_OR:
+ w = POP();
+ v = POP();
+ x = or(v, w);
+ DECREF(v);
+ DECREF(w);
+ PUSH(x);
+ break;
+
case SLICE+0:
case SLICE+1:
case SLICE+2:
@@ -1002,6 +1060,106 @@ testbool(v)
}
static object *
+or(v, w)
+ object *v, *w;
+{
+ if (v->ob_type->tp_as_number != NULL) {
+ object *x;
+ object * (*f) FPROTO((object *, object *));
+ if (coerce(&v, &w) != 0)
+ return NULL;
+ if ((f = v->ob_type->tp_as_number->nb_or) != NULL)
+ x = (*f)(v, w);
+ DECREF(v);
+ DECREF(w);
+ if (f != NULL)
+ return x;
+ }
+ err_setstr(TypeError, "bad operand type(s) for |");
+ return NULL;
+}
+
+static object *
+xor(v, w)
+ object *v, *w;
+{
+ if (v->ob_type->tp_as_number != NULL) {
+ object *x;
+ object * (*f) FPROTO((object *, object *));
+ if (coerce(&v, &w) != 0)
+ return NULL;
+ if ((f = v->ob_type->tp_as_number->nb_xor) != NULL)
+ x = (*f)(v, w);
+ DECREF(v);
+ DECREF(w);
+ if (f != NULL)
+ return x;
+ }
+ err_setstr(TypeError, "bad operand type(s) for ^");
+ return NULL;
+}
+
+static object *
+and(v, w)
+ object *v, *w;
+{
+ if (v->ob_type->tp_as_number != NULL) {
+ object *x;
+ object * (*f) FPROTO((object *, object *));
+ if (coerce(&v, &w) != 0)
+ return NULL;
+ if ((f = v->ob_type->tp_as_number->nb_and) != NULL)
+ x = (*f)(v, w);
+ DECREF(v);
+ DECREF(w);
+ if (f != NULL)
+ return x;
+ }
+ err_setstr(TypeError, "bad operand type(s) for &");
+ return NULL;
+}
+
+static object *
+lshift(v, w)
+ object *v, *w;
+{
+ if (v->ob_type->tp_as_number != NULL) {
+ object *x;
+ object * (*f) FPROTO((object *, object *));
+ if (coerce(&v, &w) != 0)
+ return NULL;
+ if ((f = v->ob_type->tp_as_number->nb_lshift) != NULL)
+ x = (*f)(v, w);
+ DECREF(v);
+ DECREF(w);
+ if (f != NULL)
+ return x;
+ }
+ err_setstr(TypeError, "bad operand type(s) for <<");
+ return NULL;
+}
+
+static object *
+rshift(v, w)
+ object *v, *w;
+{
+ if (v->ob_type->tp_as_number != NULL) {
+ object *x;
+ object * (*f) FPROTO((object *, object *));
+ if (coerce(&v, &w) != 0)
+ return NULL;
+ if ((f = v->ob_type->tp_as_number->nb_rshift) != NULL)
+ x = (*f)(v, w);
+ DECREF(v);
+ DECREF(w);
+ if (f != NULL)
+ return x;
+ }
+ err_setstr(TypeError, "bad operand type(s) for >>");
+ return NULL;
+}
+
+static object *
add(v, w)
object *v, *w;
{
@@ -1128,6 +1286,18 @@ pos(v)
}
static object *
+invert(v)
+ object *v;
+{
+ object * (*f) FPROTO((object *, object *));
+ if (v->ob_type->tp_as_number != NULL &&
+ (f = v->ob_type->tp_as_number->nb_invert) != NULL)
+ return (*f)(v);
+ err_setstr(TypeError, "bad operand type(s) for unary ~");
+ return NULL;
+}
+
+static object *
not(v)
object *v;
{