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
51
52
53
54
55
56
57
58
use crate::parser::lvalue::DeclType;
use crate::codegen::consts::ConstID;
use crate::codegen::opcodes::{LocalIndex, UpvalueIndex};
use crate::runtime::function::Signature;
pub type FunctionID = u16;
#[derive(Debug)]
pub struct FunctionProto {
signature: Signature,
upvalues: Box<[UpvalueTarget]>,
fun_id: FunctionID,
}
impl FunctionProto {
pub(super) fn new(fun_id: FunctionID, signature: Signature, upvalues: Box<[UpvalueTarget]>) -> Self {
Self {
fun_id,
signature,
upvalues,
}
}
pub fn fun_id(&self) -> FunctionID { self.fun_id }
pub fn signature(&self) -> &Signature { &self.signature }
pub fn upvalues(&self) -> &[UpvalueTarget] { &self.upvalues }
}
#[derive(Debug, Clone, Copy)]
pub enum UpvalueTarget {
Local(LocalIndex),
Upvalue(UpvalueIndex),
}
#[derive(Debug, Clone)]
pub struct UnloadedFunction {
pub signature: UnloadedSignature,
pub upvalues: Box<[UpvalueTarget]>,
pub fun_id: FunctionID,
}
#[derive(Clone, Debug)]
pub struct UnloadedSignature {
pub name: Option<ConstID>,
pub required: Box<[UnloadedParam]>,
pub default: Box<[UnloadedParam]>,
pub variadic: Option<UnloadedParam>,
}
#[derive(Clone, Debug)]
pub struct UnloadedParam {
pub name: ConstID,
pub decl: DeclType,
}