diff --git a/Cargo.lock b/Cargo.lock index 367ea3d..4cbfab2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2224,8 +2224,8 @@ checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" [[package]] name = "uplc" -version = "1.0.24-alpha" -source = "git+https://github.com/SundaeSwap-finance/aiken.git?rev=68965b52#68965b52f37e97af8f912b7082dc8072825ed27c" +version = "1.0.26-alpha" +source = "git+https://github.com/SundaeSwap-finance/aiken.git?rev=6ba2241#6ba22414bce11b708d2cf106d638c18f2e6ec1c2" dependencies = [ "blst", "cryptoxide", diff --git a/Cargo.toml b/Cargo.toml index 29be8d5..8d9189d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -uplc = { git="https://github.com/SundaeSwap-finance/aiken.git", rev = "68965b52" } +uplc = { git="https://github.com/SundaeSwap-finance/aiken.git", rev = "6ba2241" } # uplc = { path = "../aiken/crates/uplc" } num-bigint = "0.4" clap = { version = "4.5.3", features = ["derive"] } diff --git a/src/main.rs b/src/main.rs index bdf9a0b..55b8ea5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,10 @@ mod app; mod utils; +use std::collections::HashMap; use std::ffi::OsStr; use std::path::PathBuf; +use std::rc::Rc; use std::{fs, process}; use app::App; @@ -10,7 +12,7 @@ use clap::{command, Parser, Subcommand}; use pallas::codec::minicbor::decode::Error; use pallas::ledger::primitives::babbage::Language; -use uplc::ast::{FakeNamedDeBruijn, NamedDeBruijn, Program}; +use uplc::ast::{FakeNamedDeBruijn, Name, NamedDeBruijn, Program, Term, Unique}; use uplc::machine::cost_model::{CostModel, ExBudget}; use uplc::machine::{Machine, MachineState}; use uplc::{parser, PlutusData}; @@ -75,6 +77,51 @@ fn main() -> Result<(), anyhow::Error> { program = program.apply_data(data); } + let program: Program = Program::::try_from(program)?.try_into()?; + + let mut terms_to_readable_names: HashMap = HashMap::new(); + + let program = program + .clone() + .traverse_uplc_with(&mut |_, term, _, _| match term { + Term::Var(name) => { + let name = Rc::make_mut(name); + let text = terms_to_readable_names + .entry(name.unique) + .or_insert(name.text.clone() + "-" + &name.unique.to_string()) + .to_string(); + *term = Term::Var( + Name { + text, + unique: name.unique, + } + .into(), + ) + } + Term::Lambda { + parameter_name, + body, + } => { + let name = Rc::make_mut(parameter_name); + let text = terms_to_readable_names + .entry(name.unique) + .or_insert(name.text.clone() + "-" + &name.unique.to_string()) + .to_string(); + *term = Term::Lambda { + parameter_name: Name { + text: text, + unique: name.unique, + } + .into(), + body: Rc::new(body.as_ref().clone()), + }; + } + _ => {} + }); + + let program: Program = + Program::::try_from(program)?.try_into()?; + let mut machine = Machine::new( Language::PlutusV2, CostModel::default(),