Compare commits
No commits in common. "a9c16ef08dde22471b813c75906c568d37fb4156" and "d864105507cd3402b768ba3c43c2337892fdd8c4" have entirely different histories.
a9c16ef08d
...
d864105507
16
Cargo.lock
generated
16
Cargo.lock
generated
|
@ -18,22 +18,8 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rlbuild"
|
name = "rlisp"
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"rlisp_library",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rlisp_library"
|
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rlisp_repl"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"rlisp_library",
|
|
||||||
]
|
|
||||||
|
|
11
Cargo.toml
Normal file → Executable file
11
Cargo.toml
Normal file → Executable file
|
@ -1,3 +1,10 @@
|
||||||
[workspace]
|
[package]
|
||||||
|
name = "rlisp"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
members = [ "rlbuild","rlisp_library", "rlisp_repl"]
|
[dependencies]
|
||||||
|
hashbrown = { version = "0.15", default-features = false, features = [
|
||||||
|
# "alloc",
|
||||||
|
"default-hasher",
|
||||||
|
] }
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "rlbuild"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2024"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
rlisp_library = { path = "../rlisp_library" }
|
|
|
@ -1,17 +0,0 @@
|
||||||
(def use-repo (fn (a b) (print a b)))
|
|
||||||
(def pkg-install (fn (a b) (print "installed" b "from" a)))
|
|
||||||
(def pkg-defaults (fn ()))
|
|
||||||
|
|
||||||
(def resolution (fn (x y fps) ()))
|
|
||||||
|
|
||||||
(def limine_res (resolution 1024 768 24))
|
|
||||||
|
|
||||||
(use-repo 'core "https://repo.ablecorp.us/core")
|
|
||||||
|
|
||||||
(pkg-install 'core 'limine)
|
|
||||||
(pkg-install 'core 'kernel-rust)
|
|
||||||
|
|
||||||
(pkg-install 'core 'sunset)
|
|
||||||
(pkg-install 'core 'ps2-driver)
|
|
||||||
|
|
||||||
(pkg-install 'core 'cluster)
|
|
|
@ -1,88 +0,0 @@
|
||||||
#![feature(slice_take)]
|
|
||||||
#![allow(special_module_name)]
|
|
||||||
|
|
||||||
// use std::io;
|
|
||||||
// use std::io::Write;
|
|
||||||
|
|
||||||
use rlisp_library::{Environ, Expr, RispError, default_env, env_get, parse_eval};
|
|
||||||
|
|
||||||
fn extend_environ<'a>(mut env: Environ<'a>) -> Environ<'a> {
|
|
||||||
env.data.insert(
|
|
||||||
"quit".to_string(),
|
|
||||||
Expr::Func(|_args: &[Expr]| -> Result<Expr, RispError> {
|
|
||||||
// TODO: let this function take in arguments
|
|
||||||
println!("Exiting.");
|
|
||||||
std::process::exit(0);
|
|
||||||
#[allow(unreachable_code)]
|
|
||||||
Err(RispError::Reason("Cannot exit process".to_string()))
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
env.data.insert(
|
|
||||||
"print".to_string(),
|
|
||||||
Expr::Func(|args: &[Expr]| -> Result<Expr, RispError> {
|
|
||||||
let mut stri = String::new();
|
|
||||||
for arg in args {
|
|
||||||
let fmted = match arg {
|
|
||||||
Expr::Str(string) => {
|
|
||||||
let string = string.clone();
|
|
||||||
// string.pop();
|
|
||||||
// string.remove(0);
|
|
||||||
|
|
||||||
format!("{}", string)
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
format!("{}", arg)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
stri.push_str(&fmted);
|
|
||||||
stri.push_str(" ")
|
|
||||||
}
|
|
||||||
println!("{}", stri);
|
|
||||||
|
|
||||||
Ok(Expr::Bool(true))
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
env
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let env = &mut default_env();
|
|
||||||
let env = &mut extend_environ(env.clone());
|
|
||||||
|
|
||||||
let cfg = include_str!("../assets/system.rlisp");
|
|
||||||
|
|
||||||
let mut complete_exprs: Vec<String> = vec![];
|
|
||||||
let mut left_parens = 0;
|
|
||||||
let mut idx_of_first_left_paran = 0;
|
|
||||||
|
|
||||||
for (i, character) in cfg.chars().enumerate() {
|
|
||||||
if character == '(' {
|
|
||||||
if left_parens == 0 {
|
|
||||||
idx_of_first_left_paran = i
|
|
||||||
}
|
|
||||||
left_parens += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
if character == ')' {
|
|
||||||
left_parens -= 1;
|
|
||||||
if left_parens == 0 {
|
|
||||||
let idx_of_last_right_paran = i + 1;
|
|
||||||
|
|
||||||
complete_exprs
|
|
||||||
.push(cfg[idx_of_first_left_paran..idx_of_last_right_paran].to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for expr in complete_exprs {
|
|
||||||
println!("{}", expr);
|
|
||||||
match parse_eval(expr, env) {
|
|
||||||
Ok(res) => println!("-> {}", res),
|
|
||||||
Err(e) => match e {
|
|
||||||
RispError::Reason(msg) => println!("Found Error {}", msg),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "rlisp_library"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2024"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
hashbrown = { version = "0.15", default-features = false, features = [
|
|
||||||
# "alloc",
|
|
||||||
"default-hasher",
|
|
||||||
] }
|
|
|
@ -1,7 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "rlisp_repl"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2024"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
rlisp_library = { path = "../rlisp_library" }
|
|
|
@ -3,13 +3,13 @@ use alloc::string::String;
|
||||||
use alloc::string::ToString;
|
use alloc::string::ToString;
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
|
use crate::environ::env_get;
|
||||||
use crate::Environ;
|
use crate::Environ;
|
||||||
use crate::Expr;
|
use crate::Expr;
|
||||||
use crate::HashMap;
|
use crate::HashMap;
|
||||||
use crate::RLambda;
|
use crate::RLambda;
|
||||||
use crate::Rc;
|
use crate::Rc;
|
||||||
use crate::RispError;
|
use crate::RispError;
|
||||||
use crate::environ::env_get;
|
|
||||||
|
|
||||||
pub fn eval(exp: &Expr, env: &mut Environ) -> Result<Expr, RispError> {
|
pub fn eval(exp: &Expr, env: &mut Environ) -> Result<Expr, RispError> {
|
||||||
match exp {
|
match exp {
|
||||||
|
@ -45,7 +45,7 @@ pub fn eval(exp: &Expr, env: &mut Environ) -> Result<Expr, RispError> {
|
||||||
}
|
}
|
||||||
Expr::Func(_) => Err(RispError::Reason("unexpected form".to_string())),
|
Expr::Func(_) => Err(RispError::Reason("unexpected form".to_string())),
|
||||||
Expr::Lambda(_) => Err(RispError::Reason("unexpected form".to_string())),
|
Expr::Lambda(_) => Err(RispError::Reason("unexpected form".to_string())),
|
||||||
Expr::Atom(_) => Ok(exp.clone()),
|
// Expr::Nil => Err(RispError::Reason("unexpected nil".to_string())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,6 @@ fn eval_lambda_args(arg_forms: &[Expr]) -> Result<Expr, RispError> {
|
||||||
let params_exp = arg_forms
|
let params_exp = arg_forms
|
||||||
.first()
|
.first()
|
||||||
.ok_or(RispError::Reason("expected args form".to_string()))?;
|
.ok_or(RispError::Reason("expected args form".to_string()))?;
|
||||||
|
|
||||||
let body_exp = arg_forms
|
let body_exp = arg_forms
|
||||||
.get(1)
|
.get(1)
|
||||||
.ok_or(RispError::Reason("expected second form".to_string()))?;
|
.ok_or(RispError::Reason("expected second form".to_string()))?;
|
|
@ -1,23 +1,28 @@
|
||||||
#![feature(slice_take)]
|
#![feature(slice_take)]
|
||||||
#![allow(special_module_name)]
|
#![allow(special_module_name)]
|
||||||
|
#![feature(build_hasher_default_const_new)]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
|
||||||
use core::num::ParseFloatError;
|
use core::num::ParseFloatError;
|
||||||
|
// use std::hash::DefaultHasher;
|
||||||
|
|
||||||
pub extern crate alloc;
|
use alloc::fmt::format;
|
||||||
|
|
||||||
use alloc::format;
|
|
||||||
use alloc::rc::Rc;
|
use alloc::rc::Rc;
|
||||||
use alloc::string::String;
|
use alloc::string::String;
|
||||||
use alloc::string::ToString;
|
use alloc::string::ToString;
|
||||||
use alloc::vec;
|
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
pub use hashbrown::hash_map::HashMap;
|
pub use hashbrown::hash_map::HashMap;
|
||||||
|
pub extern crate alloc;
|
||||||
|
use alloc::format;
|
||||||
|
use alloc::vec;
|
||||||
|
// pub use alloc::;
|
||||||
|
// pub use core::rc::Rc;
|
||||||
|
|
||||||
mod environ;
|
mod environ;
|
||||||
pub use environ::Environ;
|
|
||||||
pub use environ::default_env;
|
pub use environ::default_env;
|
||||||
pub use environ::env_get;
|
pub use environ::env_get;
|
||||||
|
pub use environ::Environ;
|
||||||
|
|
||||||
mod parser;
|
mod parser;
|
||||||
pub use parser::parse;
|
pub use parser::parse;
|
||||||
|
@ -33,7 +38,6 @@ pub enum RispError {
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum Expr {
|
pub enum Expr {
|
||||||
Bool(bool),
|
Bool(bool),
|
||||||
Atom(String),
|
|
||||||
Symbol(String),
|
Symbol(String),
|
||||||
Number(f64),
|
Number(f64),
|
||||||
Str(String),
|
Str(String),
|
||||||
|
@ -65,7 +69,6 @@ impl fmt::Display for Expr {
|
||||||
Lambda(lambda) => {
|
Lambda(lambda) => {
|
||||||
format!("(fn {} {})", lambda.params_exp, lambda.body_exp)
|
format!("(fn {} {})", lambda.params_exp, lambda.body_exp)
|
||||||
}
|
}
|
||||||
Atom(a) => format!("{}", a),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
write!(f, "{}", str)
|
write!(f, "{}", str)
|
|
@ -1,10 +1,13 @@
|
||||||
#![feature(slice_take)]
|
#![feature(slice_take)]
|
||||||
#![allow(special_module_name)]
|
#![allow(special_module_name)]
|
||||||
|
#![feature(build_hasher_default_const_new)]
|
||||||
|
// #![no_std]
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
use rlisp_library::{Environ, Expr, RispError, default_env, env_get, parse_eval};
|
mod lib;
|
||||||
|
use lib::*;
|
||||||
|
|
||||||
fn slurp_expr() -> String {
|
fn slurp_expr() -> String {
|
||||||
let mut expr = String::new();
|
let mut expr = String::new();
|
||||||
|
@ -51,7 +54,7 @@ fn main() {
|
||||||
let env = &mut default_env();
|
let env = &mut default_env();
|
||||||
let env = &mut extend_environ(env.clone());
|
let env = &mut extend_environ(env.clone());
|
||||||
loop {
|
loop {
|
||||||
let prompt = env_get("prompt", env).unwrap_or(Expr::Symbol("rlisp => ".to_string()));
|
let prompt = env_get("prompt", env).unwrap_or(lib::Expr::Symbol("rlisp => ".to_string()));
|
||||||
print!("{}", prompt);
|
print!("{}", prompt);
|
||||||
let _ = std::io::stdout().flush();
|
let _ = std::io::stdout().flush();
|
||||||
let expr = slurp_expr();
|
let expr = slurp_expr();
|
|
@ -2,12 +2,12 @@ use alloc::string::String;
|
||||||
use alloc::string::ToString;
|
use alloc::string::ToString;
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
|
use crate::evaluate::eval;
|
||||||
|
use crate::read_seq;
|
||||||
use crate::Environ;
|
use crate::Environ;
|
||||||
use crate::Expr;
|
use crate::Expr;
|
||||||
use crate::ParseFloatError;
|
use crate::ParseFloatError;
|
||||||
use crate::RispError;
|
use crate::RispError;
|
||||||
use crate::evaluate::eval;
|
|
||||||
use crate::read_seq;
|
|
||||||
|
|
||||||
pub fn tokenize(expr: String) -> Vec<String> {
|
pub fn tokenize(expr: String) -> Vec<String> {
|
||||||
expr.replace("(", " ( ")
|
expr.replace("(", " ( ")
|
||||||
|
@ -55,8 +55,6 @@ fn parse_atom(token: &str) -> Expr {
|
||||||
stri.pop();
|
stri.pop();
|
||||||
|
|
||||||
Str(stri)
|
Str(stri)
|
||||||
} else if token.starts_with("'") {
|
|
||||||
Atom(token.to_string().clone())
|
|
||||||
} else {
|
} else {
|
||||||
Symbol(token.to_string().clone())
|
Symbol(token.to_string().clone())
|
||||||
}
|
}
|
Loading…
Reference in a new issue