/// inserts stack deallocs and stack allocs to solve scope problems
inserts stack deallocs and stack allocs to solve scope problems
inserts stack deallocs and stack allocs to solve scope problems
pub fn solve_scope_difference(
        &mut self,
        ops: &[TCOpcode],
        mut goto_scope: u32,
        mut label_scope: u32,
        loc: CodeLoc,
    ) {
        let mut goto_scopes = Vec::new();
        let mut label_scopes = Vec::new();
        while goto_scope != !0 {
            if let TCOpcodeKind::ScopeBegin(vars, parent) = ops[goto_scope as usize].kind {
                goto_scopes.push((goto_scope, vars));
                goto_scope = parent;
            } else {
                panic!("scope_idx pointed to wrong opcode")
            }
        }
        while label_scope != !0 {
            if let TCOpcodeKind::ScopeBegin(vars, parent) = ops[label_scope as usize].kind {
                label_scopes.push((label_scope, vars));
                label_scope = parent;
            } else {
                panic!("scope_idx pointed to wrong opcode")
            }
        }
        while let Some((g, l)) = goto_scopes.last().zip(label_scopes.last()) {
            let (goto, _) = g;
            let (label, _) = l;
            if goto != label {
                break;
            }
            goto_scopes.pop();
            label_scopes.pop();
        }
        for (_, scope) in goto_scopes {
            for _ in 0..scope.len() {
                self.func.opcodes.push(Opcode::StackDealloc);
            }
        }
        for (_, scope) in label_scopes.into_iter().rev() {
            for (&var, &ty) in scope {
                self.func.opcodes.push(Opcode::StackAlloc);
                self.func.opcodes.push(ty.size());
            }
        }
    }
pub fn solve_scope_difference ( & mut self , ops : & [ TCOpcode ] , mut goto_scope : u32 , mut label_scope : u32 , loc : CodeLoc , ) { let mut goto_scopes = Vec :: new ( ) ; let mut label_scopes = Vec :: new ( ) ; while goto_scope != ! 0 { if let TCOpcodeKind :: ScopeBegin ( vars , parent ) = ops [ goto_scope as usize ] . kind { goto_scopes . push ( ( goto_scope , vars ) ) ; goto_scope = parent ; } else { panic ! ( " " ) } } while label_scope != ! 0 { if let TCOpcodeKind :: ScopeBegin ( vars , parent ) = ops [ label_scope as usize ] . kind { label_scopes . push ( ( label_scope , vars ) ) ; label_scope = parent ; } else { panic ! ( " " ) } } while let Some ( ( g , l ) ) = goto_scopes . last ( ) . zip ( label_scopes . last ( ) ) { let ( goto , _ ) = g ; let ( label , _ ) = l ; if goto != label { break ; } goto_scopes . pop ( ) ; label_scopes . pop ( ) ; } for ( _ , scope ) in goto_scopes { for _ in 0 .. scope . len ( ) { self . func . opcodes . push ( Opcode :: StackDealloc ) ; } } for ( _ , scope ) in label_scopes . into_iter ( ) . rev ( ) { for ( & var , & ty ) in scope { self . func . opcodes . push ( Opcode :: StackAlloc ) ; self . func . opcodes . push ( ty . size ( ) ) ; } } }
inserts stack deallocs and stack allocs to solve scope problems
inserts stack deallocs and stack allocs to solve scope problems
&mut self
ops
&[TCOpcode]
goto_scope
u32
label_scope
u32
loc
CodeLoc