Commit 49fe0ddf authored by Kevin Modzelewski's avatar Kevin Modzelewski

code.co_firstlineno

parent 7b71c6f8
...@@ -1427,6 +1427,8 @@ public: ...@@ -1427,6 +1427,8 @@ public:
bool visit_functiondef(AST_FunctionDef* node) override { bool visit_functiondef(AST_FunctionDef* node) override {
auto def = new AST_FunctionDef(); auto def = new AST_FunctionDef();
def->lineno = node->lineno;
def->col_offset = node->col_offset;
def->name = node->name; def->name = node->name;
def->body = node->body; // expensive vector copy def->body = node->body; // expensive vector copy
// Decorators are evaluated before the defaults, so this *must* go before remapArguments(). // Decorators are evaluated before the defaults, so this *must* go before remapArguments().
......
...@@ -51,6 +51,20 @@ public: ...@@ -51,6 +51,20 @@ public:
return boxString(static_cast<BoxedCode*>(b)->f->source->fn); return boxString(static_cast<BoxedCode*>(b)->f->source->fn);
} }
static Box* firstlineno(Box* b, void*) {
RELEASE_ASSERT(b->cls == code_cls, "");
BoxedCode* code = static_cast<BoxedCode*>(b);
CLFunction* cl = code->f;
if (!cl->source) {
// I don't think it really matters what we return here;
// in CPython, builtin functions don't have code objects.
return boxInt(-1);
}
return boxInt(cl->source->ast->lineno);
}
static Box* argcount(Box* b, void*) { static Box* argcount(Box* b, void*) {
RELEASE_ASSERT(b->cls == code_cls, ""); RELEASE_ASSERT(b->cls == code_cls, "");
...@@ -114,6 +128,8 @@ void setupCode() { ...@@ -114,6 +128,8 @@ void setupCode() {
code_cls->giveAttr("co_name", new (pyston_getset_cls) BoxedGetsetDescriptor(BoxedCode::name, NULL, NULL)); code_cls->giveAttr("co_name", new (pyston_getset_cls) BoxedGetsetDescriptor(BoxedCode::name, NULL, NULL));
code_cls->giveAttr("co_filename", new (pyston_getset_cls) BoxedGetsetDescriptor(BoxedCode::filename, NULL, NULL)); code_cls->giveAttr("co_filename", new (pyston_getset_cls) BoxedGetsetDescriptor(BoxedCode::filename, NULL, NULL));
code_cls->giveAttr("co_firstlineno",
new (pyston_getset_cls) BoxedGetsetDescriptor(BoxedCode::firstlineno, NULL, NULL));
code_cls->giveAttr("co_argcount", new (pyston_getset_cls) BoxedGetsetDescriptor(BoxedCode::argcount, NULL, NULL)); code_cls->giveAttr("co_argcount", new (pyston_getset_cls) BoxedGetsetDescriptor(BoxedCode::argcount, NULL, NULL));
code_cls->giveAttr("co_varnames", new (pyston_getset_cls) BoxedGetsetDescriptor(BoxedCode::varnames, NULL, NULL)); code_cls->giveAttr("co_varnames", new (pyston_getset_cls) BoxedGetsetDescriptor(BoxedCode::varnames, NULL, NULL));
code_cls->giveAttr("co_flags", new (pyston_getset_cls) BoxedGetsetDescriptor(BoxedCode::flags, NULL, NULL)); code_cls->giveAttr("co_flags", new (pyston_getset_cls) BoxedGetsetDescriptor(BoxedCode::flags, NULL, NULL));
......
...@@ -21,7 +21,7 @@ set -e ...@@ -21,7 +21,7 @@ set -e
set -ux set -ux
python -c 'import __future__' python -c 'import __future__'
python -c 'import sys; print sys.executable' python -c 'import sys; print sys.executable'
pip install six==1.9.0 cffi==0.9.2 pip install six==1.9.0 cffi==0.9.2 pycparser==2.12
python -c 'import six; print six.__version__' python -c 'import six; print six.__version__'
""".strip() """.strip()
......
...@@ -4,6 +4,7 @@ def f(a, b=2, *args, **kw): ...@@ -4,6 +4,7 @@ def f(a, b=2, *args, **kw):
c = f.func_code c = f.func_code
print c.co_argcount print c.co_argcount
print c.co_varnames print c.co_varnames
print c.co_firstlineno
print hex(c.co_flags & 0x0c) print hex(c.co_flags & 0x0c)
def f(l=[]): def f(l=[]):
...@@ -15,3 +16,4 @@ f() ...@@ -15,3 +16,4 @@ f()
def f(): def f():
pass pass
print f.func_defaults print f.func_defaults
print f.func_code.co_firstlineno
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