feat(blueprint): a memoized program that only runs code gen every other time

This commit is contained in:
rvcas 2024-04-04 17:01:01 -04:00 committed by Lucas
parent aa3896e92a
commit cac119338d
2 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,30 @@
use aiken_lang::{ast::TypedValidator, gen_uplc::CodeGenerator};
use uplc::ast::{DeBruijn, Program};
pub struct MemoProgram {
program: Option<Program<DeBruijn>>,
}
impl MemoProgram {
pub fn new() -> Self {
Self { program: None }
}
pub fn get(
&mut self,
generator: &mut CodeGenerator,
def: &TypedValidator,
module_name: &str,
) -> Program<DeBruijn> {
match self.program.take() {
None => {
let new_program = generator.generate(def, module_name).to_debruijn().unwrap();
self.program.replace(new_program.clone());
new_program
}
Some(program) => program,
}
}
}

View File

@ -1,5 +1,6 @@
pub mod definitions;
pub mod error;
mod memo_program;
pub mod parameter;
pub mod schema;
pub mod validator;