told you so
This commit is contained in:
parent
c8c12b15e9
commit
b38faccaac
3 changed files with 8 additions and 40 deletions
16
Cargo.lock
generated
16
Cargo.lock
generated
|
@ -36,20 +36,4 @@ dependencies = [
|
||||||
"intaglio",
|
"intaglio",
|
||||||
"itertools",
|
"itertools",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"tinyvec",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tinyvec"
|
|
||||||
version = "1.6.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
|
|
||||||
dependencies = [
|
|
||||||
"tinyvec_macros",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tinyvec_macros"
|
|
||||||
version = "0.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
|
||||||
|
|
|
@ -9,4 +9,3 @@ edition = "2021"
|
||||||
intaglio = "1.8.0"
|
intaglio = "1.8.0"
|
||||||
itertools = "0.10.5"
|
itertools = "0.10.5"
|
||||||
once_cell = "1.18.0"
|
once_cell = "1.18.0"
|
||||||
tinyvec = { version = "1.6.0", features = ["alloc"] }
|
|
||||||
|
|
31
src/main.rs
31
src/main.rs
|
@ -9,7 +9,6 @@ use std::{
|
||||||
use intaglio::{Symbol, SymbolTable};
|
use intaglio::{Symbol, SymbolTable};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use tinyvec::TinyVec;
|
|
||||||
|
|
||||||
static TABLE: Lazy<Mutex<SymbolTable>> = Lazy::new(|| Mutex::new(SymbolTable::new()));
|
static TABLE: Lazy<Mutex<SymbolTable>> = Lazy::new(|| Mutex::new(SymbolTable::new()));
|
||||||
static FORALL: Lazy<Symbol> = Lazy::new(|| TABLE.lock().unwrap().intern("forall").unwrap());
|
static FORALL: Lazy<Symbol> = Lazy::new(|| TABLE.lock().unwrap().intern("forall").unwrap());
|
||||||
|
@ -41,23 +40,15 @@ fn do_it() -> Option<String> {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
type SexpVec = TinyVec<[Sexp; 8]>;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
enum Sexp {
|
enum Sexp {
|
||||||
Atom(Symbol),
|
Atom(Symbol),
|
||||||
List(Box<SexpVec>),
|
List(Vec<Sexp>),
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Sexp {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::nil()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sexp {
|
impl Sexp {
|
||||||
fn nil() -> Self {
|
fn nil() -> Self {
|
||||||
Self::List(Box::new(TinyVec::new()))
|
Self::List(Vec::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if the sexp is [`Atom`].
|
/// Returns `true` if the sexp is [`Atom`].
|
||||||
|
@ -121,7 +112,7 @@ impl Sexp {
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
Sexp::List(xs) => {
|
Sexp::List(xs) => {
|
||||||
let mut out = HashSet::from_iter(xs.iter());
|
let mut out = HashSet::from_iter(xs);
|
||||||
out.extend(xs.iter().flat_map(Sexp::concretion_targets));
|
out.extend(xs.iter().flat_map(Sexp::concretion_targets));
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
@ -227,7 +218,7 @@ fn at_depth(depth: usize, sexp: &mut Sexp) -> &mut Sexp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse<'src>(tokens: &'src [Token<'src>]) -> Option<SexpVec> {
|
fn parse<'src>(tokens: &'src [Token<'src>]) -> Option<Vec<Sexp>> {
|
||||||
let mut out = Sexp::nil();
|
let mut out = Sexp::nil();
|
||||||
let mut depth = 0;
|
let mut depth = 0;
|
||||||
|
|
||||||
|
@ -251,7 +242,7 @@ fn parse<'src>(tokens: &'src [Token<'src>]) -> Option<SexpVec> {
|
||||||
}
|
}
|
||||||
|
|
||||||
match out {
|
match out {
|
||||||
Sexp::List(xs) => Some(*xs),
|
Sexp::List(xs) => Some(xs),
|
||||||
Sexp::Atom(_) => unreachable!(),
|
Sexp::Atom(_) => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -415,7 +406,7 @@ fn matches(vars: Option<&Vec<Symbol>>, lhs: &Sexp, expr: &Sexp) -> bool {
|
||||||
(Sexp::Atom(a), Sexp::Atom(b)) => a == b || is_var(a),
|
(Sexp::Atom(a), Sexp::Atom(b)) => a == b || is_var(a),
|
||||||
(Sexp::Atom(a), Sexp::List(_)) => is_var(a),
|
(Sexp::Atom(a), Sexp::List(_)) => is_var(a),
|
||||||
(Sexp::List(a), Sexp::List(b)) => {
|
(Sexp::List(a), Sexp::List(b)) => {
|
||||||
a.len() == b.len() && a.iter().zip(b.iter()).all(|(a, b)| matches(vars, a, b))
|
a.len() == b.len() && a.iter().zip(b).all(|(a, b)| matches(vars, a, b))
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
@ -434,10 +425,7 @@ fn rw(rule: &Rule, sexp: &Sexp) -> Sexp {
|
||||||
} else {
|
} else {
|
||||||
match sexp {
|
match sexp {
|
||||||
Sexp::Atom(_) => sexp.clone(),
|
Sexp::Atom(_) => sexp.clone(),
|
||||||
Sexp::List(xs) => {
|
Sexp::List(xs) => Sexp::List(xs.iter().map(|s| s.rw(rule)).collect()),
|
||||||
let inner: SexpVec = xs.iter().map(|s| s.rw(rule)).collect();
|
|
||||||
Sexp::List(Box::new(inner))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -447,10 +435,7 @@ fn rw(rule: &Rule, sexp: &Sexp) -> Sexp {
|
||||||
} else {
|
} else {
|
||||||
match sexp {
|
match sexp {
|
||||||
Sexp::Atom(_) => sexp.clone(),
|
Sexp::Atom(_) => sexp.clone(),
|
||||||
Sexp::List(xs) => {
|
Sexp::List(xs) => Sexp::List(xs.iter().map(|s| s.rw(rule)).collect()),
|
||||||
let inner: SexpVec = xs.iter().map(|s| s.rw(rule)).collect();
|
|
||||||
Sexp::List(Box::new(inner))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue