2023-08-04 20:38:47 +02:00
|
|
|
use spl::{find_in_splpath, lex, oxidizer::RustAppBuilder, start_file};
|
2023-02-17 22:47:45 +01:00
|
|
|
|
2023-08-04 20:38:47 +02:00
|
|
|
use std::{env::args, fs};
|
2023-02-17 20:00:39 +01:00
|
|
|
|
2023-02-25 11:37:07 +01:00
|
|
|
fn main() {
|
2023-08-04 20:38:47 +02:00
|
|
|
let mut args = args().skip(1);
|
|
|
|
let arg = &args
|
|
|
|
.next()
|
|
|
|
.unwrap_or_else(|| find_in_splpath("repl.spl").expect("no file to be run"));
|
2023-08-04 23:17:35 +02:00
|
|
|
if arg == "--build" || arg == "--run" {
|
2023-08-04 20:38:47 +02:00
|
|
|
let file = args.next().unwrap();
|
|
|
|
let data = fs::read_to_string(file.clone()).expect("unable to read specified file");
|
2023-08-04 23:17:35 +02:00
|
|
|
let build_only = arg == "--build";
|
|
|
|
if build_only {
|
|
|
|
println!("Building SPL with specified natives file...");
|
|
|
|
}
|
2023-08-04 20:38:47 +02:00
|
|
|
let mut builder = RustAppBuilder::new();
|
2023-08-04 23:17:35 +02:00
|
|
|
if build_only {
|
|
|
|
if let Some(name) = args.next() {
|
|
|
|
builder.set_name(name);
|
|
|
|
}
|
|
|
|
println!("Embedding source...");
|
|
|
|
}
|
|
|
|
builder.add_source(file.to_owned(), data.to_owned());
|
|
|
|
if build_only {
|
|
|
|
println!("Preparing rust code...");
|
2023-08-04 22:39:05 +02:00
|
|
|
}
|
2023-08-04 20:38:47 +02:00
|
|
|
builder.prepare(lex(data.to_owned()).expect("invalid SPL in natives file."));
|
2023-08-04 23:17:35 +02:00
|
|
|
if build_only {
|
|
|
|
println!("Building...");
|
|
|
|
}
|
|
|
|
let app = builder.build(build_only).unwrap();
|
|
|
|
if build_only {
|
|
|
|
println!("Built! Binary is {}", app.get_binary());
|
|
|
|
} else {
|
|
|
|
let mut args: Vec<String> = args.collect();
|
|
|
|
args.insert(0, file);
|
|
|
|
app.execute(args).unwrap();
|
|
|
|
app.delete();
|
|
|
|
}
|
|
|
|
|
2023-08-04 20:38:47 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if let Err(x) = start_file(arg) {
|
2023-02-25 11:37:07 +01:00
|
|
|
println!("{x:?}");
|
|
|
|
}
|
2023-02-17 20:00:39 +01:00
|
|
|
}
|