Commit e6cbc8ae authored by Kevin Modzelewski's avatar Kevin Modzelewski

Basic docstring support

Pretty similar to #78
parent 38fa581e
......@@ -337,11 +337,15 @@ cpplint:
.PHONY: check quick_check
check:
@# These are ordered roughly in decreasing order of (chance will expose issue) / (time to run test)
$(MAKE) lint
$(MAKE) ext pyston_dbg
# $(MAKE) run_unittests
$(MAKE) check_dbg
$(MAKE) check_release
$(MAKE) check_format
$(MAKE) run_unittests
@# jit_prof forces the use of GCC as the compiler, which can expose other errors, so just build it and see what happens:
# $(MAKE) check_prof
$(MAKE) pyston_prof
......@@ -349,9 +353,7 @@ check:
$(call checksha,./pyston_prof -cqn $(TESTS_DIR)/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d)
$(call checksha,./pyston_prof -cqO $(TESTS_DIR)/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d)
$(MAKE) run_unittests
$(MAKE) check_format
$(MAKE) check_release
echo "All tests passed"
quick_check:
......
......@@ -1404,10 +1404,29 @@ private:
// cls->setattr(emitter, "__name__", name);
// name->decvref(emitter);
bool had_docstring = false;
static std::string doc_str("__doc__");
for (int i = 0, n = node->body.size(); i < n; i++) {
AST_TYPE::AST_TYPE type = node->body[i]->type;
if (type == AST_TYPE::Pass) {
continue;
} else if (type == AST_TYPE::Expr) {
AST_Expr* expr = ast_cast<AST_Expr>(node->body[i]);
if (expr->value->type == AST_TYPE::Str) {
if (i == 0) {
had_docstring = true;
CompilerVariable* str = evalExpr(expr->value, exc_info);
cls->setattr(emitter, getEmptyOpInfo(exc_info), &doc_str, str);
}
} else {
fprintf(stderr, "Currently don't support non-noop expressions in classes:\n");
printf("On line %d: ", expr->lineno);
print_ast(expr);
printf("\n");
abort();
}
} else if (type == AST_TYPE::FunctionDef) {
AST_FunctionDef* fdef = ast_cast<AST_FunctionDef>(node->body[i]);
assert(fdef->args->defaults.size() == 0);
......@@ -1424,6 +1443,10 @@ private:
}
}
if (!had_docstring) {
cls->setattr(emitter, getEmptyOpInfo(exc_info), &doc_str, getNone());
}
_doSet(node->name, cls, exc_info);
cls->decvref(emitter);
}
......
......@@ -2944,7 +2944,7 @@ extern "C" Box* import(const std::string* name) {
continue;
if (VERBOSITY() >= 1)
printf("Beginning import of %s...\n", fn.c_str());
printf("Importing %s from %s\n", name->c_str(), fn.c_str());
// TODO duplication with jit.cpp:
BoxedModule* module = createModule(*name, fn);
......
class C1(object):
"hello world"
print C1.__doc__
class C2(object):
"doc1"
"doc2"
print C2.__doc__
class C3(object):
pass
print C3.__doc__
"""
# Not supported yet:
class C3(object):
1
assert C3.__doc__ is None
class C4(object):
("a")
assert C3.__doc__ is None
"""
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