mirror of
https://github.com/Kindelia/Kind2.git
synced 2024-09-11 07:15:45 +03:00
Merge branch 'master' of github.com:kindelia/kind2
This commit is contained in:
commit
792108dd33
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -142,6 +142,7 @@ dependencies = [
|
||||
name = "kind2"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"hvm",
|
||||
]
|
||||
|
||||
|
@ -7,3 +7,4 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
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(unused_variables)]
|
||||
|
||||
mod cli;
|
||||
mod language;
|
||||
|
||||
use cli::{Cli, Parser, Command};
|
||||
use language::{*};
|
||||
use hvm::parser as parser;
|
||||
|
||||
const CHECKER_HVM: &str = include_str!("checker.hvm");
|
||||
|
||||
fn main() -> Result<(), String> {
|
||||
//gen_debug_file();
|
||||
fn main() {
|
||||
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" {
|
||||
println!("Usage:");
|
||||
println!("$ kind2 check file.kind");
|
||||
println!("$ kind2 run file.kind");
|
||||
return Ok(());
|
||||
fn run_cli() -> Result<(), String> {
|
||||
let cli_matches = Cli::parse();
|
||||
|
||||
match cli_matches.command {
|
||||
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
|
||||
let file = match std::fs::read_to_string(path) {
|
||||
Ok(code) => read_file(&code),
|
||||
@ -47,7 +62,6 @@ fn main() -> Result<(), String> {
|
||||
//println!("[{}]\n{}\n", name, show_entry(entry));
|
||||
//}
|
||||
|
||||
//
|
||||
let code = compile_file(&file);
|
||||
let mut checker = (&CHECKER_HVM[0 .. CHECKER_HVM.find("////INJECT////").unwrap()]).to_string();
|
||||
checker.push_str(&code);
|
||||
@ -57,14 +71,14 @@ fn main() -> Result<(), String> {
|
||||
|
||||
// Runs with the interpreter
|
||||
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);
|
||||
println!("{}", readback_string(&rt, main)); // TODO: optimize by deserializing term into text directly
|
||||
|
||||
// Display stats
|
||||
println!("Rewrites: {}", rt.get_rewrites());
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user