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)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
pub enum ModuleKind {
|
pub enum ModuleKind {
|
||||||
Lib,
|
Lib,
|
||||||
Script,
|
Validator,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModuleKind {
|
impl ModuleKind {
|
||||||
pub fn is_script(&self) -> bool {
|
pub fn is_validator(&self) -> bool {
|
||||||
matches!(self, ModuleKind::Script)
|
matches!(self, ModuleKind::Validator)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_lib(&self) -> bool {
|
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!(
|
assert_eq!(
|
||||||
module,
|
module,
|
||||||
ast::UntypedModule {
|
ast::UntypedModule {
|
||||||
docs: vec![],
|
docs: vec![],
|
||||||
kind: ast::ModuleKind::Script,
|
kind: ast::ModuleKind::Validator,
|
||||||
name: "".to_string(),
|
name: "".to_string(),
|
||||||
type_info: (),
|
type_info: (),
|
||||||
definitions: vec![
|
definitions: vec![
|
||||||
|
|
|
@ -92,10 +92,10 @@ impl Project {
|
||||||
|
|
||||||
let mut checked_modules = self.type_check(parsed_modules, processing_sequence)?;
|
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 {
|
if uplc_gen {
|
||||||
let programs = self.code_gen(scripts, &checked_modules)?;
|
let programs = self.code_gen(validators, &checked_modules)?;
|
||||||
|
|
||||||
self.write_build_outputs(programs)?;
|
self.write_build_outputs(programs)?;
|
||||||
}
|
}
|
||||||
|
@ -105,9 +105,9 @@ impl Project {
|
||||||
|
|
||||||
fn read_source_files(&mut self) -> Result<(), Error> {
|
fn read_source_files(&mut self) -> Result<(), Error> {
|
||||||
let lib = self.root.join("lib");
|
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)?;
|
self.aiken_files(&lib, ModuleKind::Lib)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -233,15 +233,15 @@ impl Project {
|
||||||
Ok(modules.into())
|
Ok(modules.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validate_scripts(
|
fn validate_validators(
|
||||||
&self,
|
&self,
|
||||||
checked_modules: &mut CheckedModules,
|
checked_modules: &mut CheckedModules,
|
||||||
) -> Result<Vec<(String, TypedFunction)>, Error> {
|
) -> Result<Vec<(String, TypedFunction)>, Error> {
|
||||||
let mut errors = Vec::new();
|
let mut errors = Vec::new();
|
||||||
let mut scripts = Vec::new();
|
let mut validators = Vec::new();
|
||||||
let mut indices_to_remove = 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() {
|
for (index, def) in module.ast.definitions().enumerate() {
|
||||||
if let Definition::Fn(func_def) = def {
|
if let Definition::Fn(func_def) = def {
|
||||||
if VALIDATOR_NAMES.contains(&func_def.name.as_str()) {
|
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);
|
indices_to_remove.push(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -290,7 +290,7 @@ impl Project {
|
||||||
}
|
}
|
||||||
|
|
||||||
if errors.is_empty() {
|
if errors.is_empty() {
|
||||||
Ok(scripts)
|
Ok(validators)
|
||||||
} else {
|
} else {
|
||||||
Err(Error::List(errors))
|
Err(Error::List(errors))
|
||||||
}
|
}
|
||||||
|
@ -298,7 +298,7 @@ impl Project {
|
||||||
|
|
||||||
fn code_gen(
|
fn code_gen(
|
||||||
&mut self,
|
&mut self,
|
||||||
scripts: Vec<(String, TypedFunction)>,
|
validators: Vec<(String, TypedFunction)>,
|
||||||
checked_modules: &CheckedModules,
|
checked_modules: &CheckedModules,
|
||||||
) -> Result<Vec<Script>, Error> {
|
) -> Result<Vec<Script>, Error> {
|
||||||
let mut programs = Vec::new();
|
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 {
|
let Function {
|
||||||
arguments,
|
arguments,
|
||||||
name,
|
name,
|
||||||
|
|
|
@ -181,14 +181,16 @@ impl From<CheckedModules> for HashMap<String, CheckedModule> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CheckedModules {
|
impl CheckedModules {
|
||||||
pub fn scripts(&mut self) -> impl Iterator<Item = &mut CheckedModule> {
|
pub fn validators(&mut self) -> impl Iterator<Item = &mut CheckedModule> {
|
||||||
self.0.values_mut().filter(|module| module.kind.is_script())
|
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
|
self.0
|
||||||
.into_values()
|
.into_values()
|
||||||
.filter(|module| module.kind.is_script())
|
.filter(|module| module.kind.is_validator())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue