plotnik_bytecode/bytecode/
entrypoint.rs1use super::instructions::StepAddr;
4use super::{StringId, TypeId};
5
6#[derive(Clone, Copy, Debug, PartialEq, Eq)]
8#[repr(C)]
9pub struct Entrypoint {
10 pub name: StringId,
12 pub target: StepAddr,
14 pub result_type: TypeId,
16 _pad: u16,
17}
18
19const _: () = assert!(std::mem::size_of::<Entrypoint>() == 8);
20
21impl Entrypoint {
22 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 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}