Skip to content

Commit

Permalink
Fix switch codegen issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jac3km4 committed Feb 2, 2021
1 parent f6333ab commit abfc141
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion compiler/src/assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl Assembler {
for case in cases {
let matcher = Assembler::from_expr(&case.0, None, pool, &mut scope.clone())?;
let body = Assembler::from_seq(&case.1, pool, &mut scope.clone())?;
self.emit(Instr::SwitchLabel(matcher.offset(), matcher.offset() + body.offset()));
self.emit(Instr::SwitchLabel(matcher.offset() + body.offset(), matcher.offset()));
self.append(matcher);
self.append(body);
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl Decode for Instr {
25 => Ok(Instr::Param(input.decode()?)),
26 => Ok(Instr::ObjectField(input.decode()?)),
27 => Ok(Instr::ExternalVar),
28 => Ok(Instr::Switch(input.decode()?, Offset::new(input.decode::<i16>()? + 9))),
28 => Ok(Instr::Switch(input.decode()?, Offset::new(input.decode::<i16>()? + 11))),
29 => Ok(Instr::SwitchLabel(
Offset::new(input.decode::<i16>()? + 3),
Offset::new(input.decode::<i16>()? + 5),
Expand Down Expand Up @@ -458,7 +458,7 @@ impl Encode for Instr {
Instr::Switch(idx, offset) => {
output.encode(&28u8)?;
output.encode(idx)?;
output.encode(&Offset::new(offset.value - 9))?;
output.encode(&Offset::new(offset.value - 11))?;
}
Instr::SwitchLabel(start, exit) => {
output.encode(&29u8)?;
Expand Down

0 comments on commit abfc141

Please sign in to comment.