moco_vm/
cons.rs

1use crate::{Value, integer::Integer};
2
3/// A tag.
4pub type Tag = u8;
5
6/// A cons pointer.
7pub struct Cons<V>(V);
8
9impl<V: Value> Cons<V> {
10    /// Returns an index.
11    pub fn index(self) -> usize {
12        self.0.to_pointer().to_usize() >> Tag::BITS as usize
13    }
14
15    /// Returns a tag.
16    pub fn tag(self) -> Tag {
17        self.0.to_pointer().to_usize() as _
18    }
19
20    /// Creates a cons pointer.
21    pub const fn new(value: V) -> Self {
22        Self(value)
23    }
24
25    /// Converts a cons pointer to a value.
26    pub const fn to_value(self) -> V {
27        self.0
28    }
29}