Skip to content

Commit

Permalink
Applied several suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Nicolas Polomack <[email protected]>
  • Loading branch information
OctaveLarose and Hirevo committed Feb 16, 2024
1 parent a027ea6 commit 58e3c82
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
44 changes: 22 additions & 22 deletions som-core/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ impl Bytecode {
Self::PushField(_) => "PUSH_FIELD",
Self::PushBlock(_) => "PUSH_BLOCK",
Self::PushConstant(_) => "PUSH_CONSTANT",
Self::PushConstant0 => "PUSH_CONSTANT 0",
Self::PushConstant1 => "PUSH_CONSTANT 1",
Self::PushConstant2 => "PUSH_CONSTANT 2",
Self::PushConstant0 => "PUSH_CONSTANT_0",
Self::PushConstant1 => "PUSH_CONSTANT_1",
Self::PushConstant2 => "PUSH_CONSTANT_2",
Self::PushGlobal(_) => "PUSH_GLOBAL",
Self::Push0 => "PUSH_0",
Self::Push1 => "PUSH_1",
Expand All @@ -57,14 +57,14 @@ impl Bytecode {
Self::PopLocal(_, _) => "POP_LOCAL",
Self::PopArgument(_, _) => "POP_ARGUMENT",
Self::PopField(_) => "POP_FIELD",
Self::Send1(_) => "SEND 1",
Self::Send2(_) => "SEND 2",
Self::Send3(_) => "SEND 3",
Self::SendN(_) => "SEND N",
Self::SuperSend1(_) => "SUPER_SEND 1",
Self::SuperSend2(_) => "SUPER_SEND 2",
Self::SuperSend3(_) => "SUPER_SEND 3",
Self::SuperSendN(_) => "SUPER_SEND N",
Self::Send1(_) => "SEND_1",
Self::Send2(_) => "SEND_2",
Self::Send3(_) => "SEND_3",
Self::SendN(_) => "SEND_N",
Self::SuperSend1(_) => "SUPER_SEND_1",
Self::SuperSend2(_) => "SUPER_SEND_2",
Self::SuperSend3(_) => "SUPER_SEND_3",
Self::SuperSendN(_) => "SUPER_SEND_N",
Self::ReturnLocal => "RETURN_LOCAL",
Self::ReturnNonLocal => "RETURN_NON_LOCAL",
}
Expand All @@ -82,9 +82,9 @@ impl Bytecode {
Self::PushField(_) => "PUSH_FIELD ",
Self::PushBlock(_) => "PUSH_BLOCK ",
Self::PushConstant(_) => "PUSH_CONSTANT ",
Self::PushConstant0 => "PUSH_CONSTANT 0 ",
Self::PushConstant1 => "PUSH_CONSTANT 1 ",
Self::PushConstant2 => "PUSH_CONSTANT 2 ",
Self::PushConstant0 => "PUSH_CONSTANT_0 ",
Self::PushConstant1 => "PUSH_CONSTANT_1 ",
Self::PushConstant2 => "PUSH_CONSTANT_2 ",
Self::PushGlobal(_) => "PUSH_GLOBAL ",
Self::Push0 => "PUSH_0 ",
Self::Push1 => "PUSH_1 ",
Expand All @@ -93,14 +93,14 @@ impl Bytecode {
Self::PopLocal(_, _) => "POP_LOCAL ",
Self::PopArgument(_, _) => "POP_ARGUMENT ",
Self::PopField(_) => "POP_FIELD ",
Self::Send1(_) => "SEND 1 ",
Self::Send2(_) => "SEND 2 ",
Self::Send3(_) => "SEND 3 ",
Self::SendN(_) => "SEND N ",
Self::SuperSend1(_) => "SUPER_SEND 1 ",
Self::SuperSend2(_) => "SUPER_SEND 2 ",
Self::SuperSend3(_) => "SUPER_SEND 3 ",
Self::SuperSendN(_) => "SUPER_SEND N ",
Self::Send1(_) => "SEND_1 ",
Self::Send2(_) => "SEND_2 ",
Self::Send3(_) => "SEND_3 ",
Self::SendN(_) => "SEND_N ",
Self::SuperSend1(_) => "SUPER_SEND_1 ",
Self::SuperSend2(_) => "SUPER_SEND_2 ",
Self::SuperSend3(_) => "SUPER_SEND_3 ",
Self::SuperSendN(_) => "SUPER_SEND_N ",
Self::ReturnLocal => "RETURN_LOCAL ",
Self::ReturnNonLocal => "RETURN_NON_LOCAL",
}
Expand Down
8 changes: 6 additions & 2 deletions som-interpreter-bc/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,17 @@ impl InnerGenCtxt for BlockGenCtxt<'_> {
}

fn remove_dup_popx_pop_sequences(&mut self) {
if self.body.is_none() || self.body.as_ref().unwrap().len() < 3 {
let Some(body) = self.body.as_mut() else {
return;
};

if body.len() < 3 {
return;
}

let mut indices_to_remove: Vec<usize> = vec![];

for (idx, bytecode_win) in self.body.as_ref().unwrap().windows(3).enumerate() {
for (idx, bytecode_win) in body.windows(3).enumerate() {
if matches!(bytecode_win[0], Bytecode::Dup) &&
matches!(bytecode_win[1], Bytecode::PopField(..) | Bytecode::PopLocal(..) | Bytecode::PopArgument(..)) &&
matches!(bytecode_win[2], Bytecode::Pop) {
Expand Down
2 changes: 1 addition & 1 deletion som-interpreter-bc/src/disassembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn disassemble_body(
Bytecode::PushConstant0 => 0,
Bytecode::PushConstant1 => 1,
Bytecode::PushConstant2 => 2,
_ => panic!("Obviously unreachable")
_ => unreachable!(),
};

print!(" {idx}");
Expand Down

0 comments on commit 58e3c82

Please sign in to comment.