kamo/types/parser/code.rs
1//! # Binary Type Code and Predefined Types
2//!
3//! This module defines the binary type code and some predefined types.
4
5use crate::types::Type;
6
7/// The nil type which represents the absence of a value.
8pub const NIL: u8 = 0x00;
9/// The void type which represents the absence of a value.
10pub const VOID: u8 = 0x01;
11/// The any type which represents any typed value. This excludes the void type.
12pub const ANY: u8 = 0x02;
13/// The type type which represents a type value.
14pub const TYPE: u8 = 0x03;
15/// The bool type which represents a boolean value.
16pub const BOOL: u8 = 0x04;
17/// The char type which represents a character value.
18pub const CHAR: u8 = 0x05;
19/// The int type which represents an integer value.
20pub const INT: u8 = 0x06;
21/// The float type which represents a floating-point value.
22pub const FLOAT: u8 = 0x07;
23/// The string type which represents a symbol value, also known as an interned
24/// string.
25pub const SYMBOL: u8 = 0x08;
26/// The binary type which represents a byte array value.
27pub const BINARY: u8 = 0x09;
28/// The array type which represents a homogeneous array value.
29pub const ARRAY: u8 = 0x0a;
30/// The pair type which represents a cons cell value.
31pub const PAIR: u8 = 0x0b;
32/// The lambda type which represents a function value.
33pub const LAMBDA: u8 = 0x0c;
34/// The option type which represents an optional value. The some variant is
35/// a filled type and the none variant is a nil type.
36pub const OPTION: u8 = 0x0d;
37/// The union type which represents a sequence of at least two types, which
38/// can be used alternatively (or-ed sequence).
39pub const UNION: u8 = 0x0e;
40
41/// Marker for the start of a variadic type.
42pub const VARIADIC: u8 = 0x40;
43/// Marker for the start of a return type.
44pub const RETURN: u8 = 0x41;
45/// Marker for the end of a union type.
46pub const END: u8 = 0x7f;
47
48/// Marker for the start of a fixed length of an array with a maximum length of
49/// 15 elements (4-bit length field)
50pub const FIXED0: u8 = 0x80;
51pub const FIXED0_MAX: u8 = 0x8f;
52/// Marker for the start of a fixed length of an array with a maximum length of
53/// 4095 elements (12-bit length field)
54pub const FIXED1: u8 = 0x90;
55pub const FIXED1_MAX: u8 = 0x9f;
56/// Marker for the start of a fixed length of an array with a maximum length of
57/// 1048575 elements (20-bit length field)
58pub const FIXED2: u8 = 0xa0;
59pub const FIXED2_MAX: u8 = 0xaf;
60/// Marker for the start of a fixed length of an array with a maximum length of
61/// 268435455 elements (28-bit length field)
62pub const FIXED3: u8 = 0xb0;
63pub const FIXED3_MAX: u8 = 0xbf;
64/// Marker for the start of a fixed length of an array with a maximum length of
65/// 68719476735 elements (36-bit length field)
66pub const FIXED4: u8 = 0xc0;
67pub const FIXED4_MAX: u8 = 0xcf;
68
69lazy_static! {
70 /// Predifined nil type.
71 pub static ref T_NIL: Type = unsafe { Type::new_unchecked([NIL]) };
72 /// Predifined void type.
73 pub static ref T_VOID: Type = unsafe { Type::new_unchecked([VOID]) };
74 /// Predifined any type.
75 pub static ref T_ANY: Type = unsafe { Type::new_unchecked([ANY]) };
76 /// Predifined type type.
77 pub static ref T_TYPE: Type = unsafe { Type::new_unchecked([TYPE]) };
78 /// Predifined bool type.
79 pub static ref T_BOOL: Type = unsafe { Type::new_unchecked([BOOL]) };
80 /// Predifined char type.
81 pub static ref T_CHAR: Type = unsafe { Type::new_unchecked([CHAR]) };
82 /// Predifined int type.
83 pub static ref T_INT: Type = unsafe { Type::new_unchecked([INT]) };
84 /// Predifined float type.
85 pub static ref T_FLOAT: Type = unsafe { Type::new_unchecked([FLOAT]) };
86 /// Predifined string type.
87 pub static ref T_STRING: Type = unsafe { Type::new_unchecked([ARRAY, CHAR]) };
88 /// Predifined symbol type.
89 pub static ref T_SYMBOL: Type = unsafe { Type::new_unchecked([SYMBOL]) };
90 /// Predifined binary type.
91 pub static ref T_BINARY: Type = unsafe { Type::new_unchecked([BINARY]) };
92 /// Predifined vector type an array of any type.
93 pub static ref T_VECTOR: Type = unsafe { Type::new_unchecked([ARRAY, ANY]) };
94 /// Predifined list type a pair of any type and an optional list type.
95 pub static ref T_LIST: Type = unsafe { Type::new_unchecked([PAIR, OPTION, ANY, OPTION, ANY]) };
96}