mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-19 19:10:17 +00:00
set def_line
for function
This commit is contained in:
parent
5dba2cd8e6
commit
a55f62c860
@ -9,3 +9,13 @@ y = 2
|
||||
costly_func(2) # 3s
|
||||
|
||||
time.sleep(1) # 1s
|
||||
|
||||
def new_func(a, b, c):
|
||||
x = a + b
|
||||
x = x + c
|
||||
return a
|
||||
|
||||
def new_func2(a, b, c):
|
||||
x = a + b
|
||||
x = x + c
|
||||
return a
|
||||
|
@ -2416,6 +2416,7 @@ static Error* consume_pep695_py312(Compiler* self) {
|
||||
|
||||
static Error* compile_function(Compiler* self, int decorators) {
|
||||
Error* err;
|
||||
int def_line = prev()->line;
|
||||
consume(TK_ID);
|
||||
c11_sv decl_name_sv = Token__sv(prev());
|
||||
int decl_index;
|
||||
@ -2445,7 +2446,7 @@ static Error* compile_function(Compiler* self, int decorators) {
|
||||
}
|
||||
}
|
||||
|
||||
Ctx__emit_(ctx(), OP_LOAD_FUNCTION, decl_index, prev()->line);
|
||||
Ctx__emit_(ctx(), OP_LOAD_FUNCTION, decl_index, def_line);
|
||||
Ctx__s_emit_decorators(ctx(), decorators);
|
||||
|
||||
py_Name decl_name = py_namev(decl_name_sv);
|
||||
@ -2458,9 +2459,9 @@ static Error* compile_function(Compiler* self, int decorators) {
|
||||
}
|
||||
}
|
||||
|
||||
Ctx__emit_(ctx(), OP_STORE_CLASS_ATTR, Ctx__add_name(ctx(), decl_name), prev()->line);
|
||||
Ctx__emit_(ctx(), OP_STORE_CLASS_ATTR, Ctx__add_name(ctx(), decl_name), def_line);
|
||||
} else {
|
||||
NameExpr* e = NameExpr__new(prev()->line, decl_name, name_scope(self));
|
||||
NameExpr* e = NameExpr__new(def_line, decl_name, name_scope(self));
|
||||
vtemit_store((Expr*)e, ctx());
|
||||
vtdelete((Expr*)e);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user