Fixed variable lifetime in loops

This commit is contained in:
2024-07-16 20:22:28 +02:00
parent 1825a72f8c
commit f9d72fe490
11 changed files with 90 additions and 18 deletions

View File

@ -22,8 +22,12 @@ func (a *Assembler) Call(name string) {
// Return returns back to the caller.
func (a *Assembler) Return() {
if len(a.Instructions) > 0 && a.Instructions[len(a.Instructions)-1].Mnemonic == RETURN {
return
if len(a.Instructions) > 0 {
lastMnemonic := a.Instructions[len(a.Instructions)-1].Mnemonic
if lastMnemonic == RETURN || lastMnemonic == JUMP {
return
}
}
a.Instructions = append(a.Instructions, Instruction{Mnemonic: RETURN})