Przeglądaj źródła

Update compiler.cpp

blueloveTH 2 lat temu
rodzic
commit
6681efe770
1 zmienionych plików z 4 dodań i 1 usunięć
  1. 4 1
      src/compiler.cpp

+ 4 - 1
src/compiler.cpp

@@ -33,7 +33,10 @@ namespace pkpy{
         // previously, we only do this if the last opcode is not a return
         // however, this is buggy...since there may be a jump to the end (out of bound) even if the last opcode is a return
         ctx()->emit_(OP_RETURN_VALUE, 1, BC_KEEPLINE);
-        ctx()->co->end_line = prev().line;
+        // find the last valid token
+        int j = i-1;
+        while(tokens[j].type == TK("@eol") || tokens[j].type == TK("@dedent") || tokens[j].type == TK("@eof")) j--;
+        ctx()->co->end_line = tokens[j].line;
 
         // some check here
         std::vector<Bytecode>& codes = ctx()->co->codes;