Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow human readable names for terms #7

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
49 changes: 48 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
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;
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};
Expand Down Expand Up @@ -75,6 +77,51 @@ fn main() -> Result<(), anyhow::Error> {
program = program.apply_data(data);
}

let program: Program<Name> = Program::<Name>::try_from(program)?.try_into()?;

let mut terms_to_readable_names: HashMap<Unique, String> = 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<NamedDeBruijn> =
Program::<NamedDeBruijn>::try_from(program)?.try_into()?;

let mut machine = Machine::new(
Language::PlutusV2,
CostModel::default(),
Expand Down