Commit f70d316e authored by Travis Hance's avatar Travis Hance

realimag

parent ea1c4746
...@@ -728,6 +728,19 @@ static void _addFuncPow(const char* name, ConcreteCompilerType* rtn_type, void* ...@@ -728,6 +728,19 @@ static void _addFuncPow(const char* name, ConcreteCompilerType* rtn_type, void*
float_cls->giveAttr(name, new BoxedFunction(cl, { None })); float_cls->giveAttr(name, new BoxedFunction(cl, { None }));
} }
static Box* floatFloat(Box* b, void*) {
if (b->cls == float_cls) {
return b;
} else {
assert(PyFloat_Check(b));
return boxFloat(static_cast<BoxedFloat*>(b)->d);
}
}
static Box* float0(Box*, void*) {
return boxFloat(0.0);
}
void setupFloat() { void setupFloat() {
_addFunc("__add__", BOXED_FLOAT, (void*)floatAddFloat, (void*)floatAddInt, (void*)floatAdd); _addFunc("__add__", BOXED_FLOAT, (void*)floatAddFloat, (void*)floatAddInt, (void*)floatAdd);
float_cls->giveAttr("__radd__", float_cls->getattr("__add__")); float_cls->giveAttr("__radd__", float_cls->getattr("__add__"));
...@@ -768,6 +781,9 @@ void setupFloat() { ...@@ -768,6 +781,9 @@ void setupFloat() {
float_cls->giveAttr("__trunc__", new BoxedFunction(boxRTFunction((void*)floatTrunc, BOXED_INT, 1))); float_cls->giveAttr("__trunc__", new BoxedFunction(boxRTFunction((void*)floatTrunc, BOXED_INT, 1)));
float_cls->giveAttr("real", new (pyston_getset_cls) BoxedGetsetDescriptor(floatFloat, NULL, NULL));
float_cls->giveAttr("imag", new (pyston_getset_cls) BoxedGetsetDescriptor(float0, NULL, NULL));
float_cls->freeze(); float_cls->freeze();
} }
......
...@@ -1063,6 +1063,19 @@ static void _addFuncIntUnknown(const char* name, ConcreteCompilerType* rtn_type, ...@@ -1063,6 +1063,19 @@ static void _addFuncIntUnknown(const char* name, ConcreteCompilerType* rtn_type,
int_cls->giveAttr(name, new BoxedFunction(cl)); int_cls->giveAttr(name, new BoxedFunction(cl));
} }
static Box* intInt(Box* b, void*) {
if (b->cls == int_cls) {
return b;
} else {
assert(PyInt_Check(b));
return boxInt(static_cast<BoxedInt*>(b)->n);
}
}
static Box* int0(Box*, void*) {
return boxInt(0);
}
void setupInt() { void setupInt() {
for (int i = 0; i < NUM_INTERNED_INTS; i++) { for (int i = 0; i < NUM_INTERNED_INTS; i++) {
interned_ints[i] = new BoxedInt(i); interned_ints[i] = new BoxedInt(i);
...@@ -1112,6 +1125,9 @@ void setupInt() { ...@@ -1112,6 +1125,9 @@ void setupInt() {
int_cls->giveAttr("__init__", int_cls->giveAttr("__init__",
new BoxedFunction(boxRTFunction((void*)intInit, NONE, 2, 1, true, false), { boxInt(0) })); new BoxedFunction(boxRTFunction((void*)intInit, NONE, 2, 1, true, false), { boxInt(0) }));
int_cls->giveAttr("real", new (pyston_getset_cls) BoxedGetsetDescriptor(intInt, NULL, NULL));
int_cls->giveAttr("imag", new (pyston_getset_cls) BoxedGetsetDescriptor(int0, NULL, NULL));
int_cls->freeze(); int_cls->freeze();
} }
......
...@@ -1296,6 +1296,21 @@ static PyObject* long_pow(PyObject* v, PyObject* w, PyObject* x) noexcept { ...@@ -1296,6 +1296,21 @@ static PyObject* long_pow(PyObject* v, PyObject* w, PyObject* x) noexcept {
} }
} }
static Box* longLong(Box* b, void*) {
if (b->cls == long_cls) {
return b;
} else {
assert(PyLong_Check(b));
BoxedLong* l = new BoxedLong();
mpz_init_set(l->n, static_cast<BoxedLong*>(b)->n);
return l;
}
}
static Box* long0(Box* b, void*) {
return boxLong(0);
}
void setupLong() { void setupLong() {
mp_set_memory_functions(customised_allocation, customised_realloc, customised_free); mp_set_memory_functions(customised_allocation, customised_realloc, customised_free);
...@@ -1356,6 +1371,9 @@ void setupLong() { ...@@ -1356,6 +1371,9 @@ void setupLong() {
long_cls->giveAttr("__trunc__", new BoxedFunction(boxRTFunction((void*)longTrunc, UNKNOWN, 1))); long_cls->giveAttr("__trunc__", new BoxedFunction(boxRTFunction((void*)longTrunc, UNKNOWN, 1)));
long_cls->giveAttr("__index__", new BoxedFunction(boxRTFunction((void*)longIndex, LONG, 1))); long_cls->giveAttr("__index__", new BoxedFunction(boxRTFunction((void*)longIndex, LONG, 1)));
long_cls->giveAttr("real", new (pyston_getset_cls) BoxedGetsetDescriptor(longLong, NULL, NULL));
long_cls->giveAttr("imag", new (pyston_getset_cls) BoxedGetsetDescriptor(long0, NULL, NULL));
long_cls->freeze(); long_cls->freeze();
long_cls->tp_as_number->nb_power = long_pow; long_cls->tp_as_number->nb_power = long_pow;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment