Fixed variable lifetime in loops
This commit is contained in:
@ -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})
|
||||
|
Reference in New Issue
Block a user