stak_code/
lib.rs

1//! Bytecodes for Stak Scheme.
2
3#![no_std]
4
5#[cfg(feature = "alloc")]
6extern crate alloc;
7#[cfg(test)]
8extern crate std;
9
10#[cfg(feature = "alloc")]
11mod decode;
12#[cfg(feature = "alloc")]
13mod encode;
14#[cfg(feature = "alloc")]
15mod error;
16mod ir;
17
18#[cfg(feature = "alloc")]
19pub use decode::decode;
20#[cfg(feature = "alloc")]
21pub use encode::encode;
22#[cfg(feature = "alloc")]
23pub use error::Error;
24pub use ir::*;
25
26/// A number of bits required to encode an instruction in bytecodes.
27pub const INSTRUCTION_BITS: u64 = 4;
28/// A mask for instruction bits in bytecodes.
29pub const INSTRUCTION_MASK: u8 = (1 << INSTRUCTION_BITS) - 1;
30/// A base for integer encoding in bytecodes.
31pub const INTEGER_BASE: u64 = i8::MAX as u64 + 1;
32/// A base for short integer encoding in bytecodes.
33pub const SHORT_INTEGER_BASE: u64 = 1 << (8 - INSTRUCTION_BITS - 1);
34
35// Those bytes are not used in UTF-8.
36/// A symbol separator.
37pub const SYMBOL_SEPARATOR: u8 = 0xFE;
38/// A symbol terminator.
39pub const SYMBOL_TERMINATOR: u8 = 0xFF;
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn mask() {
47        assert_eq!(INSTRUCTION_MASK, 0b1111);
48    }
49}