Răsfoiți Sursa

set `def_line` for function

blueloveTH 6 luni în urmă
părinte
comite
a55f62c860
2 a modificat fișierele cu 14 adăugiri și 3 ștergeri
  1. 10 0
      scripts/98_profiler.py
  2. 4 3
      src/compiler/compiler.c

+ 10 - 0
scripts/98_profiler.py

@@ -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

+ 4 - 3
src/compiler/compiler.c

@@ -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);
     }