diff --git a/README.md b/README.md index 3c1ab93..a6605ab 100644 --- a/README.md +++ b/README.md @@ -57,12 +57,12 @@ and not as representative of my skills as a programmer today as this one. ## What is currently being tested? -Currently when testing the compiler I run `./libtest.sh fibonacci` or -`./libtest.sh arithmetic`. +Currently when testing the compiler I run `./libtest.sh reid_src/{file}.reid`, +where the `{file}` is one of the various examples I've written to help me test +features of the compiler. -What `./libtest.sh $1` does, is it compiles and runs the rust example found with -name `$1`, which may exist in any of the two projects. The two mentioned above -are in `reid/examples`. +What `./libtest.sh $1` does, is it compiles and runs the rust example found at +path `$1`. Some pre-existing examples can be found in [`reid_src`](./reid_src) All examples currently end up producing a `hello.o` and `hello.asm` file to the root directory, which is then linked with `ldd` to produce a `main`, which is diff --git a/libtest.sh b/libtest.sh index 715b59a..c5bf6c8 100755 --- a/libtest.sh +++ b/libtest.sh @@ -6,7 +6,7 @@ # Do note this file is extremely simply for my own personal convenience export .env -cargo run --example $1 && \ +cargo run --example cli $1 && \ # clang hello.o -o main && \ ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 \ -o main /usr/lib/crt1.o hello.o -lc && \ diff --git a/reid/examples/array.rs b/reid/examples/array.rs deleted file mode 100644 index 9952667..0000000 --- a/reid/examples/array.rs +++ /dev/null @@ -1,11 +0,0 @@ -use reid::compile; - -pub static ARRAY: &str = include_str!("./reid/array.reid"); - -fn main() { - let text = match compile(ARRAY) { - Ok(t) => t, - Err(e) => panic!("{}", e), - }; - println!("{}", text); -} diff --git a/reid/examples/cli.rs b/reid/examples/cli.rs new file mode 100644 index 0000000..45a993b --- /dev/null +++ b/reid/examples/cli.rs @@ -0,0 +1,18 @@ +use std::{env, fs}; + +use reid::compile; + +fn main() -> Result<(), std::io::Error> { + let args: Vec = env::args().collect(); + if let Some(filename) = args.get(1) { + let text = fs::read_to_string(filename)?; + let output = match compile(&text) { + Ok(t) => t, + Err(e) => panic!("{}", e), + }; + println!("{}", output); + } else { + println!("Please input compiled file path!") + } + Ok(()) +} diff --git a/reid/examples/fibonacci.rs b/reid/examples/fibonacci.rs deleted file mode 100644 index a934f72..0000000 --- a/reid/examples/fibonacci.rs +++ /dev/null @@ -1,11 +0,0 @@ -use reid::compile; - -pub static FIBONACCI: &str = include_str!("./reid/fibonacci.reid"); - -fn main() { - let text = match compile(FIBONACCI) { - Ok(t) => t, - Err(e) => panic!("{}", e), - }; - println!("{}", text); -} diff --git a/reid/examples/mutable.rs b/reid/examples/mutable.rs deleted file mode 100644 index ec6a04c..0000000 --- a/reid/examples/mutable.rs +++ /dev/null @@ -1,11 +0,0 @@ -use reid::compile; - -pub static MUTABLE: &str = include_str!("./reid/mutable.reid"); - -fn main() { - let text = match compile(MUTABLE) { - Ok(t) => t, - Err(e) => panic!("{}", e), - }; - println!("{}", text); -} diff --git a/reid/examples/reid/array.reid b/reid_src/array.reid similarity index 100% rename from reid/examples/reid/array.reid rename to reid_src/array.reid diff --git a/reid/examples/reid/fibonacci.reid b/reid_src/fibonacci.reid similarity index 100% rename from reid/examples/reid/fibonacci.reid rename to reid_src/fibonacci.reid diff --git a/reid/examples/reid/mutable.reid b/reid_src/mutable.reid similarity index 100% rename from reid/examples/reid/mutable.reid rename to reid_src/mutable.reid diff --git a/reid/examples/reid/strings.reid b/reid_src/strings.reid similarity index 100% rename from reid/examples/reid/strings.reid rename to reid_src/strings.reid