Commit fb8f9e05 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #53 from lameiro/master

Uses module name when generating IR, for improved readability.
parents 666eadb0 e157d33f
...@@ -52,7 +52,7 @@ const std::string SourceInfo::getName() { ...@@ -52,7 +52,7 @@ const std::string SourceInfo::getName() {
case AST_TYPE::FunctionDef: case AST_TYPE::FunctionDef:
return ast_cast<AST_FunctionDef>(ast)->name; return ast_cast<AST_FunctionDef>(ast)->name;
case AST_TYPE::Module: case AST_TYPE::Module:
return "module"; return this->parent_module->name();
default: default:
RELEASE_ASSERT(0, "%d", ast->type); RELEASE_ASSERT(0, "%d", ast->type);
} }
......
...@@ -52,6 +52,16 @@ BoxedModule::BoxedModule(const std::string &name, const std::string &fn) : HCBox ...@@ -52,6 +52,16 @@ BoxedModule::BoxedModule(const std::string &name, const std::string &fn) : HCBox
this->giveAttr("__file__", boxString(fn)); this->giveAttr("__file__", boxString(fn));
} }
std::string BoxedModule::name(){
Box* name = this->peekattr("__name__");
if (!name || name->cls != str_cls) {
return "?";
} else {
BoxedString *sname = static_cast<BoxedString*>(name);
return sname->s;
}
}
extern "C" Box* boxCLFunction(CLFunction *f) { extern "C" Box* boxCLFunction(CLFunction *f) {
return new BoxedFunction(f); return new BoxedFunction(f);
} }
...@@ -317,20 +327,12 @@ Box* moduleRepr(BoxedModule* m) { ...@@ -317,20 +327,12 @@ Box* moduleRepr(BoxedModule* m) {
assert(m->cls == module_cls); assert(m->cls == module_cls);
std::ostringstream os; std::ostringstream os;
os << "<module '"; os << "<module '" << m->name() << "' ";
Box* name = m->peekattr("__name__");
if (!name || name->cls != str_cls) {
os << '?';
} else {
BoxedString *sname = static_cast<BoxedString*>(name);
os << sname->s;
}
if (m->fn == "__builtin__") { if (m->fn == "__builtin__") {
os << "' (built-in)>"; os << "(built-in)>";
} else { } else {
os << "' from '" << m->fn << "'>"; os << "from '" << m->fn << "'>";
} }
return boxString(os.str()); return boxString(os.str());
} }
......
...@@ -256,6 +256,7 @@ class BoxedModule : public HCBox { ...@@ -256,6 +256,7 @@ class BoxedModule : public HCBox {
const std::string fn; // for traceback purposes; not the same as __file__ const std::string fn; // for traceback purposes; not the same as __file__
BoxedModule(const std::string &name, const std::string &fn); BoxedModule(const std::string &name, const std::string &fn);
std::string name();
}; };
class BoxedSlice : public HCBox { class BoxedSlice : public HCBox {
......
import empty_module
import math
x = repr(empty_module)
# cpython will simplify the path (remove . and ..), and use the pyc file in the repr string. Pyston still doesn't support that, so we are only checking the non-path part.
print x[0:29]
print x[-2:]
print repr(math) # no path for built-ins, so we can just check as normal
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