Skip to main content

luaur_compiler/methods/
compiler_compile_expr_temp_n.rs

1use crate::records::compiler::Compiler;
2use luaur_ast::records::ast_expr::AstExpr;
3use luaur_ast::records::ast_expr_call::AstExprCall;
4use luaur_ast::records::ast_expr_varargs::AstExprVarargs;
5use luaur_ast::records::ast_node::AstNode;
6use luaur_ast::rtti;
7use luaur_common::enums::luau_opcode::LuauOpcode;
8use luaur_common::macros::luau_assert::LUAU_ASSERT;
9
10impl Compiler {
11    pub fn compile_expr_temp_n(
12        &mut self,
13        node: *mut AstExpr,
14        target: u8,
15        target_count: u8,
16        target_top: bool,
17    ) {
18        LUAU_ASSERT!(!target_top || u32::from(target) + u32::from(target_count) == self.reg_top);
19
20        if target_count == 255 {
21            let location = unsafe { (*node).base.location };
22            crate::records::compile_error::CompileError::raise(
23                &location,
24                core::format_args!("Exceeded result count limit; simplify the code to compile"),
25            );
26        }
27
28        let expr_call = unsafe { rtti::ast_node_as::<AstExprCall>(node as *mut AstNode) };
29        if !expr_call.is_null() {
30            self.compile_expr_call(expr_call, target, target_count, target_top, false);
31            return;
32        }
33
34        let expr_varargs = unsafe { rtti::ast_node_as::<AstExprVarargs>(node as *mut AstNode) };
35        if !expr_varargs.is_null() {
36            self.compile_expr_varargs(expr_varargs, target, target_count, false);
37            return;
38        }
39
40        self.compile_expr_temp(node, target);
41
42        for i in 1..target_count {
43            unsafe {
44                let bytecode = &mut *self.bytecode;
45                bytecode.emit_abc(LuauOpcode::LOP_LOADNIL, target.wrapping_add(i), 0, 0);
46            }
47        }
48    }
49}