added basic datatypes

This commit is contained in:
Erin 2022-08-05 23:41:09 +02:00 committed by ondra05
parent 5664e1309a
commit c3c8c23956
6 changed files with 79 additions and 2 deletions

View file

@ -0,0 +1,2 @@
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Function;

View file

@ -0,0 +1,2 @@
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct List;

View 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),
}

View 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)
}
}