Add LoadMethod and CallMethod* opcodes

This commit is contained in:
Noah 2021-03-15 09:21:20 -05:00
parent da0c85d2ac
commit ee0af406e2
2 changed files with 87 additions and 33 deletions

View file

@ -167,25 +167,29 @@ impl CodeInfo {
let mut startdepths = vec![u32::MAX; self.blocks.len()];
startdepths[0] = 0;
stack.push(Label(0));
let debug = false;
'process_blocks: while let Some(block) = stack.pop() {
let mut depth = startdepths[block.0 as usize];
if debug {
eprintln!("===BLOCK {}===", block.0);
}
let block = &self.blocks[block.0 as usize];
for i in &block.instructions {
let instr = &i.instr;
let effect = instr.stack_effect(false);
let new_depth = add_ui(depth, effect);
if debug {
eprintln!("{:?}: {:+}, {:+} = {}", instr, effect, depth, new_depth);
}
if new_depth > maxdepth {
maxdepth = new_depth
}
// we don't want to worry about Continue or Break, they use unwinding to jump to
// their targets and as such the stack size is taken care of in frame.rs by setting
// we don't want to worry about Continue, it uses unwinding to jump to
// its targets and as such the stack size is taken care of in frame.rs by setting
// it back to the level it was at when SetupLoop was run
let jump_label = instr.label_arg().filter(|_| {
!matches!(
instr,
Instruction::Continue { .. } | Instruction::Break { .. }
)
});
let jump_label = instr
.label_arg()
.filter(|_| !matches!(instr, Instruction::Continue { .. }));
if let Some(&target_block) = jump_label {
let effect = instr.stack_effect(true);
let target_depth = add_ui(depth, effect);
@ -215,7 +219,7 @@ fn stackdepth_push(stack: &mut Vec<Label>, startdepths: &mut [u32], target: Labe
fn add_ui(a: u32, b: i32) -> u32 {
if b < 0 {
a - b.abs() as u32
a - b.wrapping_abs() as u32
} else {
a + b as u32
}