Skip to main content

luaur_compiler/methods/
compiler_ensure_export_table.rs

1use crate::records::compiler::Compiler;
2use luaur_ast::records::ast_node::AstNode;
3use luaur_common::enums::luau_opcode::LuauOpcode;
4use luaur_common::macros::luau_assert::LUAU_ASSERT;
5
6const K_DEFAULT_ALLOC_PC: u32 = !0u32;
7
8impl Compiler {
9    pub fn ensure_export_table(&mut self, node: *mut AstNode) {
10        let export_local = &mut self.export_table_local as *mut _;
11        if self.locals.contains(&export_local) {
12            return;
13        }
14
15        LUAU_ASSERT!(self.at_top_level());
16
17        let table_reg = self.alloc_reg(node, 1);
18        unsafe {
19            (*self.bytecode).emit_abc(
20                LuauOpcode::LOP_NEWTABLE,
21                table_reg,
22                Compiler::encode_hash_size(0),
23                0,
24            );
25            (*self.bytecode).emit_aux(0);
26        }
27
28        self.push_local(export_local, table_reg, K_DEFAULT_ALLOC_PC);
29    }
30}