Compare commits

..

No commits in common. "4e7e050bf6cb72f1112f18e4f2f55f1394688d4b" and "04a470d771bd86646d27ef35811fc7d6a3c7bafb" have entirely different histories.

4 changed files with 6 additions and 84 deletions

2
Cargo.lock generated
View file

@ -88,7 +88,7 @@ dependencies = [
[[package]] [[package]]
name = "crisp" name = "crisp"
version = "0.1.3" version = "0.1.0"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"miette", "miette",

View file

@ -1,10 +1,10 @@
[package] [package]
name = "crisp" name = "crisp"
version = "0.1.3" version = "0.1.0"
edition = "2021" edition = "2021"
[lib] [lib]
name = "crisp" crate-type = ["staticlib"]
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]

View file

@ -11,7 +11,7 @@ pub mod reader;
pub mod types; pub mod types;
use types::*; use types::*;
fn main() -> Result<()> { pub fn main() -> Result<()> {
let mut rl = Editor::<(), rustyline::history::DefaultHistory>::new().unwrap(); let mut rl = Editor::<(), rustyline::history::DefaultHistory>::new().unwrap();
if rl.load_history(".mal-history").is_err() { if rl.load_history(".mal-history").is_err() {
eprintln!("No previous history."); eprintln!("No previous history.");

View file

@ -1,4 +1,4 @@
use miette::{miette, Result}; use color_eyre::{eyre::eyre, Result};
use std::{num::ParseIntError, rc::Rc}; use std::{num::ParseIntError, rc::Rc};
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)] #[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
@ -46,14 +46,7 @@ impl Value {
pub fn apply(&self, args: LispArgs) -> Result<Value> { pub fn apply(&self, args: LispArgs) -> Result<Value> {
match self { match self {
Self::Function(f, _) => f(args), Self::Function(f, _) => f(args),
_ => Err(miette!("No function here, shouldn't call apply")), _ => Err(eyre!("No function here, shouldn't call apply")),
}
}
pub fn is_list(&self) -> bool {
match self {
Self::List(_) => true,
_ => false,
} }
} }
} }
@ -107,64 +100,6 @@ impl From<&i64> for Value {
} }
} }
impl From<Value> for String {
fn from(value: Value) -> Self {
match value {
Value::String(str) => str,
Value::Symbol(Symbol(str)) => str,
Value::Keyword(Keyword(str)) => str,
_ => String::default(),
}
}
}
impl From<&Value> for String {
fn from(value: &Value) -> Self {
match value {
Value::String(str) => str.clone(),
Value::Symbol(Symbol(str)) => str.clone(),
Value::Keyword(Keyword(str)) => str.clone(),
_ => String::default(),
}
}
}
impl From<Value> for i32 {
fn from(value: Value) -> Self {
match value {
Value::Number(num) => num as i32,
_ => 0,
}
}
}
impl From<Value> for i64 {
fn from(value: Value) -> Self {
match value {
Value::Number(num) => num,
_ => 0,
}
}
}
impl From<&Value> for i32 {
fn from(value: &Value) -> Self {
match value {
Value::Number(num) => *num as i32,
_ => 0,
}
}
}
impl From<&Value> for i64 {
fn from(value: &Value) -> Self {
match value {
Value::Number(num) => *num,
_ => 0,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] #[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Symbol(pub String); pub struct Symbol(pub String);
@ -194,16 +129,3 @@ impl std::fmt::Display for Keyword {
std::fmt::Display::fmt(&self.0, f) std::fmt::Display::fmt(&self.0, f)
} }
} }
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_conversions() {
let value = Value::Symbol(Symbol("c1".to_owned()));
let string = String::from("c1");
let convert = String::from(value);
assert_eq!(string, convert);
}
}