aboutsummaryrefslogtreecommitdiffstats
path: root/rust/spectrum.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/spectrum.rs')
-rw-r--r--rust/spectrum.rs33
1 files changed, 17 insertions, 16 deletions
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;
}
}