Rename 'scripts' as 'validators' across the codebase.
This commit is contained in:
parent
c9da049712
commit
2e5406afa3
|
@ -17,12 +17,12 @@ pub type UntypedModule = Module<(), UntypedDefinition>;
|
|||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum ModuleKind {
|
||||
Lib,
|
||||
Script,
|
||||
Validator,
|
||||
}
|
||||
|
||||
impl ModuleKind {
|
||||
pub fn is_script(&self) -> bool {
|
||||
matches!(self, ModuleKind::Script)
|
||||
pub fn is_validator(&self) -> bool {
|
||||
matches!(self, ModuleKind::Validator)
|
||||
}
|
||||
|
||||
pub fn is_lib(&self) -> bool {
|
||||
|
|
|
@ -106,13 +106,13 @@ fn module() {
|
|||
}
|
||||
"#;
|
||||
|
||||
let (module, _extra) = parser::module(code, ast::ModuleKind::Script).unwrap();
|
||||
let (module, _extra) = parser::module(code, ast::ModuleKind::Validator).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
module,
|
||||
ast::UntypedModule {
|
||||
docs: vec![],
|
||||
kind: ast::ModuleKind::Script,
|
||||
kind: ast::ModuleKind::Validator,
|
||||
name: "".to_string(),
|
||||
type_info: (),
|
||||
definitions: vec![
|
||||
|
|
|
@ -92,10 +92,10 @@ impl Project {
|
|||
|
||||
let mut checked_modules = self.type_check(parsed_modules, processing_sequence)?;
|
||||
|
||||
let scripts = self.validate_scripts(&mut checked_modules)?;
|
||||
let validators = self.validate_validators(&mut checked_modules)?;
|
||||
|
||||
if uplc_gen {
|
||||
let programs = self.code_gen(scripts, &checked_modules)?;
|
||||
let programs = self.code_gen(validators, &checked_modules)?;
|
||||
|
||||
self.write_build_outputs(programs)?;
|
||||
}
|
||||
|
@ -105,9 +105,9 @@ impl Project {
|
|||
|
||||
fn read_source_files(&mut self) -> Result<(), Error> {
|
||||
let lib = self.root.join("lib");
|
||||
let scripts = self.root.join("validators");
|
||||
let validators = self.root.join("validators");
|
||||
|
||||
self.aiken_files(&scripts, ModuleKind::Script)?;
|
||||
self.aiken_files(&validators, ModuleKind::Validator)?;
|
||||
self.aiken_files(&lib, ModuleKind::Lib)?;
|
||||
|
||||
Ok(())
|
||||
|
@ -233,15 +233,15 @@ impl Project {
|
|||
Ok(modules.into())
|
||||
}
|
||||
|
||||
fn validate_scripts(
|
||||
fn validate_validators(
|
||||
&self,
|
||||
checked_modules: &mut CheckedModules,
|
||||
) -> Result<Vec<(String, TypedFunction)>, Error> {
|
||||
let mut errors = Vec::new();
|
||||
let mut scripts = Vec::new();
|
||||
let mut validators = Vec::new();
|
||||
let mut indices_to_remove = Vec::new();
|
||||
|
||||
for module in checked_modules.scripts() {
|
||||
for module in checked_modules.validators() {
|
||||
for (index, def) in module.ast.definitions().enumerate() {
|
||||
if let Definition::Fn(func_def) = def {
|
||||
if VALIDATOR_NAMES.contains(&func_def.name.as_str()) {
|
||||
|
@ -278,7 +278,7 @@ impl Project {
|
|||
})
|
||||
}
|
||||
|
||||
scripts.push((module.name.clone(), func_def.clone()));
|
||||
validators.push((module.name.clone(), func_def.clone()));
|
||||
indices_to_remove.push(index);
|
||||
}
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ impl Project {
|
|||
}
|
||||
|
||||
if errors.is_empty() {
|
||||
Ok(scripts)
|
||||
Ok(validators)
|
||||
} else {
|
||||
Err(Error::List(errors))
|
||||
}
|
||||
|
@ -298,7 +298,7 @@ impl Project {
|
|||
|
||||
fn code_gen(
|
||||
&mut self,
|
||||
scripts: Vec<(String, TypedFunction)>,
|
||||
validators: Vec<(String, TypedFunction)>,
|
||||
checked_modules: &CheckedModules,
|
||||
) -> Result<Vec<Script>, Error> {
|
||||
let mut programs = Vec::new();
|
||||
|
@ -330,7 +330,7 @@ impl Project {
|
|||
}
|
||||
}
|
||||
|
||||
for (module_name, func_def) in scripts {
|
||||
for (module_name, func_def) in validators {
|
||||
let Function {
|
||||
arguments,
|
||||
name,
|
||||
|
|
|
@ -181,14 +181,16 @@ impl From<CheckedModules> for HashMap<String, CheckedModule> {
|
|||
}
|
||||
|
||||
impl CheckedModules {
|
||||
pub fn scripts(&mut self) -> impl Iterator<Item = &mut CheckedModule> {
|
||||
self.0.values_mut().filter(|module| module.kind.is_script())
|
||||
pub fn validators(&mut self) -> impl Iterator<Item = &mut CheckedModule> {
|
||||
self.0
|
||||
.values_mut()
|
||||
.filter(|module| module.kind.is_validator())
|
||||
}
|
||||
|
||||
pub fn into_scripts(self) -> impl Iterator<Item = CheckedModule> {
|
||||
pub fn into_validators(self) -> impl Iterator<Item = CheckedModule> {
|
||||
self.0
|
||||
.into_values()
|
||||
.filter(|module| module.kind.is_script())
|
||||
.filter(|module| module.kind.is_validator())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue