|
@@ -10,6 +10,7 @@ namespace pkpy{
|
|
|
|
|
|
|
|
CodeObject_ Compiler::push_global_context(){
|
|
CodeObject_ Compiler::push_global_context(){
|
|
|
CodeObject_ co = std::make_shared<CodeObject>(lexer->src, lexer->src->filename);
|
|
CodeObject_ co = std::make_shared<CodeObject>(lexer->src, lexer->src->filename);
|
|
|
|
|
+ co->start_line = prev().line;
|
|
|
contexts.push(CodeEmitContext(vm, co, contexts.size()));
|
|
contexts.push(CodeEmitContext(vm, co, contexts.size()));
|
|
|
return co;
|
|
return co;
|
|
|
}
|
|
}
|
|
@@ -17,6 +18,7 @@ namespace pkpy{
|
|
|
FuncDecl_ Compiler::push_f_context(Str name){
|
|
FuncDecl_ Compiler::push_f_context(Str name){
|
|
|
FuncDecl_ decl = std::make_shared<FuncDecl>();
|
|
FuncDecl_ decl = std::make_shared<FuncDecl>();
|
|
|
decl->code = std::make_shared<CodeObject>(lexer->src, name);
|
|
decl->code = std::make_shared<CodeObject>(lexer->src, name);
|
|
|
|
|
+ decl->code->start_line = prev().line;
|
|
|
decl->nested = name_scope() == NAME_LOCAL;
|
|
decl->nested = name_scope() == NAME_LOCAL;
|
|
|
contexts.push(CodeEmitContext(vm, decl->code, contexts.size()));
|
|
contexts.push(CodeEmitContext(vm, decl->code, contexts.size()));
|
|
|
contexts.top().func = decl;
|
|
contexts.top().func = decl;
|
|
@@ -31,6 +33,8 @@ 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;
|
|
|
|
|
+
|
|
|
// some check here
|
|
// some check here
|
|
|
std::vector<Bytecode>& codes = ctx()->co->codes;
|
|
std::vector<Bytecode>& codes = ctx()->co->codes;
|
|
|
if(ctx()->co->varnames.size() > PK_MAX_CO_VARNAMES){
|
|
if(ctx()->co->varnames.size() > PK_MAX_CO_VARNAMES){
|