Skip to content

Commit b8749ce

Browse files
committed
aml: fix branching calculations for DefIfElse
1 parent 4ceaa01 commit b8749ce

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

aml/src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ impl Interpreter {
214214
const DEF_ELSE_OP: u8 = 0xa1;
215215
// TODO: maybe need to handle error here
216216
if context.peek()? == DEF_ELSE_OP {
217+
context.next()?;
217218
let _else_length = context.pkglength()?;
218219
}
219220
}
@@ -400,11 +401,12 @@ impl Interpreter {
400401
// Check for an else-branch, and skip over it
401402
// TODO: if we run out of stream here, it might just be an IfOp at the
402403
// end I think?
403-
let start_pc = context.current_block.pc;
404404
const DEF_ELSE_OP: u8 = 0xa1;
405405
if context.peek()? == DEF_ELSE_OP {
406-
let else_length = context.pkglength()? - (context.current_block.pc - start_pc);
407-
context.current_block.pc += else_length;
406+
context.next()?;
407+
let start_pc = context.current_block.pc;
408+
let else_length = context.pkglength()?;
409+
context.current_block.pc += else_length - (context.current_block.pc - start_pc);
408410
}
409411

410412
continue;
@@ -754,8 +756,7 @@ impl Interpreter {
754756
1,
755757
));
756758
}
757-
// TODO: maybe should be a normal error instead
758-
Opcode::Else => panic!("Unexpected DefElseOp without corresponding DefIfElseOp"),
759+
Opcode::Else => return Err(AmlError::ElseFoundWithoutCorrespondingIf),
759760
Opcode::While => todo!(),
760761
Opcode::Noop => {}
761762
Opcode::Return => context.start_in_flight_op(OpInFlight::new(Opcode::Return, 1)),
@@ -1347,6 +1348,7 @@ pub enum AmlError {
13471348
ObjectDoesNotExist(AmlName),
13481349

13491350
NoCurrentOp,
1351+
ElseFoundWithoutCorrespondingIf,
13501352

13511353
MethodArgCountIncorrect,
13521354

0 commit comments

Comments
 (0)