diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index 51eaba8..b5c3d37 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -1,8 +1,8 @@ //! **bodge** //! (third-person singular simple present bodges, present participle **bodging**, //! simple past and past participle **bodged**) -//! 1. (Britain) To do a clumsy or inelegant job, usually as a temporary repair; mend, patch up, repair. -//! 2. To work green wood using traditional country methods; to perform the craft of a bodger. +//! 1. (Britain) To do a clumsy or inelegant job, usually as a temporary repair; mend, patch up, repair. +//! 2. To work green wood using traditional country methods; to perform the craft of a bodger. //! //! A simple tree-walk interpreter intended for testing purposes. //! To be replaced by VM soon™️ :ferrisClueless: diff --git a/src/interpreter/value.rs b/src/interpreter/value.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/interpreter/value/function.rs b/src/interpreter/value/function.rs new file mode 100644 index 0000000..f3a0e28 --- /dev/null +++ b/src/interpreter/value/function.rs @@ -0,0 +1,2 @@ +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct Function; diff --git a/src/interpreter/value/list.rs b/src/interpreter/value/list.rs new file mode 100644 index 0000000..da8868a --- /dev/null +++ b/src/interpreter/value/list.rs @@ -0,0 +1,2 @@ +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct List; diff --git a/src/interpreter/value/mod.rs b/src/interpreter/value/mod.rs new file mode 100644 index 0000000..6505580 --- /dev/null +++ b/src/interpreter/value/mod.rs @@ -0,0 +1,25 @@ +mod function; +mod list; +mod string; + +pub use function::Function; +pub use list::List; +pub use string::Str; + +use std::{collections::BTreeMap, rc::Rc}; + +pub type OrderedF64 = ordered_float::OrderedFloat; + +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum Value<'s> { + List(List), + Vector(Rc>), + Map(Rc>), + Symbol(Str<'s>), + Keyword(Str<'s>), + Number(OrderedF64), + String(Str<'s>), + Function(Function), + Macro(Function), +} + diff --git a/src/interpreter/value/string.rs b/src/interpreter/value/string.rs new file mode 100644 index 0000000..52cc22a --- /dev/null +++ b/src/interpreter/value/string.rs @@ -0,0 +1,48 @@ +use std::{rc::Rc, ops::Deref, fmt::Display}; + +#[derive(Debug, Clone)] +pub enum Str<'a> { + Borrowed(&'a str), + Shared(Rc), +} + +impl<'a> From<&'a str> for Str<'a> { + fn from(x: &'a str) -> Self { + Self::Borrowed(x) + } +} + +impl<'a> From> for Str<'a> { + fn from(x: Rc) -> Self { + Self::Shared(x) + } +} + +impl<'a> Deref for Str<'a> { + type Target = str; + + fn deref(&self) -> &Self::Target { + match self { + Self::Borrowed(b) => b, + Self::Shared(s) => s, + } + } +} + +impl<'a> PartialEq for Str<'a> { + fn eq(&self, other: &Self) -> bool { + **self == **other + } +} + +impl<'a> Eq for Str<'a> {} + +impl<'a> Display for Str<'a> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Str::Borrowed(b) => *b, + Str::Shared(s) => s, + } + .fmt(f) + } +}