luaur_compiler/methods/
compiler_compile_stat_function.rs1use crate::records::compiler::Compiler;
2use crate::records::l_value::LValue;
3use crate::records::reg_scope::RegScope;
4use luaur_ast::records::ast_stat_function::AstStatFunction;
5
6impl Compiler {
7 pub fn compile_stat_function(&mut self, stat: *mut AstStatFunction) {
8 unsafe {
9 let stat_ref = &*stat;
10 if let reg = self.get_expr_local_reg(stat_ref.name) {
11 if reg >= 0 {
12 self.compile_expr(
13 stat_ref.func as *mut luaur_ast::records::ast_expr::AstExpr,
14 reg as u8,
15 false,
16 );
17 return;
18 }
19 }
20
21 let mut rs = self.reg_scope_compiler();
22 let reg = self.alloc_reg(stat as *mut _, 1);
23 self.compile_expr_temp(
24 stat_ref.func as *mut luaur_ast::records::ast_expr::AstExpr,
25 reg,
26 );
27 let var = self.compile_l_value(stat_ref.name, &mut rs);
28 self.compile_assign(&var, reg, stat_ref.name);
29 }
30 }
31}