add functions to blueprints
This commit is contained in:
parent
622b0d51b0
commit
87d657593a
File diff suppressed because it is too large
Load Diff
|
@ -1,5 +1,6 @@
|
||||||
pub mod definitions;
|
pub mod definitions;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
|
pub mod function;
|
||||||
pub mod parameter;
|
pub mod parameter;
|
||||||
pub mod schema;
|
pub mod schema;
|
||||||
pub mod validator;
|
pub mod validator;
|
||||||
|
@ -8,6 +9,7 @@ use crate::{config::Config, module::CheckedModules};
|
||||||
use aiken_lang::gen_uplc::CodeGenerator;
|
use aiken_lang::gen_uplc::CodeGenerator;
|
||||||
use definitions::Definitions;
|
use definitions::Definitions;
|
||||||
use error::Error;
|
use error::Error;
|
||||||
|
use function::Function;
|
||||||
use schema::{Annotated, Schema};
|
use schema::{Annotated, Schema};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use validator::Validator;
|
use validator::Validator;
|
||||||
|
@ -18,6 +20,7 @@ pub struct Blueprint {
|
||||||
pub validators: Vec<Validator>,
|
pub validators: Vec<Validator>,
|
||||||
#[serde(skip_serializing_if = "Definitions::is_empty", default)]
|
#[serde(skip_serializing_if = "Definitions::is_empty", default)]
|
||||||
pub definitions: Definitions<Annotated<Schema>>,
|
pub definitions: Definitions<Annotated<Schema>>,
|
||||||
|
pub functions: Vec<Function>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
|
@ -75,9 +78,19 @@ impl Blueprint {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let functions: Result<Vec<_>, Error> = modules
|
||||||
|
.functions()
|
||||||
|
.map(|(func, def)| {
|
||||||
|
let mut f = Function::from_checked_module(modules, generator, func, def)?;
|
||||||
|
definitions.merge(&mut f.definitions);
|
||||||
|
f.definitions = Definitions::new();
|
||||||
|
Ok(f)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
Ok(Blueprint {
|
Ok(Blueprint {
|
||||||
preamble,
|
preamble,
|
||||||
validators: validators?,
|
validators: validators?,
|
||||||
|
functions: functions?,
|
||||||
definitions,
|
definitions,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -159,6 +172,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
validators: vec![],
|
validators: vec![],
|
||||||
definitions: Definitions::new(),
|
definitions: Definitions::new(),
|
||||||
|
functions: vec![],
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serde_json::to_value(&blueprint).unwrap(),
|
serde_json::to_value(&blueprint).unwrap(),
|
||||||
|
@ -186,6 +200,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
validators: vec![],
|
validators: vec![],
|
||||||
definitions: Definitions::new(),
|
definitions: Definitions::new(),
|
||||||
|
functions: vec![],
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serde_json::to_value(&blueprint).unwrap(),
|
serde_json::to_value(&blueprint).unwrap(),
|
||||||
|
@ -237,6 +252,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
validators: vec![],
|
validators: vec![],
|
||||||
definitions,
|
definitions,
|
||||||
|
functions: vec![],
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serde_json::to_value(&blueprint).unwrap(),
|
serde_json::to_value(&blueprint).unwrap(),
|
||||||
|
|
|
@ -286,6 +286,29 @@ impl CheckedModules {
|
||||||
items.into_iter()
|
items.into_iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn functions(&self) -> impl Iterator<Item = (&CheckedModule, &TypedFunction)> {
|
||||||
|
let mut items = vec![];
|
||||||
|
|
||||||
|
for validator_module in self.0.values() {
|
||||||
|
for some_definition in validator_module.ast.definitions() {
|
||||||
|
if let Definition::Fn(def) = some_definition {
|
||||||
|
if let Some(doc) = def.doc.clone() {
|
||||||
|
if doc.contains("PUB") {
|
||||||
|
items.push((validator_module, def));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
items.sort_by(|left, right| {
|
||||||
|
(left.0.package.to_string(), left.0.name.to_string())
|
||||||
|
.cmp(&(right.0.package.to_string(), right.0.name.to_string()))
|
||||||
|
});
|
||||||
|
|
||||||
|
items.into_iter()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn into_validators(self) -> impl Iterator<Item = CheckedModule> {
|
pub fn into_validators(self) -> impl Iterator<Item = CheckedModule> {
|
||||||
self.0
|
self.0
|
||||||
.into_values()
|
.into_values()
|
||||||
|
|
Loading…
Reference in New Issue