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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use crate::libapi::{ClassDef, FuncDef, Module};
use crate::val::ValDef;
/// A symbol can either point to a [const value](ValDef), [another module](Module), or a [function
/// or method](FuncDef)
#[derive(Debug, Copy, Clone)]
pub enum Symbol {
Module(&'static Module),
Func(&'static FuncDef),
Class(&'static ClassDef),
Val(ValDef),
}
impl Symbol {
/// This const initializer is a convenience helpers for describing modules in static/const
/// structures where the From trait isn't allowed. Without this, the descriptions become very
/// ponderous. ie. `Symbol::Val(ValDef::U64(123))` vs. `Symbol::u64(123)`
pub const fn u64(val: u64) -> Self {
Self::Val(ValDef::U64(val))
}
pub const fn u32(val: u32) -> Self {
Self::Val(ValDef::U32(val))
}
pub const fn u16(val: u16) -> Self {
Self::Val(ValDef::U16(val))
}
pub const fn u8(val: u8) -> Self {
Self::Val(ValDef::U8(val))
}
pub const fn int_val(val: u64) -> Self {
Self::Val(ValDef::U64(val))
}
}
impl Eq for Symbol {}
impl PartialEq for Symbol {
fn eq(&self, other: &Symbol) -> bool {
match self {
Symbol::Module(a) => {
if let Symbol::Module(b) = other {
std::ptr::eq((*a) as *const Module, (*b) as *const Module)
} else {
false
}
}
Symbol::Func(a) => {
if let Symbol::Func(b) = other {
a == b
} else {
false
}
}
Symbol::Class(a) => {
if let Symbol::Class(b) = other {
std::ptr::eq((*a) as *const ClassDef, (*b) as *const ClassDef)
} else {
false
}
}
Symbol::Val(a) => {
if let Symbol::Val(b) = other {
a == b
} else {
false
}
}
}
}
}