diff --git a/examples/test.lua b/examples/test.lua index 2fa6c80..d569215 100644 --- a/examples/test.lua +++ b/examples/test.lua @@ -1,5 +1,5 @@ -local test = 10 +local test = 11 if test == 10 then print("first") elseif test == 11 then diff --git a/src/compile.rs b/src/compile.rs index 73183b4..70236d5 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -423,11 +423,16 @@ impl Statement { 0, ))); - let block_instructions = if_part.1.compile(state, scope); + let if_block_instructions = if_part.1.compile(state, scope); + let else_block_instructions = else_block.compile(state, scope); instructions.push(PreInstr::Instr(Instruction::Jmp( - block_instructions.len() as i32 + if_block_instructions.len() as i32 + 1, ))); - instructions.extend(block_instructions); + instructions.extend(if_block_instructions); + instructions.push(PreInstr::Instr(Instruction::Jmp( + else_block_instructions.len() as i32, + ))); + instructions.extend(else_block_instructions); } Statement::Expression(expr) => { let (instr, _) = expr.kind.compile(state, scope, None);