luaur_compiler/methods/
compiler_alloc_reg.rs1use crate::records::compile_error::CompileError;
2use crate::records::compiler::Compiler;
3use luaur_ast::records::ast_node::AstNode;
4use luaur_ast::records::location::Location;
5use luaur_common::functions::vformat::vformat;
6use luaur_common::macros::luau_noinline::LUAU_NOINLINE;
7
8impl Compiler {
9 pub fn alloc_reg(&mut self, node: *mut AstNode, count: u32) -> u8 {
10 let top = self.reg_top;
11 let k_max_register_count = 255;
12
13 if top + count > k_max_register_count {
14 let location = unsafe { (*node).location };
15 CompileError::raise(
18 &location,
19 format_args!(
20 "Out of registers when trying to allocate {} registers: exceeded limit {}",
21 count, k_max_register_count
22 ),
23 );
24 }
25
26 self.reg_top += count;
27 self.stack_size = core::cmp::max(self.stack_size, self.reg_top);
28
29 top as u8
30 }
31}