Commit 79b6133a authored by Dong-hee,Na's avatar Dong-hee,Na

implementation of dictionary's recursive printing

parent ded39f2a
...@@ -31,7 +31,22 @@ using namespace pyston::ExceptionStyle; ...@@ -31,7 +31,22 @@ using namespace pyston::ExceptionStyle;
using pyston::ExceptionStyle::ExceptionStyle; using pyston::ExceptionStyle::ExceptionStyle;
Box* dictRepr(BoxedDict* self) { Box* dictRepr(BoxedDict* self) {
int status = Py_ReprEnter((PyObject*)self);
std::vector<char> chars; std::vector<char> chars;
if(status != 0)
{
if(status < 0)
return boxString(llvm::StringRef(&chars[0], chars.size()));
chars.push_back('{');
chars.push_back('.');
chars.push_back('.');
chars.push_back('.');
chars.push_back('}');
return boxString(llvm::StringRef(&chars[0], chars.size()));
}
chars.push_back('{'); chars.push_back('{');
bool first = true; bool first = true;
for (const auto& p : self->d) { for (const auto& p : self->d) {
...@@ -49,6 +64,7 @@ Box* dictRepr(BoxedDict* self) { ...@@ -49,6 +64,7 @@ Box* dictRepr(BoxedDict* self) {
chars.insert(chars.end(), v->s().begin(), v->s().end()); chars.insert(chars.end(), v->s().begin(), v->s().end());
} }
chars.push_back('}'); chars.push_back('}');
Py_ReprLeave((PyObject*)self);
return boxString(llvm::StringRef(&chars[0], chars.size())); return boxString(llvm::StringRef(&chars[0], chars.size()));
} }
......
...@@ -230,3 +230,9 @@ while True: ...@@ -230,3 +230,9 @@ while True:
except StopIteration: except StopIteration:
break break
print sorted(l) print sorted(l)
#recursive printing test
d = dict()
d['one'] = '1'
d['two'] = d
print d
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