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) {
std::vector<char> chars;
try { int status = Py_ReprEnter((PyObject*)self);
if (status != 0) {
std::vector<char> chars; try {
int status = Py_ReprEnter((PyObject*)self);
if (status != 0) {
if (status < 0) if (status < 0)
throwCAPIException(); throwCAPIException();
} catch (ExcInfo e) {
chars.push_back('{'); Py_ReprLeave((PyObject*)self);
chars.push_back('.'); throw e;
chars.push_back('.');
chars.push_back('.');
chars.push_back('}');
return boxString(llvm::StringRef(&chars[0], chars.size()));
} }
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()));
}
bool first = true; chars.push_back('{');
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;
try {
first = false;
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());
} catch (ExcInfo e) {
Py_ReprLeave((PyObject*)self);
throw e;
} }
chars.push_back('}');
Py_ReprLeave((PyObject*)self);
return boxString(llvm::StringRef(&chars[0], chars.size()));
} catch (ExcInfo e) {
Py_ReprLeave((PyObject*)self);
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,51 +61,41 @@ extern "C" PyObject* PyList_AsTuple(PyObject* v) noexcept { ...@@ -61,51 +61,41 @@ extern "C" PyObject* PyList_AsTuple(PyObject* v) noexcept {
} }
extern "C" Box* listRepr(BoxedList* self) { extern "C" Box* listRepr(BoxedList* self) {
std::vector<char> chars;
int status = Py_ReprEnter((PyObject*)self);
try { if (status != 0) {
try {
std::vector<char> chars;
int status = Py_ReprEnter((PyObject*)self);
if (status != 0) {
if (status < 0) if (status < 0)
throwCAPIException(); throwCAPIException();
} catch (ExcInfo e) {
chars.push_back('['); Py_ReprLeave((PyObject*)self);
chars.push_back('.'); throw e;
chars.push_back('.');
chars.push_back('.');
chars.push_back(']');
return boxString(llvm::StringRef(&chars[0], chars.size()));
} }
chars.push_back('['); chars.push_back('[');
chars.push_back('.');
for (int i = 0; i < self->size; i++) { chars.push_back('.');
chars.push_back('.');
if (i > 0) {
chars.push_back(',');
chars.push_back(' ');
}
Box* r = self->elts->elts[i]->reprICAsString();
assert(r->cls == str_cls);
BoxedString* s = static_cast<BoxedString*>(r);
chars.insert(chars.end(), s->s().begin(), s->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()));
}
chars.push_back('[');
} catch (ExcInfo e) { for (int i = 0; i < self->size; i++) {
Py_ReprLeave((PyObject*)self);
throw e; if (i > 0) {
chars.push_back(',');
chars.push_back(' ');
}
Box* r = self->elts->elts[i]->reprICAsString();
assert(r->cls == str_cls);
BoxedString* s = static_cast<BoxedString*>(r);
chars.insert(chars.end(), s->s().begin(), s->s().end());
} }
chars.push_back(']');
Py_ReprLeave((PyObject*)self);
return boxString(llvm::StringRef(&chars[0], chars.size()));
} }
extern "C" Box* listNonzero(BoxedList* self) { extern "C" Box* listNonzero(BoxedList* self) {
......
...@@ -95,55 +95,56 @@ Box* setNew(Box* _cls, Box* container) { ...@@ -95,55 +95,56 @@ 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;
int status = Py_ReprEnter((PyObject*)self);
std::vector<char> chars;
int status = Py_ReprEnter((PyObject*)self);
if (status != 0) {
if (status != 0) {
try {
if (status < 0) if (status < 0)
throwCAPIException(); throwCAPIException();
} catch (ExcInfo e) {
std::string ty = std::string(type_name); Py_ReprLeave((PyObject*)self);
chars.insert(chars.end(), ty.begin(), ty.end()); throw e;
chars.push_back('(');
chars.push_back('.');
chars.push_back('.');
chars.push_back('.');
chars.push_back(')');
return boxString(llvm::StringRef(&chars[0], chars.size()));
} }
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('.');
chars.push_back(')');
bool first = true; return boxString(llvm::StringRef(&chars[0], chars.size()));
for (Box* elt : self->s) { }
if (!first) { std::string ty = std::string(type_name);
chars.push_back(','); chars.insert(chars.end(), ty.begin(), ty.end());
chars.push_back(' ');
} chars.push_back('(');
chars.push_back('[');
bool first = true;
for (Box* elt : self->s) {
if (!first) {
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());
first = false; } catch (ExcInfo e) {
Py_ReprLeave((PyObject*)self);
throw e;
} }
chars.push_back(']');
chars.push_back(')');
Py_ReprLeave((PyObject*)self);
return boxString(llvm::StringRef(&chars[0], chars.size()));
} catch (ExcInfo e) { first = false;
Py_ReprLeave((PyObject*)self);
throw e;
} }
chars.push_back(']');
chars.push_back(')');
Py_ReprLeave((PyObject*)self);
return boxString(llvm::StringRef(&chars[0], chars.size()));
} }
Box* setRepr(BoxedSet* self) { Box* setRepr(BoxedSet* self) {
......
...@@ -199,58 +199,57 @@ extern "C" Py_ssize_t PyTuple_Size(PyObject* op) noexcept { ...@@ -199,58 +199,57 @@ 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 {
int n;
std::vector<char> chars;
int status = Py_ReprEnter((PyObject*)t);
n = t->size(); assert(isSubclass(t->cls, tuple_cls));
if (n == 0) { int n;
chars.push_back('('); std::vector<char> chars;
chars.push_back(')'); int status = Py_ReprEnter((PyObject*)t);
return boxString(llvm::StringRef(&chars[0], chars.size())); n = t->size();
} if (n == 0) {
chars.push_back('(');
chars.push_back(')');
return boxString(llvm::StringRef(&chars[0], chars.size()));
}
if (status != 0) { if (status != 0) {
try {
if (status < 0) if (status < 0)
throwCAPIException(); throwCAPIException();
} catch (ExcInfo e) {
chars.push_back('('); Py_ReprLeave((PyObject*)t);
chars.push_back('.'); throw e;
chars.push_back('.');
chars.push_back('.');
chars.push_back(')');
return boxString(llvm::StringRef(&chars[0], chars.size()));
} }
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()));
}
chars.push_back('(');
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
if (i) { if (i) {
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)
chars.push_back(','); chars.push_back(',');
chars.push_back(')');
Py_ReprLeave((PyObject*)t);
return boxString(llvm::StringRef(&chars[0], chars.size())); chars.push_back(')');
Py_ReprLeave((PyObject*)t);
} catch (ExcInfo e) { return boxString(llvm::StringRef(&chars[0], chars.size()));
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