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",
|
||||
"itertools",
|
||||
"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"
|
||||
itertools = "0.10.5"
|
||||
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 itertools::Itertools;
|
||||
use once_cell::sync::Lazy;
|
||||
use tinyvec::TinyVec;
|
||||
|
||||
static TABLE: Lazy<Mutex<SymbolTable>> = Lazy::new(|| Mutex::new(SymbolTable::new()));
|
||||
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)]
|
||||
enum Sexp {
|
||||
Atom(Symbol),
|
||||
List(Box<SexpVec>),
|
||||
}
|
||||
|
||||
impl Default for Sexp {
|
||||
fn default() -> Self {
|
||||
Self::nil()
|
||||
}
|
||||
List(Vec<Sexp>),
|
||||
}
|
||||
|
||||
impl Sexp {
|
||||
fn nil() -> Self {
|
||||
Self::List(Box::new(TinyVec::new()))
|
||||
Self::List(Vec::new())
|
||||
}
|
||||
|
||||
/// Returns `true` if the sexp is [`Atom`].
|
||||
|
@ -121,7 +112,7 @@ impl Sexp {
|
|||
out
|
||||
}
|
||||
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
|
||||
}
|
||||
|
@ -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 depth = 0;
|
||||
|
||||
|
@ -251,7 +242,7 @@ fn parse<'src>(tokens: &'src [Token<'src>]) -> Option<SexpVec> {
|
|||
}
|
||||
|
||||
match out {
|
||||
Sexp::List(xs) => Some(*xs),
|
||||
Sexp::List(xs) => Some(xs),
|
||||
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::List(_)) => is_var(a),
|
||||
(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,
|
||||
}
|
||||
|
@ -434,10 +425,7 @@ fn rw(rule: &Rule, sexp: &Sexp) -> Sexp {
|
|||
} else {
|
||||
match sexp {
|
||||
Sexp::Atom(_) => sexp.clone(),
|
||||
Sexp::List(xs) => {
|
||||
let inner: SexpVec = xs.iter().map(|s| s.rw(rule)).collect();
|
||||
Sexp::List(Box::new(inner))
|
||||
}
|
||||
Sexp::List(xs) => Sexp::List(xs.iter().map(|s| s.rw(rule)).collect()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -447,10 +435,7 @@ fn rw(rule: &Rule, sexp: &Sexp) -> Sexp {
|
|||
} else {
|
||||
match sexp {
|
||||
Sexp::Atom(_) => sexp.clone(),
|
||||
Sexp::List(xs) => {
|
||||
let inner: SexpVec = xs.iter().map(|s| s.rw(rule)).collect();
|
||||
Sexp::List(Box::new(inner))
|
||||
}
|
||||
Sexp::List(xs) => Sexp::List(xs.iter().map(|s| s.rw(rule)).collect()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue