sphinx/codegen/
funproto.rs1use crate::language::Access;
2use crate::codegen::consts::ConstID;
3use crate::codegen::opcodes::{LocalIndex, UpvalueIndex};
4use crate::runtime::function::Signature;
5
6
7pub type FunctionID = u16;
8
9#[derive(Debug)]
10pub struct FunctionProto {
11 signature: Signature,
12 upvalues: Box<[UpvalueTarget]>,
13 fun_id: FunctionID,
14}
15
16impl FunctionProto {
17 pub(super) fn new(fun_id: FunctionID, signature: Signature, upvalues: Box<[UpvalueTarget]>) -> Self {
18 Self {
19 fun_id,
20 signature,
21 upvalues,
22 }
23 }
24
25 pub fn fun_id(&self) -> FunctionID { self.fun_id }
26 pub fn signature(&self) -> &Signature { &self.signature }
27 pub fn upvalues(&self) -> &[UpvalueTarget] { &self.upvalues }
28}
29
30
31#[derive(Debug, Clone, Copy)]
32pub enum UpvalueTarget {
33 Local(LocalIndex),
34 Upvalue(UpvalueIndex),
35}
36
37
38#[derive(Debug, Clone)]
39pub struct UnloadedFunction {
40 pub signature: UnloadedSignature,
41 pub upvalues: Box<[UpvalueTarget]>,
42 pub fun_id: FunctionID,
43}
44
45#[derive(Clone, Debug)]
46pub struct UnloadedSignature {
47 pub name: Option<ConstID>,
48 pub required: Box<[UnloadedParam]>,
49 pub default: Box<[UnloadedParam]>,
50 pub variadic: Option<UnloadedParam>,
51}
52
53
54#[derive(Clone, Debug)]
55pub struct UnloadedParam {
56 pub name: ConstID,
57 pub mode: Access,
58}