Commit ebdaab07 authored by Travis Hance's avatar Travis Hance Committed by Travis Hance

real and imag member descriptors

parent f1683788
......@@ -222,6 +222,10 @@ void setupComplex() {
complex_cls->giveAttr("__str__", new BoxedFunction(boxRTFunction((void*)complexStr, STR, 1)));
complex_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)complexRepr, STR, 1)));
complex_cls->giveAttr("real",
new BoxedMemberDescriptor(BoxedMemberDescriptor::FLOAT, offsetof(BoxedComplex, real)));
complex_cls->giveAttr("imag",
new BoxedMemberDescriptor(BoxedMemberDescriptor::FLOAT, offsetof(BoxedComplex, imag)));
complex_cls->freeze();
}
......
......@@ -842,6 +842,11 @@ Box* dataDescriptorInstanceSpecialCases(GetattrRewriteArgs* rewrite_args, Box* o
int rtn = reinterpret_cast<int*>(obj)[member_desc->offset / sizeof(int)];
return boxInt(rtn);
}
case BoxedMemberDescriptor::FLOAT: {
rewrite_args = NULL;
double rtn = reinterpret_cast<double*>(obj)[member_desc->offset / sizeof(double)];
return boxFloat(rtn);
}
default:
RELEASE_ASSERT(0, "%d", member_desc->type);
}
......
......@@ -346,6 +346,7 @@ public:
BYTE = T_BYTE,
INT = T_INT,
OBJECT = T_OBJECT,
FLOAT = T_FLOAT,
} type;
int offset;
......
......@@ -12,3 +12,6 @@ print 0.5j - 1.5
print 0.5j * 1.5
print 0.5j * 1.5
print 0.5j * 1.5
print (0.5j + 1.5).real
print (0.5j + 1.5).imag
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