Add compiling of the else-block

This commit is contained in:
Sofia 2026-03-19 17:35:31 +02:00
parent b6a38101f7
commit 50bd615767
2 changed files with 9 additions and 4 deletions

View File

@ -1,5 +1,5 @@
local test = 10
local test = 11
if test == 10 then
print("first")
elseif test == 11 then

View File

@ -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);