Rule execution now runs, no tests tho

This commit is contained in:
2022-08-19 12:55:02 +02:00
parent 329dea72b7
commit 891d78c112
30 changed files with 925 additions and 560 deletions

View File

@@ -1,14 +1,23 @@
#![feature(specialization)]
use std::env::current_dir;
use std::{env::current_dir, process::exit};
mod parse;
mod project;
mod utils;
mod expression;
mod rule;
use expression::{Expr, Clause};
use mappable_rc::Mrc;
use project::{rule_collector, Loaded, file_loader};
use rule::Repository;
use utils::to_mrc_slice;
fn literal(orig: &[&str]) -> Vec<String> {
fn literal(orig: &[&str]) -> Mrc<[String]> {
to_mrc_slice(vliteral(orig))
}
fn vliteral(orig: &[&str]) -> Vec<String> {
orig.iter().map(|&s| s.to_owned()).collect()
}
@@ -21,15 +30,40 @@ export (match_sequence $lhs) >> (match_sequence $rhs) =100=> (bind ($lhs) (\_. $
export (match_sequence $lhs) >>= (match_sequence $rhs) =100=> (bind ($lhs) ($rhs))
"#;
fn initial_tree() -> Mrc<[Expr]> {
to_mrc_slice(vec![Expr(Clause::Name {
local: None,
qualified: to_mrc_slice(vec!["main".to_string(), "main".to_string()])
}, None)])
}
fn main() {
let cwd = current_dir().unwrap();
let collect_rules = rule_collector(move |n| {
if n == vec!["prelude"] { Ok(Loaded::Module(PRELUDE.to_string())) }
if n == literal(&["prelude"]) { Ok(Loaded::Module(PRELUDE.to_string())) }
else { file_loader(cwd.clone())(n) }
}, literal(&["...", ">>", ">>=", "[", "]", ",", "=", "=>"]));
}, vliteral(&["...", ">>", ">>=", "[", "]", ",", "=", "=>"]));
match collect_rules.try_find(&literal(&["main"])) {
Ok(rules) => for rule in rules.iter() {
println!("{rule:?}")
Ok(rules) => {
let mut tree = initial_tree();
println!("Start processing {tree:?}");
let repo = Repository::new(rules.as_ref().to_owned());
println!("Ruleset: {repo:?}");
let mut i = 0; loop {
if 10 <= i {break} else {i += 1}
match repo.step(Mrc::clone(&tree)) {
Ok(Some(phase)) => {
tree = phase;
println!("Step {i}: {tree:?}")
},
Ok(None) => exit(0),
Err(e) => {
eprintln!("Rule error: {e:?}");
exit(0)
}
}
}
}
Err(err) => println!("{:#?}", err)
}