Commit d021017c authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #139 from tjhance/complex2

Complex2
parents 8e952a4e ebdaab07
......@@ -163,6 +163,9 @@ def convert(n, f):
elif isinstance(v, float):
f.write(struct.pack(">d", v))
elif isinstance(v, complex):
# Complex constants can only be pure imaginary
# (e.g., in 1+0j, 1 and 0j are separate literals)
assert v.real == 0.0
f.write(struct.pack(">d", v.imag))
elif v is None or isinstance(v, _ast.AST):
convert(v, f)
......
......@@ -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();
}
......
......@@ -20,11 +20,6 @@
namespace pyston {
extern "C" Box* createPureImaginary(double i);
extern "C" double mod_complex_complex(double lhs, double rhs);
extern "C" double div_complex_complex(double lhs, double rhs);
extern "C" double floordiv_complex_complex(double lhs, double rhs);
extern "C" double pow_complex_complex(double lhs, double rhs);
}
#endif
......@@ -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