Update libtest and make examples/cli.rs
This commit is contained in:
parent
bc1cc99bcc
commit
e15f77d9de
10
README.md
10
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?
|
## What is currently being tested?
|
||||||
|
|
||||||
Currently when testing the compiler I run `./libtest.sh fibonacci` or
|
Currently when testing the compiler I run `./libtest.sh reid_src/{file}.reid`,
|
||||||
`./libtest.sh arithmetic`.
|
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
|
What `./libtest.sh $1` does, is it compiles and runs the rust example found at
|
||||||
name `$1`, which may exist in any of the two projects. The two mentioned above
|
path `$1`. Some pre-existing examples can be found in [`reid_src`](./reid_src)
|
||||||
are in `reid/examples`.
|
|
||||||
|
|
||||||
All examples currently end up producing a `hello.o` and `hello.asm` file to the
|
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
|
root directory, which is then linked with `ldd` to produce a `main`, which is
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
# Do note this file is extremely simply for my own personal convenience
|
# Do note this file is extremely simply for my own personal convenience
|
||||||
|
|
||||||
export .env
|
export .env
|
||||||
cargo run --example $1 && \
|
cargo run --example cli $1 && \
|
||||||
# clang hello.o -o main && \
|
# clang hello.o -o main && \
|
||||||
ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 \
|
ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 \
|
||||||
-o main /usr/lib/crt1.o hello.o -lc && \
|
-o main /usr/lib/crt1.o hello.o -lc && \
|
||||||
|
@ -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);
|
|
||||||
}
|
|
18
reid/examples/cli.rs
Normal file
18
reid/examples/cli.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
use std::{env, fs};
|
||||||
|
|
||||||
|
use reid::compile;
|
||||||
|
|
||||||
|
fn main() -> Result<(), std::io::Error> {
|
||||||
|
let args: Vec<String> = 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(())
|
||||||
|
}
|
@ -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);
|
|
||||||
}
|
|
@ -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);
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user