Skip to main content

luaur_compiler/methods/
compiler_pop_locals.rs

1use crate::functions::sref_compiler::sref_ast_name;
2use crate::records::compiler::Compiler;
3use luaur_common::enums::luau_bytecode_type::LBC_TYPE_ANY;
4use luaur_common::macros::luau_assert::LUAU_ASSERT;
5
6impl Compiler {
7    pub fn pop_locals(&mut self, start: usize) {
8        LUAU_ASSERT!(start <= self.local_stack.len());
9
10        for i in start..self.local_stack.len() {
11            let local = self.local_stack[i];
12            let l = self.locals.find_mut(&local);
13            LUAU_ASSERT!(l.is_some());
14            let l = l.unwrap();
15            LUAU_ASSERT!(l.allocated);
16
17            l.allocated = false;
18
19            if self.options.debug_level >= 2 {
20                let debugpc = unsafe { (*self.bytecode).get_debug_pc() };
21                unsafe {
22                    (*self.bytecode).push_debug_local(
23                        sref_ast_name((*local).name),
24                        l.reg,
25                        l.debugpc,
26                        debugpc,
27                    );
28                }
29            }
30
31            if self.options.type_info_level >= 1 && i >= self.arg_count {
32                let debugpc = unsafe { (*self.bytecode).get_debug_pc() };
33                let ty = self
34                    .local_types
35                    .find(&local)
36                    .copied()
37                    .unwrap_or(LBC_TYPE_ANY);
38
39                unsafe {
40                    (*self.bytecode).push_local_type_info(ty, l.reg, l.allocpc, debugpc);
41                }
42            }
43        }
44
45        self.local_stack.resize(start, core::ptr::null_mut());
46    }
47}