Speed sketch beginnings of a Rust implementation of new stripped-down Scheme-like Kraken

This commit is contained in:
2023-02-07 02:07:53 -05:00
parent 3807381ceb
commit 60dad101f8
7 changed files with 715 additions and 0 deletions

37
kr/src/ast.rs Normal file
View File

@@ -0,0 +1,37 @@
use std::rc::Rc;
#[derive(Debug)]
pub enum Form {
Int(i32),
Symbol(String),
Pair(Rc<Form>,Rc<Form>),
PrimComb(String, fn(Rc<Form>, Rc<Form>) -> Rc<Form>),
Nil,
}
impl Form {
pub fn int(&self) -> Option<i32> {
match self {
Form::Int(i) => Some(*i),
_ => None,
}
}
pub fn sym(&self) -> Option<&str> {
match self {
Form::Symbol(s) => Some(s),
_ => None,
}
}
pub fn car(&self) -> Option<Rc<Form>> {
match self {
Form::Pair(car, cdr) => Some(Rc::clone(car)),
_ => None,
}
}
pub fn cdr(&self) -> Option<Rc<Form>> {
match self {
Form::Pair(car, cdr) => Some(Rc::clone(cdr)),
_ => None,
}
}
}