Add Fuzzer to the prelude.

This commit is contained in:
KtorZ
2024-03-01 17:02:49 +01:00
parent 5b4fedd084
commit 93347d8e7b
3 changed files with 26 additions and 5 deletions

View File

@@ -29,7 +29,7 @@ pub const OPTION: &str = "Option";
pub const ORDERING: &str = "Ordering";
pub const REDEEMER_WRAPPER: &str = "RedeemerWrapper";
pub const PRNG: &str = "PRNG";
pub const FUZZER: &str = "FUZZER";
pub const FUZZER: &str = "Fuzzer";
/// Build a prelude that can be injected
/// into a compiler pipeline
@@ -482,6 +482,23 @@ pub fn prelude(id_gen: &IdGenerator) -> TypeInfo {
),
);
// Fuzzer
//
// pub type Fuzzer<a> =
// fn(PRNG) -> Option<(PRNG, a)>
let fuzzer_value = generic_var(id_gen.next());
prelude.types.insert(
FUZZER.to_string(),
TypeConstructor {
location: Span::empty(),
parameters: vec![fuzzer_value.clone()],
tipo: fuzzer(fuzzer_value),
module: "".to_string(),
public: true,
},
);
prelude
}
@@ -1302,6 +1319,13 @@ pub fn prng() -> Rc<Type> {
})
}
pub fn fuzzer(a: Rc<Type>) -> Rc<Type> {
Rc::new(Type::Fn {
args: vec![prng()],
ret: option(tuple(vec![prng(), a])),
})
}
pub fn list(t: Rc<Type>) -> Rc<Type> {
Rc::new(Type::App {
public: true,