added basic datatypes
This commit is contained in:
parent
5664e1309a
commit
c3c8c23956
|
@ -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:
|
||||
|
|
2
src/interpreter/value/function.rs
Normal file
2
src/interpreter/value/function.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Function;
|
2
src/interpreter/value/list.rs
Normal file
2
src/interpreter/value/list.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct List;
|
25
src/interpreter/value/mod.rs
Normal file
25
src/interpreter/value/mod.rs
Normal file
|
@ -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<f64>;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum Value<'s> {
|
||||
List(List),
|
||||
Vector(Rc<Vec<Self>>),
|
||||
Map(Rc<BTreeMap<Self, Self>>),
|
||||
Symbol(Str<'s>),
|
||||
Keyword(Str<'s>),
|
||||
Number(OrderedF64),
|
||||
String(Str<'s>),
|
||||
Function(Function),
|
||||
Macro(Function),
|
||||
}
|
||||
|
48
src/interpreter/value/string.rs
Normal file
48
src/interpreter/value/string.rs
Normal file
|
@ -0,0 +1,48 @@
|
|||
use std::{rc::Rc, ops::Deref, fmt::Display};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Str<'a> {
|
||||
Borrowed(&'a str),
|
||||
Shared(Rc<str>),
|
||||
}
|
||||
|
||||
impl<'a> From<&'a str> for Str<'a> {
|
||||
fn from(x: &'a str) -> Self {
|
||||
Self::Borrowed(x)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<Rc<str>> for Str<'a> {
|
||||
fn from(x: Rc<str>) -> 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)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue