use crate::instr::Builtin;
#[derive(Debug)]
pub(super) enum ExpDesc {
Prefix(PrefixExp),
Vararg,
Other,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(super) struct CallSite(u32);
impl CallSite {
const LINE_MASK: u32 = (1 << 24) - 1;
pub(super) fn new(num_args: u8, line: u32) -> Self {
Self((u32::from(num_args) << 24) | line.min(Self::LINE_MASK))
}
pub(super) fn num_args(self) -> u8 {
(self.0 >> 24) as u8
}
pub(super) fn line(self) -> u32 {
self.0 & Self::LINE_MASK
}
}
#[allow(variant_size_differences)]
#[derive(Clone, Debug)]
pub(super) enum PrefixExp {
Place(PlaceExp),
FunctionCall(CallSite),
Parenthesized,
}
#[derive(Clone, Debug)]
pub(super) enum PlaceExp {
Local(u8),
Upvalue(u8),
Global(u16),
Builtin(Builtin),
TableIndex,
FieldAccess(u16),
}
impl From<PrefixExp> for ExpDesc {
fn from(exp: PrefixExp) -> Self {
Self::Prefix(exp)
}
}
impl From<PlaceExp> for PrefixExp {
fn from(exp: PlaceExp) -> Self {
Self::Place(exp)
}
}