From e9faa8cac1093d68b760194227c43026273929c0 Mon Sep 17 00:00:00 2001 From: Shaakeed Belizaire Date: Fri, 12 Apr 2024 15:02:49 -0400 Subject: [PATCH 1/5] allow human readable names for terms --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/main.rs | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 4 deletions(-) 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..da29dd3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,9 +10,10 @@ 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}; use uplc::machine::cost_model::{CostModel, ExBudget}; use uplc::machine::{Machine, MachineState}; +use uplc::optimize; use uplc::{parser, PlutusData}; #[derive(Parser, Debug)] @@ -75,6 +76,39 @@ fn main() -> Result<(), anyhow::Error> { program = program.apply_data(data); } + let program: Program = Program::::try_from(program)?.try_into()?; + + let program = program + .clone() + .traverse_uplc_with(&mut |_, term, _, _| match term { + Term::Var(_) => { + let term = Term::Var( + Name { + text: "the champ is here".to_string(), + unique: 0.into(), + } + .into(), + ); + program.apply_term(&term); + println!("Var - {}", term); + } + Term::Delay(_) => println!("Delay - {}", term), + Term::Lambda { + parameter_name, + body, + } => println!("Lambda - {}", term), + Term::Apply { function, argument } => println!("Apply - {}", term), + Term::Constant(_) => println!("Constant - {}", term), + Term::Force(_) => println!("Force - {}", term), + Term::Error => println!("Error - {}", term), + Term::Builtin(_) => println!("Builtin - {}", term), + Term::Constr { tag, fields } => println!("Contr - {}", term), + Term::Case { constr, branches } => println!("Case - {}", term), + }); + + let program: Program = + Program::::try_from(program)?.try_into()?; + let mut machine = Machine::new( Language::PlutusV2, CostModel::default(), From bc4903e2ac3f5eb609973384aa2cf9c29d4ee936 Mon Sep 17 00:00:00 2001 From: Shaakeed Belizaire Date: Sat, 13 Apr 2024 16:54:02 -0400 Subject: [PATCH 2/5] Error: Free Unique 0 with name i_0-0 --- src/main.rs | 55 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/src/main.rs b/src/main.rs index da29dd3..a0f8bee 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,10 +12,9 @@ use clap::{command, Parser, Subcommand}; use pallas::codec::minicbor::decode::Error; use pallas::ledger::primitives::babbage::Language; -use uplc::ast::{FakeNamedDeBruijn, Name, NamedDeBruijn, Program, Term}; +use uplc::ast::{FakeNamedDeBruijn, Name, NamedDeBruijn, Program, Term, Unique}; use uplc::machine::cost_model::{CostModel, ExBudget}; use uplc::machine::{Machine, MachineState}; -use uplc::optimize; use uplc::{parser, PlutusData}; #[derive(Parser, Debug)] @@ -78,30 +79,30 @@ fn main() -> Result<(), anyhow::Error> { 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(_) => { - let term = Term::Var( - Name { - text: "the champ is here".to_string(), - unique: 0.into(), - } - .into(), - ); - program.apply_term(&term); - println!("Var - {}", term); + Term::Var(name) => { + *term = update_terms(name, &mut terms_to_readable_names); + println!("{:?}", terms_to_readable_names); } - Term::Delay(_) => println!("Delay - {}", term), + Term::Delay(name) => println!("Delay - {}", term), Term::Lambda { parameter_name, body, - } => println!("Lambda - {}", term), + } => { + println!("paramter_name - {:?}", parameter_name); + println!("body - {:?}", body); + *term = update_terms(parameter_name, &mut terms_to_readable_names); + println!("{:?}", terms_to_readable_names); + } Term::Apply { function, argument } => println!("Apply - {}", term), - Term::Constant(_) => println!("Constant - {}", term), - Term::Force(_) => println!("Force - {}", term), - Term::Error => println!("Error - {}", term), - Term::Builtin(_) => println!("Builtin - {}", term), + Term::Constant(name) => println!("Constant - {}", term), + Term::Force(name) => println!("Force - {}", term), + Term::Error => println!("Error"), + Term::Builtin(name) => println!("Builtin - {}", term), Term::Constr { tag, fields } => println!("Contr - {}", term), Term::Case { constr, branches } => println!("Case - {}", term), }); @@ -143,3 +144,21 @@ fn main() -> Result<(), anyhow::Error> { } } } + +fn update_terms( + name: &mut Rc, + terms_to_readable_names: &mut HashMap, +) -> Term { + 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::Var( + Name { + text: text, + unique: name.unique, + } + .into(), + ) +} From 12e026d932e50894f5e83bdb57307a77619819e5 Mon Sep 17 00:00:00 2001 From: Shaakeed Belizaire Date: Sat, 13 Apr 2024 17:31:35 -0400 Subject: [PATCH 3/5] update --- src/main.rs | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/main.rs b/src/main.rs index a0f8bee..26fe953 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,7 @@ use pallas::ledger::primitives::babbage::Language; use uplc::ast::{FakeNamedDeBruijn, Name, NamedDeBruijn, Program, Term, Unique}; use uplc::machine::cost_model::{CostModel, ExBudget}; use uplc::machine::{Machine, MachineState}; +use uplc::parser::term; use uplc::{parser, PlutusData}; #[derive(Parser, Debug)] @@ -81,22 +82,39 @@ fn main() -> Result<(), anyhow::Error> { let mut terms_to_readable_names: HashMap = HashMap::new(); + println!("{:?}", program); + let program = program .clone() .traverse_uplc_with(&mut |_, term, _, _| match term { Term::Var(name) => { - *term = update_terms(name, &mut terms_to_readable_names); - println!("{:?}", terms_to_readable_names); + 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::Delay(name) => println!("Delay - {}", term), Term::Lambda { parameter_name, body, } => { - println!("paramter_name - {:?}", parameter_name); - println!("body - {:?}", body); - *term = update_terms(parameter_name, &mut terms_to_readable_names); - println!("{:?}", terms_to_readable_names); + 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).into(), + body: Rc::new(body.as_ref().clone()), + } } Term::Apply { function, argument } => println!("Apply - {}", term), Term::Constant(name) => println!("Constant - {}", term), @@ -107,6 +125,8 @@ fn main() -> Result<(), anyhow::Error> { Term::Case { constr, branches } => println!("Case - {}", term), }); + println!("{:?}", terms_to_readable_names); + println!("{:?}", program); let program: Program = Program::::try_from(program)?.try_into()?; @@ -144,21 +164,3 @@ fn main() -> Result<(), anyhow::Error> { } } } - -fn update_terms( - name: &mut Rc, - terms_to_readable_names: &mut HashMap, -) -> Term { - 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::Var( - Name { - text: text, - unique: name.unique, - } - .into(), - ) -} From bf1d2dd64b20b7842796d8dd3d0bba882779d4fa Mon Sep 17 00:00:00 2001 From: Shaakeed Belizaire Date: Mon, 15 Apr 2024 13:23:46 -0400 Subject: [PATCH 4/5] anotha --- src/main.rs | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index 26fe953..d01ee72 100644 --- a/src/main.rs +++ b/src/main.rs @@ -82,8 +82,6 @@ fn main() -> Result<(), anyhow::Error> { let mut terms_to_readable_names: HashMap = HashMap::new(); - println!("{:?}", program); - let program = program .clone() .traverse_uplc_with(&mut |_, term, _, _| match term { @@ -101,7 +99,9 @@ fn main() -> Result<(), anyhow::Error> { .into(), ) } - Term::Delay(name) => println!("Delay - {}", term), + Term::Delay(name) => { + println!("Delay name - {}", name); + } Term::Lambda { parameter_name, body, @@ -116,17 +116,32 @@ fn main() -> Result<(), anyhow::Error> { body: Rc::new(body.as_ref().clone()), } } - Term::Apply { function, argument } => println!("Apply - {}", term), - Term::Constant(name) => println!("Constant - {}", term), - Term::Force(name) => println!("Force - {}", term), - Term::Error => println!("Error"), - Term::Builtin(name) => println!("Builtin - {}", term), - Term::Constr { tag, fields } => println!("Contr - {}", term), - Term::Case { constr, branches } => println!("Case - {}", term), + Term::Apply { function, argument } => { + println!("Apply function - {}", function); + println!("Apply argument - {}", argument); + } + Term::Constant(name) => { + println!("Constant name - {:?}", name); + } + Term::Force(name) => { + println!("Force name - {:?}", name); + } + Term::Error => { + println!("Error"); + } + Term::Builtin(name) => { + println!("Builtin name - {}", name); + } + Term::Constr { tag, fields } => { + println!("Contr tag - {}", tag); + println!("Contr fields - {:?}", fields); + } + Term::Case { constr, branches } => { + println!("Case constr - {}", constr); + println!("Case branches - {:?}", branches); + } }); - println!("{:?}", terms_to_readable_names); - println!("{:?}", program); let program: Program = Program::::try_from(program)?.try_into()?; From c7ae0efe3e668c25dd37a3649335e936ef92a3fa Mon Sep 17 00:00:00 2001 From: Shaakeed Belizaire Date: Tue, 16 Apr 2024 11:43:27 -0400 Subject: [PATCH 5/5] fix unique error --- src/main.rs | 37 +++++++------------------------------ 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/src/main.rs b/src/main.rs index d01ee72..55b8ea5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,6 @@ use pallas::ledger::primitives::babbage::Language; use uplc::ast::{FakeNamedDeBruijn, Name, NamedDeBruijn, Program, Term, Unique}; use uplc::machine::cost_model::{CostModel, ExBudget}; use uplc::machine::{Machine, MachineState}; -use uplc::parser::term; use uplc::{parser, PlutusData}; #[derive(Parser, Debug)] @@ -99,9 +98,6 @@ fn main() -> Result<(), anyhow::Error> { .into(), ) } - Term::Delay(name) => { - println!("Delay name - {}", name); - } Term::Lambda { parameter_name, body, @@ -112,34 +108,15 @@ fn main() -> Result<(), anyhow::Error> { .or_insert(name.text.clone() + "-" + &name.unique.to_string()) .to_string(); *term = Term::Lambda { - parameter_name: Name::text(text).into(), + parameter_name: Name { + text: text, + unique: name.unique, + } + .into(), body: Rc::new(body.as_ref().clone()), - } - } - Term::Apply { function, argument } => { - println!("Apply function - {}", function); - println!("Apply argument - {}", argument); - } - Term::Constant(name) => { - println!("Constant name - {:?}", name); - } - Term::Force(name) => { - println!("Force name - {:?}", name); - } - Term::Error => { - println!("Error"); - } - Term::Builtin(name) => { - println!("Builtin name - {}", name); - } - Term::Constr { tag, fields } => { - println!("Contr tag - {}", tag); - println!("Contr fields - {:?}", fields); - } - Term::Case { constr, branches } => { - println!("Case constr - {}", constr); - println!("Case branches - {:?}", branches); + }; } + _ => {} }); let program: Program =