Commit 8095521e authored by Dong-hee,Na's avatar Dong-hee,Na

implement recursive printing of set and tuples.

w:
parent eb8e5c4d
......@@ -99,6 +99,14 @@ static Box* _setRepr(BoxedSet* self, const char* type_name) {
std::string O("");
llvm::raw_string_ostream os(O);
int status = Py_ReprEnter((PyObject*)self);
if (status != 0) {
if (status < 0)
return boxString(os.str());
os << type_name << "(...)";
return boxString(os.str());
}
os << type_name << "([";
bool first = true;
for (Box* elt : self->s) {
......@@ -109,6 +117,7 @@ static Box* _setRepr(BoxedSet* self, const char* type_name) {
first = false;
}
os << "])";
Py_ReprLeave((PyObject*)self);
return boxString(os.str());
}
......
......@@ -203,11 +203,27 @@ extern "C" Py_ssize_t PyTuple_Size(PyObject* op) noexcept {
Box* tupleRepr(BoxedTuple* t) {
assert(isSubclass(t->cls, tuple_cls));
int n;
std::string O("");
llvm::raw_string_ostream os(O);
n = t->size();
if (n == 0) {
os << "()";
return boxString(os.str());
}
int status = Py_ReprEnter((PyObject*)t);
if (status != 0) {
if (status < 0)
return boxString(os.str());
os << "(...)";
return boxString(os.str());
}
os << "(";
int n = t->size();
for (int i = 0; i < n; i++) {
if (i)
os << ", ";
......@@ -219,6 +235,7 @@ Box* tupleRepr(BoxedTuple* t) {
os << ",";
os << ")";
Py_ReprLeave((PyObject*)t);
return boxString(os.str());
}
......
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