Generate an arbitrary Expr using pointer-tree technique (no stack overflow)
(g: &mut Gen)
| 170 | } |
| 171 | |
| 172 | /// Count nested applications for telescope compression. |
| 173 | pub fn app_telescope_count(&self) -> u64 { |
| 174 | let mut count = 0u64; |
| 175 | let mut curr = self; |
| 176 | while let Expr::App(f, _) = curr { |
| 177 | count += 1; |
| 178 | curr = f.as_ref(); |
| 179 | } |
| 180 | count |
| 181 | } |
| 182 | |
| 183 | /// Count nested lambdas for telescope compression. |
| 184 | pub fn lam_telescope_count(&self) -> u64 { |
| 185 | let mut count = 0u64; |
| 186 | let mut curr = self; |
| 187 | while let Expr::Lam(_, _, body) = curr { |
| 188 | count += 1; |
| 189 | curr = body.as_ref(); |
| 190 | } |
| 191 | count |
| 192 | } |
| 193 | |
| 194 | /// Count nested foralls for telescope compression. |
| 195 | pub fn all_telescope_count(&self) -> u64 { |
| 196 | let mut count = 0u64; |
| 197 | let mut curr = self; |
| 198 | while let Expr::All(_, _, _, body) = curr { |
| 199 | count += 1; |
| 200 | curr = body.as_ref(); |
| 201 | } |
| 202 | count |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | #[cfg(test)] |
| 207 | pub mod tests { |
| 208 | use super::*; |
| 209 | use crate::constant::Constant; |
| 210 | use crate::serialize::{get_expr, put_expr}; |
| 211 | use crate::tests::gen_range; |
| 212 | use quickcheck::{Arbitrary, Gen}; |
| 213 | use quickcheck_macros::quickcheck; |
| 214 | use std::ptr; |
| 215 | |
| 216 | #[derive(Clone, Copy)] |
| 217 | enum Case { |
| 218 | Var, |
| 219 | Share, |
| 220 | Str, |
| 221 | Nat, |
| 222 | Sort, |
| 223 | Ref, |
| 224 | Rec, |
| 225 | App, |
| 226 | Lam, |
| 227 | All, |
| 228 | Prj, |
| 229 | Let, |
no test coverage detected