1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use core::mem;
use string_interner::Symbol;
use crate::language::{IntType, FloatType, InternSymbol};
use crate::runtime::errors::ErrorKind;
pub type ConstID = u16;
pub type StringID = usize;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Constant {
Integer(IntType),
Float([u8; mem::size_of::<FloatType>()]),
String(StringID),
Error { error: ErrorKind, message: StringID },
}
impl From<IntType> for Constant {
fn from(value: IntType) -> Self { Self::Integer(value) }
}
impl From<FloatType> for Constant {
fn from(value: FloatType) -> Self { Self::Float(value.to_le_bytes()) }
}
impl From<InternSymbol> for Constant {
fn from(symbol: InternSymbol) -> Self { Self::String(symbol.to_usize()) }
}