mirror of https://github.com/python/cpython
Use new instancebinop interface
This commit is contained in:
parent
6a00cd8b89
commit
06186519e5
|
@ -68,7 +68,7 @@ static object *add PROTO((object *, object *));
|
||||||
static object *sub PROTO((object *, object *));
|
static object *sub PROTO((object *, object *));
|
||||||
static object *mul PROTO((object *, object *));
|
static object *mul PROTO((object *, object *));
|
||||||
static object *divide PROTO((object *, object *));
|
static object *divide PROTO((object *, object *));
|
||||||
static object *rem PROTO((object *, object *));
|
static object *mod PROTO((object *, object *));
|
||||||
static object *neg PROTO((object *));
|
static object *neg PROTO((object *));
|
||||||
static object *pos PROTO((object *));
|
static object *pos PROTO((object *));
|
||||||
static object *not PROTO((object *));
|
static object *not PROTO((object *));
|
||||||
|
@ -571,7 +571,7 @@ eval_code(co, globals, locals, owner, arg)
|
||||||
case BINARY_MODULO:
|
case BINARY_MODULO:
|
||||||
w = POP();
|
w = POP();
|
||||||
v = POP();
|
v = POP();
|
||||||
x = rem(v, w);
|
x = mod(v, w);
|
||||||
DECREF(v);
|
DECREF(v);
|
||||||
DECREF(w);
|
DECREF(w);
|
||||||
PUSH(x);
|
PUSH(x);
|
||||||
|
@ -1742,18 +1742,18 @@ flushline()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define BINOP(opname, ropname) \
|
#define BINOP(opname, ropname, thisfunc) \
|
||||||
do { \
|
if (!is_instanceobject(v) && !is_instanceobject(w)) \
|
||||||
if (is_instanceobject(v) || is_instanceobject(w)) \
|
; \
|
||||||
return instancebinop(v, w, opname, ropname); \
|
else \
|
||||||
} while (0)
|
return instancebinop(v, w, opname, ropname, thisfunc)
|
||||||
|
|
||||||
|
|
||||||
static object *
|
static object *
|
||||||
or(v, w)
|
or(v, w)
|
||||||
object *v, *w;
|
object *v, *w;
|
||||||
{
|
{
|
||||||
BINOP("__or__", "__ror__");
|
BINOP("__or__", "__ror__", or);
|
||||||
if (v->ob_type->tp_as_number != NULL) {
|
if (v->ob_type->tp_as_number != NULL) {
|
||||||
object *x;
|
object *x;
|
||||||
object * (*f) FPROTO((object *, object *));
|
object * (*f) FPROTO((object *, object *));
|
||||||
|
@ -1774,7 +1774,7 @@ static object *
|
||||||
xor(v, w)
|
xor(v, w)
|
||||||
object *v, *w;
|
object *v, *w;
|
||||||
{
|
{
|
||||||
BINOP("__xor__", "__rxor__");
|
BINOP("__xor__", "__rxor__", xor);
|
||||||
if (v->ob_type->tp_as_number != NULL) {
|
if (v->ob_type->tp_as_number != NULL) {
|
||||||
object *x;
|
object *x;
|
||||||
object * (*f) FPROTO((object *, object *));
|
object * (*f) FPROTO((object *, object *));
|
||||||
|
@ -1795,7 +1795,7 @@ static object *
|
||||||
and(v, w)
|
and(v, w)
|
||||||
object *v, *w;
|
object *v, *w;
|
||||||
{
|
{
|
||||||
BINOP("__and__", "__rand__");
|
BINOP("__and__", "__rand__", and);
|
||||||
if (v->ob_type->tp_as_number != NULL) {
|
if (v->ob_type->tp_as_number != NULL) {
|
||||||
object *x;
|
object *x;
|
||||||
object * (*f) FPROTO((object *, object *));
|
object * (*f) FPROTO((object *, object *));
|
||||||
|
@ -1816,7 +1816,7 @@ static object *
|
||||||
lshift(v, w)
|
lshift(v, w)
|
||||||
object *v, *w;
|
object *v, *w;
|
||||||
{
|
{
|
||||||
BINOP("__lshift__", "__rlshift__");
|
BINOP("__lshift__", "__rlshift__", lshift);
|
||||||
if (v->ob_type->tp_as_number != NULL) {
|
if (v->ob_type->tp_as_number != NULL) {
|
||||||
object *x;
|
object *x;
|
||||||
object * (*f) FPROTO((object *, object *));
|
object * (*f) FPROTO((object *, object *));
|
||||||
|
@ -1837,7 +1837,7 @@ static object *
|
||||||
rshift(v, w)
|
rshift(v, w)
|
||||||
object *v, *w;
|
object *v, *w;
|
||||||
{
|
{
|
||||||
BINOP("__rshift__", "__rrshift__");
|
BINOP("__rshift__", "__rrshift__", rshift);
|
||||||
if (v->ob_type->tp_as_number != NULL) {
|
if (v->ob_type->tp_as_number != NULL) {
|
||||||
object *x;
|
object *x;
|
||||||
object * (*f) FPROTO((object *, object *));
|
object * (*f) FPROTO((object *, object *));
|
||||||
|
@ -1858,7 +1858,7 @@ static object *
|
||||||
add(v, w)
|
add(v, w)
|
||||||
object *v, *w;
|
object *v, *w;
|
||||||
{
|
{
|
||||||
BINOP("__add__", "__radd__");
|
BINOP("__add__", "__radd__", add);
|
||||||
if (v->ob_type->tp_as_sequence != NULL)
|
if (v->ob_type->tp_as_sequence != NULL)
|
||||||
return (*v->ob_type->tp_as_sequence->sq_concat)(v, w);
|
return (*v->ob_type->tp_as_sequence->sq_concat)(v, w);
|
||||||
else if (v->ob_type->tp_as_number != NULL) {
|
else if (v->ob_type->tp_as_number != NULL) {
|
||||||
|
@ -1878,7 +1878,7 @@ static object *
|
||||||
sub(v, w)
|
sub(v, w)
|
||||||
object *v, *w;
|
object *v, *w;
|
||||||
{
|
{
|
||||||
BINOP("__sub__", "__rsub__");
|
BINOP("__sub__", "__rsub__", sub);
|
||||||
if (v->ob_type->tp_as_number != NULL) {
|
if (v->ob_type->tp_as_number != NULL) {
|
||||||
object *x;
|
object *x;
|
||||||
if (coerce(&v, &w) != 0)
|
if (coerce(&v, &w) != 0)
|
||||||
|
@ -1898,7 +1898,7 @@ mul(v, w)
|
||||||
{
|
{
|
||||||
typeobject *tp;
|
typeobject *tp;
|
||||||
tp = v->ob_type;
|
tp = v->ob_type;
|
||||||
BINOP("__mul__", "__rmul__");
|
BINOP("__mul__", "__rmul__", mul);
|
||||||
if (tp->tp_as_number != NULL &&
|
if (tp->tp_as_number != NULL &&
|
||||||
w->ob_type->tp_as_sequence != NULL &&
|
w->ob_type->tp_as_sequence != NULL &&
|
||||||
!is_instanceobject(v)) {
|
!is_instanceobject(v)) {
|
||||||
|
@ -1942,7 +1942,7 @@ static object *
|
||||||
divide(v, w)
|
divide(v, w)
|
||||||
object *v, *w;
|
object *v, *w;
|
||||||
{
|
{
|
||||||
BINOP("__div__", "__rdiv__");
|
BINOP("__div__", "__rdiv__", divide);
|
||||||
if (v->ob_type->tp_as_number != NULL) {
|
if (v->ob_type->tp_as_number != NULL) {
|
||||||
object *x;
|
object *x;
|
||||||
if (coerce(&v, &w) != 0)
|
if (coerce(&v, &w) != 0)
|
||||||
|
@ -1957,13 +1957,13 @@ divide(v, w)
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static object *
|
||||||
rem(v, w)
|
mod(v, w)
|
||||||
object *v, *w;
|
object *v, *w;
|
||||||
{
|
{
|
||||||
if (is_stringobject(v)) {
|
if (is_stringobject(v)) {
|
||||||
return formatstring(v, w);
|
return formatstring(v, w);
|
||||||
}
|
}
|
||||||
BINOP("__mod__", "__rmod__");
|
BINOP("__mod__", "__rmod__", mod);
|
||||||
if (v->ob_type->tp_as_number != NULL) {
|
if (v->ob_type->tp_as_number != NULL) {
|
||||||
object *x;
|
object *x;
|
||||||
if (coerce(&v, &w) != 0)
|
if (coerce(&v, &w) != 0)
|
||||||
|
|
Loading…
Reference in New Issue