lua_semantics/expression/
function.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::{cell::RefCell, rc::Rc};

use crate::{Block, VariableInfo};

use super::ExprLocalVariable;

/// constructing `function`. not a function object.
#[derive(Debug, Clone)]
pub struct FunctionDefinition {
    /// stack offset of arguments
    pub args: Vec<Rc<RefCell<VariableInfo>>>,
    /// if true, this function is variadic
    pub variadic: bool,
    /// function body
    pub body: Block,
}

impl FunctionDefinition {
    pub fn new(
        args: Vec<Rc<RefCell<VariableInfo>>>,
        variadic: bool,
        body: Block,
        // stack_size: usize,
    ) -> Self {
        Self {
            args,
            variadic,
            body,
            // stack_size,
        }
    }
}

#[derive(Debug, Clone)]
pub struct ExprFunctionObject {
    /// when constructing function object, copy upvalues from these sources
    pub upvalues_source: Vec<ExprLocalVariable>,

    /// function definition
    pub definition: FunctionDefinition,
}

impl ExprFunctionObject {
    pub fn new(upvalues_source: Vec<ExprLocalVariable>, definition: FunctionDefinition) -> Self {
        Self {
            upvalues_source,
            definition,
        }
    }
}