codegen will not generate 'jmp' if 'if' and 'elsif' is the last condition

This commit is contained in:
Valk Richard Li 2021-02-18 11:45:47 +08:00
parent 02148f4766
commit 9c9bb52818
2 changed files with 15 additions and 13 deletions

View File

@ -523,6 +523,8 @@ void nasal_codegen::conditional_gen(nasal_ast& ast)
gen(op_jmpfalse,0);
block_gen(tmp.get_children()[1]);
jmp_label.push_back(exec_code.size());
// without 'else' the last condition doesn't need to jmp
if(i!=size-1)
gen(op_jmp,0);
exec_code[ptr].index=exec_code.size();
}
@ -532,8 +534,8 @@ void nasal_codegen::conditional_gen(nasal_ast& ast)
break;
}
}
for(std::vector<int>::iterator j=jmp_label.begin();j!=jmp_label.end();++j)
exec_code[*j].index=exec_code.size();
for(std::vector<int>::iterator i=jmp_label.begin();i!=jmp_label.end();++i)
exec_code[*i].index=exec_code.size();
return;
}