mirror of
https://github.com/Kindelia/Kind2.git
synced 2024-09-11 07:15:45 +03:00
commit
a9c2a73545
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -142,6 +142,7 @@ dependencies = [
|
|||||||
name = "kind2"
|
name = "kind2"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"clap",
|
||||||
"hvm",
|
"hvm",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -7,3 +7,4 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
hvm = "0.1.40"
|
hvm = "0.1.40"
|
||||||
|
clap = { version = "3.1.8", features = ["derive"] }
|
20
src/cli.rs
Normal file
20
src/cli.rs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
pub use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
#[clap(author, version, about, long_about = None)]
|
||||||
|
#[clap(propagate_version = true)]
|
||||||
|
pub struct Cli {
|
||||||
|
#[clap(subcommand)]
|
||||||
|
pub command: Command,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subcommand)]
|
||||||
|
pub enum Command {
|
||||||
|
/// Run a file interpreted
|
||||||
|
#[clap(aliases = &["r"])]
|
||||||
|
Run { file: String, params: Vec<String> },
|
||||||
|
|
||||||
|
/// Check a file
|
||||||
|
#[clap(aliases = &["c"])]
|
||||||
|
Check { file: String, params: Vec<String> },
|
||||||
|
}
|
40
src/main.rs
40
src/main.rs
@ -1,27 +1,42 @@
|
|||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
#![allow(unused_variables)]
|
#![allow(unused_variables)]
|
||||||
|
|
||||||
|
mod cli;
|
||||||
mod language;
|
mod language;
|
||||||
|
|
||||||
|
use cli::{Cli, Parser, Command};
|
||||||
use language::{*};
|
use language::{*};
|
||||||
use hvm::parser as parser;
|
use hvm::parser as parser;
|
||||||
|
|
||||||
const CHECKER_HVM: &str = include_str!("checker.hvm");
|
const CHECKER_HVM: &str = include_str!("checker.hvm");
|
||||||
|
|
||||||
fn main() -> Result<(), String> {
|
fn main() {
|
||||||
//gen_debug_file();
|
match run_cli() {
|
||||||
|
Ok(..) => {}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("{}", err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let args: Vec<String> = std::env::args().collect();
|
// ------------------------------------------------------------
|
||||||
|
// ------------------------------------------------------------
|
||||||
|
// ------------------------------------------------------------
|
||||||
|
|
||||||
if args.len() <= 2 || args[1] != "check" && args[1] != "run" {
|
fn run_cli() -> Result<(), String> {
|
||||||
println!("Usage:");
|
let cli_matches = Cli::parse();
|
||||||
println!("$ kind2 check file.kind");
|
|
||||||
println!("$ kind2 run file.kind");
|
match cli_matches.command {
|
||||||
return Ok(());
|
Command::Run { file: path, params } => {
|
||||||
|
kind2(&path, "Api.run_main")
|
||||||
|
}
|
||||||
|
|
||||||
|
Command::Check { file: path, params } => {
|
||||||
|
kind2(&path, "Api.check_all")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let path = &args[2];
|
fn kind2(path: &str, main_function: &str) -> Result<(), String> {
|
||||||
|
|
||||||
// Reads definitions from file
|
// Reads definitions from file
|
||||||
let file = match std::fs::read_to_string(path) {
|
let file = match std::fs::read_to_string(path) {
|
||||||
Ok(code) => read_file(&code),
|
Ok(code) => read_file(&code),
|
||||||
@ -47,7 +62,6 @@ fn main() -> Result<(), String> {
|
|||||||
//println!("[{}]\n{}\n", name, show_entry(entry));
|
//println!("[{}]\n{}\n", name, show_entry(entry));
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//
|
|
||||||
let code = compile_file(&file);
|
let code = compile_file(&file);
|
||||||
let mut checker = (&CHECKER_HVM[0 .. CHECKER_HVM.find("////INJECT////").unwrap()]).to_string();
|
let mut checker = (&CHECKER_HVM[0 .. CHECKER_HVM.find("////INJECT////").unwrap()]).to_string();
|
||||||
checker.push_str(&code);
|
checker.push_str(&code);
|
||||||
@ -57,14 +71,14 @@ fn main() -> Result<(), String> {
|
|||||||
|
|
||||||
// Runs with the interpreter
|
// Runs with the interpreter
|
||||||
let mut rt = hvm::Runtime::from_code(&checker)?;
|
let mut rt = hvm::Runtime::from_code(&checker)?;
|
||||||
let main = rt.alloc_code(if args[1] == "check" { "Api.check_all" } else { "Api.run_main" })?;
|
let main = rt.alloc_code(main_function)?;
|
||||||
rt.normalize(main);
|
rt.normalize(main);
|
||||||
println!("{}", readback_string(&rt, main)); // TODO: optimize by deserializing term into text directly
|
println!("{}", readback_string(&rt, main)); // TODO: optimize by deserializing term into text directly
|
||||||
|
|
||||||
// Display stats
|
// Display stats
|
||||||
println!("Rewrites: {}", rt.get_rewrites());
|
println!("Rewrites: {}", rt.get_rewrites());
|
||||||
|
|
||||||
return Ok(());
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------
|
// ------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user