aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2022-06-27 12:04:45 -0700
committerbnewbold <bnewbold@robocracy.org>2022-06-27 12:04:45 -0700
commita10f9b602eeb56876fafdcf7067d93bd90d28a92 (patch)
tree28853823aa808ee58f229f4489f87efe6a7e9b6a
parent553a6fc04dfcb6f07cdcba5534eeed4ed708858a (diff)
downloadspectrum-a10f9b602eeb56876fafdcf7067d93bd90d28a92.tar.gz
spectrum-a10f9b602eeb56876fafdcf7067d93bd90d28a92.zip
commit old notes on rust implementationHEADmaster
-rw-r--r--rust/TODO10
-rw-r--r--rust/notes.txt3
-rw-r--r--rust/spectrum.rs33
3 files changed, 30 insertions, 16 deletions
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<String, SchemeExpr>) {
}
}
-/* 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<String, SchemeExpr>) -> Result<(), String> {
@@ -778,8 +779,10 @@ fn import_file(fpath: &Path, top_env: &mut HashMap<String, SchemeExpr>) -> 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<String, SchemeExpr>) -> Resul
}
fn usage() {
- println!("usage:\tspectrum [-h] [-v] [--no-repl] [--no-prelude] [<files>]");
- 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>]
+
+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::<String, SchemeExpr>::new();
let mut file_list = Vec::<String>::new();
@@ -828,6 +830,8 @@ fn main() {
}
}
+ let mut top_env = HashMap::<String, SchemeExpr>::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;
}
}