From 50a7a7aca16b0c74423403746a32c12f983ff7e9 Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 15 Feb 2024 17:04:34 -0500 Subject: [PATCH] Add built-in identifiers --- src/built_in_identifiers.rs | 34 +++++++++++++++++++++++++++------- src/value/mod.rs | 12 ++++++------ 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/built_in_identifiers.rs b/src/built_in_identifiers.rs index c6f5061..8659ad5 100644 --- a/src/built_in_identifiers.rs +++ b/src/built_in_identifiers.rs @@ -10,22 +10,42 @@ pub fn all_built_in_identifiers() -> impl Iterator { static OPTION: OnceLock = OnceLock::new(); static NONE: OnceLock = OnceLock::new(); +static SOME: OnceLock = OnceLock::new(); +static RESULT: OnceLock = OnceLock::new(); +static OK: OnceLock = OnceLock::new(); +static ERROR: OnceLock = 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()))) + } } } } diff --git a/src/value/mod.rs b/src/value/mod.rs index 2b256dd..7249521 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -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), + String(String), Struct(StructInstance), - Enum(EnumInstance), } impl Value {