fix(build): --uplc must use Program<Name> to pretty print

This commit is contained in:
rvcas
2023-06-07 16:25:59 -04:00
parent 1747090931
commit 8d107b1293
3 changed files with 33 additions and 5 deletions

View File

@@ -39,7 +39,7 @@ use std::{
};
use telemetry::EventListener;
use uplc::{
ast::{DeBruijn, Term},
ast::{DeBruijn, Name, Program, Term},
machine::cost_model::ExBudget,
};
@@ -227,8 +227,10 @@ where
for validator in &blueprint.validators {
let path = dir.clone().join(format!("{}.uplc", validator.title));
fs::write(&path, validator.program.to_pretty())
.map_err(|error| Error::FileIo { error, path })?;
let program = &validator.program;
let program: Program<Name> = program.try_into().unwrap();
fs::write(&path, program.to_pretty()).map_err(|error| Error::FileIo { error, path })?;
}
Ok(())

View File

@@ -537,6 +537,29 @@ impl TryFrom<Term<Name>> for Term<DeBruijn> {
}
}
impl TryFrom<&Program<DeBruijn>> for Program<Name> {
type Error = debruijn::Error;
fn try_from(value: &Program<DeBruijn>) -> Result<Self, Self::Error> {
Ok(Program::<Name> {
version: value.version,
term: (&value.term).try_into()?,
})
}
}
impl TryFrom<&Term<DeBruijn>> for Term<Name> {
type Error = debruijn::Error;
fn try_from(value: &Term<DeBruijn>) -> Result<Self, debruijn::Error> {
let mut converter = Converter::new();
let term = converter.debruijn_to_name(value)?;
Ok(term)
}
}
impl TryFrom<Program<NamedDeBruijn>> for Program<Name> {
type Error = debruijn::Error;