Skip to main content

luaur_compiler/methods/
compiler_compile_expr_list_temp.rs

1use crate::records::compiler::Compiler;
2use luaur_ast::records::ast_array::AstArray;
3use luaur_ast::records::ast_expr::AstExpr;
4use luaur_common::enums::luau_opcode::LuauOpcode;
5use luaur_common::macros::luau_assert::LUAU_ASSERT;
6
7impl Compiler {
8    pub fn compile_expr_list_temp(
9        &mut self,
10        list: &AstArray<*mut AstExpr>,
11        target: u8,
12        target_count: u8,
13        target_top: bool,
14    ) {
15        LUAU_ASSERT!(!target_top || (target as u32 + target_count as u32) == self.reg_top);
16
17        if list.size == target_count as usize {
18            for i in 0..list.size {
19                let expr = unsafe { *list.data.add(i) };
20                self.compile_expr_temp(expr, target.wrapping_add(i as u8));
21            }
22        } else if list.size > target_count as usize {
23            for i in 0..target_count as usize {
24                let expr = unsafe { *list.data.add(i) };
25                self.compile_expr_temp(expr, target.wrapping_add(i as u8));
26            }
27
28            for i in target_count as usize..list.size {
29                let expr = unsafe { *list.data.add(i) };
30                self.compile_expr_side(expr);
31            }
32        } else if list.size > 0 {
33            for i in 0..list.size - 1 {
34                let expr = unsafe { *list.data.add(i) };
35                self.compile_expr_temp(expr, target.wrapping_add(i as u8));
36            }
37
38            let last_expr = unsafe { *list.data.add(list.size - 1) };
39            self.compile_expr_temp_n(
40                last_expr,
41                target.wrapping_add((list.size - 1) as u8),
42                target_count.wrapping_sub((list.size - 1) as u8),
43                target_top,
44            );
45        } else {
46            for i in 0..target_count {
47                unsafe {
48                    let bytecode = &mut *self.bytecode;
49                    bytecode.emit_abc(LuauOpcode::LOP_LOADNIL, target.wrapping_add(i), 0, 0);
50                }
51            }
52        }
53    }
54}