plotnik_bytecode/bytecode/
entrypoint.rs

1//! Entrypoint section types.
2
3use super::instructions::StepAddr;
4use super::{StringId, TypeId};
5
6/// Named query definition entry point (8 bytes).
7#[derive(Clone, Copy, Debug, PartialEq, Eq)]
8#[repr(C)]
9pub struct Entrypoint {
10    /// Definition name.
11    pub name: StringId,
12    /// Starting instruction address.
13    pub target: StepAddr,
14    /// Result type.
15    pub result_type: TypeId,
16    _pad: u16,
17}
18
19const _: () = assert!(std::mem::size_of::<Entrypoint>() == 8);
20
21impl Entrypoint {
22    /// Create a new entrypoint.
23    pub fn new(name: StringId, target: StepAddr, result_type: TypeId) -> Self {
24        Self {
25            name,
26            target,
27            result_type,
28            _pad: 0,
29        }
30    }
31
32    /// Decode from 8 bytes (crate-internal deserialization).
33    pub(crate) fn from_bytes(bytes: &[u8]) -> Self {
34        Self {
35            name: StringId::new(u16::from_le_bytes([bytes[0], bytes[1]])),
36            target: u16::from_le_bytes([bytes[2], bytes[3]]),
37            result_type: TypeId(u16::from_le_bytes([bytes[4], bytes[5]])),
38            _pad: 0,
39        }
40    }
41
42    pub fn name(&self) -> StringId {
43        self.name
44    }
45    pub fn target(&self) -> StepAddr {
46        self.target
47    }
48    pub fn result_type(&self) -> TypeId {
49        self.result_type
50    }
51}