Compare commits

...

10 commits

Author SHA1 Message Date
Chris Cochrun
4e7e050bf6 grrrr 2024-12-05 22:39:20 -06:00
Chris Cochrun
f0dfa0c238 types are converting right 2024-12-05 22:38:08 -06:00
Chris Cochrun
fa078e8d3f updates to cargo so builds work 2024-12-05 17:31:06 -06:00
Chris Cochrun
5340d5906f adding some debug 2024-12-05 17:25:16 -06:00
Chris Cochrun
2489bf56dc adding conversions for symbols and keywords to strings 2024-11-29 21:59:33 -06:00
Chris Cochrun
c3abe2fe48 adding Value to String 2024-11-28 06:50:03 -06:00
Chris Cochrun
b4a393cce7 more conversions for values 2024-11-20 12:14:34 -06:00
Chris Cochrun
f630d138cb proper library setup 2024-11-19 17:44:51 -06:00
Chris Cochrun
5d30ca51ed adding moving to string 2024-11-19 15:25:47 -06:00
Chris Cochrun
b01eda5e0e fixing types still using color_eyre 2024-11-19 11:01:48 -06:00
4 changed files with 84 additions and 6 deletions

2
Cargo.lock generated
View file

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

View file

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

View file

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

View file

@ -1,4 +1,4 @@
use color_eyre::{eyre::eyre, Result};
use miette::{miette, Result};
use std::{num::ParseIntError, rc::Rc};
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
@ -46,7 +46,14 @@ impl Value {
pub fn apply(&self, args: LispArgs) -> Result<Value> {
match self {
Self::Function(f, _) => f(args),
_ => Err(eyre!("No function here, shouldn't call apply")),
_ => Err(miette!("No function here, shouldn't call apply")),
}
}
pub fn is_list(&self) -> bool {
match self {
Self::List(_) => true,
_ => false,
}
}
}
@ -100,6 +107,64 @@ 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)]
pub struct Symbol(pub String);
@ -129,3 +194,16 @@ impl std::fmt::Display for Keyword {
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);
}
}