Update compiler.cpp

This commit is contained in:
blueloveTH 2024-02-07 17:45:19 +08:00
parent c06bf5729c
commit 6681efe770

View File

@ -33,7 +33,10 @@ namespace pkpy{
// previously, we only do this if the last opcode is not a return // 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 // 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()->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 // some check here
std::vector<Bytecode>& codes = ctx()->co->codes; std::vector<Bytecode>& codes = ctx()->co->codes;