1
0

Add built-in identifiers

This commit is contained in:
Jeff 2024-02-15 17:04:34 -05:00
parent edded5043d
commit 50a7a7aca1
2 changed files with 33 additions and 13 deletions

View File

@ -10,22 +10,42 @@ pub fn all_built_in_identifiers() -> impl Iterator<Item = BuiltInIdentifier> {
static OPTION: OnceLock<Identifier> = OnceLock::new();
static NONE: OnceLock<Identifier> = OnceLock::new();
static SOME: OnceLock<Identifier> = OnceLock::new();
static RESULT: OnceLock<Identifier> = OnceLock::new();
static OK: OnceLock<Identifier> = OnceLock::new();
static ERROR: OnceLock<Identifier> = OnceLock::new();
#[derive(Sequence, Debug)]
pub enum BuiltInIdentifier {
Option,
None,
Some,
Result,
Ok,
Error,
}
impl BuiltInIdentifier {
pub fn get(&self) -> Identifier {
pub fn get(&self) -> &Identifier {
match self {
BuiltInIdentifier::Option => OPTION
.get_or_init(|| Identifier::from_raw_parts(Arc::new("Option".to_string())))
.clone(),
BuiltInIdentifier::None => NONE
.get_or_init(|| Identifier::from_raw_parts(Arc::new("None".to_string())))
.clone(),
BuiltInIdentifier::Option => {
OPTION.get_or_init(|| Identifier::from_raw_parts(Arc::new("Option".to_string())))
}
BuiltInIdentifier::None => {
NONE.get_or_init(|| Identifier::from_raw_parts(Arc::new("None".to_string())))
}
BuiltInIdentifier::Some => {
SOME.get_or_init(|| Identifier::from_raw_parts(Arc::new("Some".to_string())))
}
BuiltInIdentifier::Result => {
RESULT.get_or_init(|| Identifier::from_raw_parts(Arc::new("Result".to_string())))
}
BuiltInIdentifier::Ok => {
OK.get_or_init(|| Identifier::from_raw_parts(Arc::new("Ok".to_string())))
}
BuiltInIdentifier::Error => {
ERROR.get_or_init(|| Identifier::from_raw_parts(Arc::new("Error".to_string())))
}
}
}
}

View File

@ -35,16 +35,16 @@ pub mod struct_instance;
/// value that can be treated as any other.
#[derive(Debug, Clone)]
pub enum Value {
Boolean(bool),
Enum(EnumInstance),
Float(f64),
Function(Function),
Integer(i64),
List(List),
Map(Map),
Function(Function),
String(String),
Float(f64),
Integer(i64),
Boolean(bool),
Range(RangeInclusive<i64>),
String(String),
Struct(StructInstance),
Enum(EnumInstance),
}
impl Value {