mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
fix a bug
This commit is contained in:
parent
849c6aabb5
commit
f60cd8a21e
@ -62,11 +62,11 @@ class Compiler {
|
||||
if(!ctx()->s_expr.empty()){
|
||||
throw std::runtime_error("!ctx()->s_expr.empty()\n" + ctx()->_log_s_expr());
|
||||
}
|
||||
// if the last op does not return, add a default return None
|
||||
if(ctx()->co->codes.empty() || ctx()->co->codes.back().op != OP_RETURN_VALUE){
|
||||
// add a `return None` in the end as a guard
|
||||
// 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_LOAD_NONE, BC_NOARG, BC_KEEPLINE);
|
||||
ctx()->emit(OP_RETURN_VALUE, BC_NOARG, BC_KEEPLINE);
|
||||
}
|
||||
ctx()->co->optimize(vm);
|
||||
if(ctx()->co->varnames.size() > PK_MAX_CO_VARNAMES){
|
||||
SyntaxError("maximum number of local variables exceeded");
|
||||
|
@ -5,3 +5,10 @@ assert list(mp) == [1, 4, 9, 16, 25]
|
||||
|
||||
|
||||
assert not 3>4
|
||||
|
||||
def f(x):
|
||||
if x>1:
|
||||
return 1
|
||||
|
||||
assert f(2) == 1
|
||||
assert f(0) == None
|
Loading…
x
Reference in New Issue
Block a user