From a10f9b602eeb56876fafdcf7067d93bd90d28a92 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Mon, 27 Jun 2022 12:04:45 -0700 Subject: commit old notes on rust implementation --- rust/TODO | 10 ++++++++++ rust/notes.txt | 3 +++ rust/spectrum.rs | 33 +++++++++++++++++---------------- 3 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 rust/TODO create mode 100644 rust/notes.txt (limited to 'rust') diff --git a/rust/TODO b/rust/TODO new file mode 100644 index 0000000..6198755 --- /dev/null +++ b/rust/TODO @@ -0,0 +1,10 @@ +- basic tests +- fold in norvig's "lispy2" additions http://norvig.com/lispy2.html +- fix quote (should take an expr, not a list?) +- fix cond/cdr behavior working right; also empty tuple +- get minimal.scm to run +- if let +- use getopt +? multi-part lambdas +? apply +? re-write runge kutta with lists, not vectors diff --git a/rust/notes.txt b/rust/notes.txt new file mode 100644 index 0000000..cc35cdf --- /dev/null +++ b/rust/notes.txt @@ -0,0 +1,3 @@ +https://mgattozzi.github.io/2016/11/08/scheme-input.html + +see also: tail recursion notes impl notes from norvig diff --git a/rust/spectrum.rs b/rust/spectrum.rs index ecc00d2..73ba59d 100644 --- a/rust/spectrum.rs +++ b/rust/spectrum.rs @@ -757,8 +757,9 @@ fn repl(verbose: bool, top_env: &mut HashMap) { } } -/* This loads and evals the hard-coded prelude file (which is just scheme expressions compiled into - * the executable), saving the resulting defines in top_env. +/* Loads and evals the hard-coded prelude file (which is just scheme + * expressions compiled into the executable), saving the resulting defines in + # top_env. */ fn import_prelude(top_env: &mut HashMap) -> Result<(), String> { @@ -778,8 +779,10 @@ fn import_file(fpath: &Path, top_env: &mut HashMap) -> Resul let mut f = File::open(fpath) .expect(&format!("couldn't open file: {}", &fpath.to_str().unwrap())); + f.read_to_end(&mut raw_bytes) .expect(&format!("couldn't read file: {}", &fpath.to_str().unwrap())); + let contents = String::from_utf8(raw_bytes) .expect(&format!("UTF-8 decode error reading file: {}", &fpath.to_str().unwrap())); @@ -792,13 +795,13 @@ fn import_file(fpath: &Path, top_env: &mut HashMap) -> Resul } fn usage() { - println!("usage:\tspectrum [-h] [-v] [--no-repl] [--no-prelude] []"); - println!(""); - println!("Files will be loaded in order, then drop to REPL (unless \"--no-repl\" is passed)."); - println!("Verbose flag (\"-v\") will result in lexed tokens and parsed AST \ - being dumped to stdout (when on REPL)."); - println!("A \"prelude\" of common Scheme/LISP functions (eg, cdaddr) will \ - be loaded before any files (unless \"--no-prelude\" is passed)."); + println!( +r#"usage:\tspectrum [-h] [-v] [--no-repl] [--no-prelude] [] + +Files will be loaded in order, then drop to REPL (unless "--no-repl" is passed). +Verbose flag ("-v") will result in lexed tokens and parsed AST being dumped to stdout (when on REPL). +A "prelude" of common Scheme/LISP functions (eg, cdaddr) will be loaded before any files (unless "--no-prelude" is passed). +"#); } fn main() { @@ -806,7 +809,6 @@ fn main() { let mut verbose: bool = false; let mut no_repl: bool = false; let mut no_prelude: bool = false; - let mut top_env = HashMap::::new(); let mut file_list = Vec::::new(); @@ -828,6 +830,8 @@ fn main() { } } + let mut top_env = HashMap::::new(); + if !no_prelude { import_prelude(&mut top_env).unwrap(); } @@ -839,12 +843,9 @@ fn main() { return; } println!("Loading {}...", fname); - match import_file(&fpath, &mut top_env) { - Err(e) => { - println!("Error loading file: {}\n {}", fname, e); - return; - }, - Ok(_) => () + if let Err(e) = import_file(&fpath, &mut top_env) { + println!("Error loading file: {}\n {}", fname, e); + return; } } -- cgit v1.2.3