Commit 4fc24442 authored by Dong-hee,Na's avatar Dong-hee,Na

some changing about exception handling and remove blank line

parent 2196761b
...@@ -31,57 +31,48 @@ using namespace pyston::ExceptionStyle; ...@@ -31,57 +31,48 @@ using namespace pyston::ExceptionStyle;
using pyston::ExceptionStyle::ExceptionStyle; using pyston::ExceptionStyle::ExceptionStyle;
Box* dictRepr(BoxedDict* self) { Box* dictRepr(BoxedDict* self) {
try {
std::vector<char> chars; std::vector<char> chars;
int status = Py_ReprEnter((PyObject*)self); int status = Py_ReprEnter((PyObject*)self);
if (status != 0) { if (status != 0) {
try {
if (status < 0) if (status < 0)
throwCAPIException(); throwCAPIException();
} catch (ExcInfo e) {
Py_ReprLeave((PyObject*)self);
throw e;
}
chars.push_back('{'); chars.push_back('{');
chars.push_back('.'); chars.push_back('.');
chars.push_back('.'); chars.push_back('.');
chars.push_back('.'); chars.push_back('.');
chars.push_back('}'); chars.push_back('}');
return boxString(llvm::StringRef(&chars[0], chars.size())); 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) {
if (!first) { if (!first) {
chars.push_back(','); chars.push_back(',');
chars.push_back(' '); chars.push_back(' ');
} }
first = false; first = false;
try {
BoxedString* k = static_cast<BoxedString*>(repr(p.first)); BoxedString* k = static_cast<BoxedString*>(repr(p.first));
BoxedString* v = static_cast<BoxedString*>(repr(p.second)); BoxedString* v = static_cast<BoxedString*>(repr(p.second));
chars.insert(chars.end(), k->s().begin(), k->s().end()); chars.insert(chars.end(), k->s().begin(), k->s().end());
chars.push_back(':'); chars.push_back(':');
chars.push_back(' '); chars.push_back(' ');
chars.insert(chars.end(), v->s().begin(), v->s().end()); chars.insert(chars.end(), v->s().begin(), v->s().end());
}
chars.push_back('}');
Py_ReprLeave((PyObject*)self);
return boxString(llvm::StringRef(&chars[0], chars.size()));
} catch (ExcInfo e) { } catch (ExcInfo e) {
Py_ReprLeave((PyObject*)self); Py_ReprLeave((PyObject*)self);
throw e; throw e;
} }
}
chars.push_back('}');
Py_ReprLeave((PyObject*)self);
return boxString(llvm::StringRef(&chars[0], chars.size()));
} }
Box* dictClear(BoxedDict* self) { Box* dictClear(BoxedDict* self) {
......
...@@ -61,26 +61,24 @@ extern "C" PyObject* PyList_AsTuple(PyObject* v) noexcept { ...@@ -61,26 +61,24 @@ extern "C" PyObject* PyList_AsTuple(PyObject* v) noexcept {
} }
extern "C" Box* listRepr(BoxedList* self) { extern "C" Box* listRepr(BoxedList* self) {
try {
std::vector<char> chars; std::vector<char> chars;
int status = Py_ReprEnter((PyObject*)self); int status = Py_ReprEnter((PyObject*)self);
if (status != 0) { if (status != 0) {
try {
if (status < 0) if (status < 0)
throwCAPIException(); throwCAPIException();
} catch (ExcInfo e) {
Py_ReprLeave((PyObject*)self);
throw e;
}
chars.push_back('['); chars.push_back('[');
chars.push_back('.'); chars.push_back('.');
chars.push_back('.'); chars.push_back('.');
chars.push_back('.'); chars.push_back('.');
chars.push_back(']'); chars.push_back(']');
return boxString(llvm::StringRef(&chars[0], chars.size())); return boxString(llvm::StringRef(&chars[0], chars.size()));
} }
chars.push_back('['); chars.push_back('[');
for (int i = 0; i < self->size; i++) { for (int i = 0; i < self->size; i++) {
...@@ -89,23 +87,15 @@ extern "C" Box* listRepr(BoxedList* self) { ...@@ -89,23 +87,15 @@ extern "C" Box* listRepr(BoxedList* self) {
chars.push_back(','); chars.push_back(',');
chars.push_back(' '); chars.push_back(' ');
} }
Box* r = self->elts->elts[i]->reprICAsString(); Box* r = self->elts->elts[i]->reprICAsString();
assert(r->cls == str_cls); assert(r->cls == str_cls);
BoxedString* s = static_cast<BoxedString*>(r); BoxedString* s = static_cast<BoxedString*>(r);
chars.insert(chars.end(), s->s().begin(), s->s().end()); chars.insert(chars.end(), s->s().begin(), s->s().end());
} }
chars.push_back(']'); chars.push_back(']');
Py_ReprLeave((PyObject*)self); Py_ReprLeave((PyObject*)self);
return boxString(llvm::StringRef(&chars[0], chars.size())); return boxString(llvm::StringRef(&chars[0], chars.size()));
} catch (ExcInfo e) {
Py_ReprLeave((PyObject*)self);
throw e;
}
} }
extern "C" Box* listNonzero(BoxedList* self) { extern "C" Box* listNonzero(BoxedList* self) {
......
...@@ -95,19 +95,20 @@ Box* setNew(Box* _cls, Box* container) { ...@@ -95,19 +95,20 @@ Box* setNew(Box* _cls, Box* container) {
static Box* _setRepr(BoxedSet* self, const char* type_name) { static Box* _setRepr(BoxedSet* self, const char* type_name) {
try {
std::vector<char> chars; std::vector<char> chars;
int status = Py_ReprEnter((PyObject*)self); int status = Py_ReprEnter((PyObject*)self);
if (status != 0) { if (status != 0) {
try {
if (status < 0) if (status < 0)
throwCAPIException(); throwCAPIException();
} catch (ExcInfo e) {
Py_ReprLeave((PyObject*)self);
throw e;
}
std::string ty = std::string(type_name); std::string ty = std::string(type_name);
chars.insert(chars.end(), ty.begin(), ty.end()); chars.insert(chars.end(), ty.begin(), ty.end());
chars.push_back('('); chars.push_back('(');
chars.push_back('.'); chars.push_back('.');
chars.push_back('.'); chars.push_back('.');
...@@ -130,20 +131,20 @@ static Box* _setRepr(BoxedSet* self, const char* type_name) { ...@@ -130,20 +131,20 @@ static Box* _setRepr(BoxedSet* self, const char* type_name) {
chars.push_back(','); chars.push_back(',');
chars.push_back(' '); chars.push_back(' ');
} }
try {
BoxedString* str = static_cast<BoxedString*>(repr(elt)); BoxedString* str = static_cast<BoxedString*>(repr(elt));
chars.insert(chars.end(), str->s().begin(), str->s().end()); chars.insert(chars.end(), str->s().begin(), str->s().end());
} catch (ExcInfo e) {
Py_ReprLeave((PyObject*)self);
throw e;
}
first = false; first = false;
} }
chars.push_back(']'); chars.push_back(']');
chars.push_back(')'); chars.push_back(')');
Py_ReprLeave((PyObject*)self); Py_ReprLeave((PyObject*)self);
return boxString(llvm::StringRef(&chars[0], chars.size())); return boxString(llvm::StringRef(&chars[0], chars.size()));
} catch (ExcInfo e) {
Py_ReprLeave((PyObject*)self);
throw e;
}
} }
Box* setRepr(BoxedSet* self) { Box* setRepr(BoxedSet* self) {
......
...@@ -199,14 +199,11 @@ extern "C" Py_ssize_t PyTuple_Size(PyObject* op) noexcept { ...@@ -199,14 +199,11 @@ extern "C" Py_ssize_t PyTuple_Size(PyObject* op) noexcept {
} }
Box* tupleRepr(BoxedTuple* t) { Box* tupleRepr(BoxedTuple* t) {
assert(isSubclass(t->cls, tuple_cls));
try {
assert(isSubclass(t->cls, tuple_cls));
int n; int n;
std::vector<char> chars; std::vector<char> chars;
int status = Py_ReprEnter((PyObject*)t); int status = Py_ReprEnter((PyObject*)t);
n = t->size(); n = t->size();
if (n == 0) { if (n == 0) {
chars.push_back('('); chars.push_back('(');
...@@ -215,9 +212,13 @@ Box* tupleRepr(BoxedTuple* t) { ...@@ -215,9 +212,13 @@ Box* tupleRepr(BoxedTuple* t) {
} }
if (status != 0) { if (status != 0) {
try {
if (status < 0) if (status < 0)
throwCAPIException(); throwCAPIException();
} catch (ExcInfo e) {
Py_ReprLeave((PyObject*)t);
throw e;
}
chars.push_back('('); chars.push_back('(');
chars.push_back('.'); chars.push_back('.');
chars.push_back('.'); chars.push_back('.');
...@@ -226,8 +227,6 @@ Box* tupleRepr(BoxedTuple* t) { ...@@ -226,8 +227,6 @@ Box* tupleRepr(BoxedTuple* t) {
return boxString(llvm::StringRef(&chars[0], chars.size())); return boxString(llvm::StringRef(&chars[0], chars.size()));
} }
chars.push_back('('); chars.push_back('(');
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
...@@ -235,8 +234,13 @@ Box* tupleRepr(BoxedTuple* t) { ...@@ -235,8 +234,13 @@ Box* tupleRepr(BoxedTuple* t) {
chars.push_back(','); chars.push_back(',');
chars.push_back(' '); chars.push_back(' ');
} }
try {
BoxedString* elt_repr = static_cast<BoxedString*>(repr(t->elts[i])); BoxedString* elt_repr = static_cast<BoxedString*>(repr(t->elts[i]));
chars.insert(chars.end(), elt_repr->s().begin(), elt_repr->s().end()); chars.insert(chars.end(), elt_repr->s().begin(), elt_repr->s().end());
} catch (ExcInfo e) {
Py_ReprLeave((PyObject*)t);
throw e;
}
} }
if (n == 1) if (n == 1)
...@@ -246,11 +250,6 @@ Box* tupleRepr(BoxedTuple* t) { ...@@ -246,11 +250,6 @@ Box* tupleRepr(BoxedTuple* t) {
Py_ReprLeave((PyObject*)t); Py_ReprLeave((PyObject*)t);
return boxString(llvm::StringRef(&chars[0], chars.size())); return boxString(llvm::StringRef(&chars[0], chars.size()));
} catch (ExcInfo e) {
Py_ReprLeave((PyObject*)t);
throw e;
}
} }
Box* tupleNonzero(BoxedTuple* self) { Box* tupleNonzero(BoxedTuple* self) {
......
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