commit some changes so far

This commit is contained in:
microproofs 2024-02-14 09:55:25 -05:00 committed by Kasey
parent 9a52258e14
commit 8f84eb382f
1 changed files with 44 additions and 36 deletions

View File

@ -1,7 +1,12 @@
use std::{cmp::Ordering, iter::Peekable, rc::Rc, vec}; use std::{
cmp::Ordering,
iter::{self, Peekable},
rc::Rc,
vec,
};
use indexmap::IndexMap; use indexmap::IndexMap;
use itertools::Itertools; use itertools::{EitherOrBoth, Itertools};
use pallas::ledger::primitives::babbage::{BigInt, PlutusData}; use pallas::ledger::primitives::babbage::{BigInt, PlutusData};
@ -83,53 +88,56 @@ impl Default for IdGen {
#[derive(PartialEq, Clone, Debug)] #[derive(PartialEq, Clone, Debug)]
pub enum BuiltinArgs { pub enum BuiltinArgs {
TwoArgs((usize, Term<Name>), (usize, Term<Name>)), TwoArgs {
ThreeArgs( fst: (usize, Term<Name>),
(usize, Term<Name>), snd: Option<(usize, Term<Name>)>,
(usize, Term<Name>), },
(usize, Term<Name>), ThreeArgs {
), fst: (usize, Term<Name>),
TwoArgsAnyOrder((usize, Term<Name>), (usize, Term<Name>)), snd: Option<(usize, Term<Name>)>,
thd: Option<(usize, Term<Name>)>,
},
TwoArgsAnyOrder {
fst: (usize, Term<Name>),
snd: Option<(usize, Term<Name>)>,
},
} }
impl BuiltinArgs { impl BuiltinArgs {
fn args_from_arg_stack(stack: Vec<(usize, Term<Name>)>, is_order_agnostic: bool) -> Self { fn args_from_arg_stack(stack: Vec<(usize, Term<Name>)>, is_order_agnostic: bool) -> Self {
let mut ordered_arg_stack = stack.into_iter().rev().sorted_by(|(_, arg1), (_, arg2)| { let mut ordered_arg_stack = if is_order_agnostic {
stack.into_iter().rev().sorted_by(|(_, arg1), (_, arg2)| {
// sort by constant first if the builtin is order agnostic // sort by constant first if the builtin is order agnostic
if is_order_agnostic { if matches!(arg1, Term::Constant(_)) == matches!(arg2, Term::Constant(_)) {
if matches!(arg1, Term::Constant(_)) && matches!(arg2, Term::Constant(_)) { Ordering::Equal
std::cmp::Ordering::Equal
} else if matches!(arg1, Term::Constant(_)) { } else if matches!(arg1, Term::Constant(_)) {
std::cmp::Ordering::Less Ordering::Less
} else if matches!(arg2, Term::Constant(_)) {
std::cmp::Ordering::Greater
} else { } else {
std::cmp::Ordering::Equal Ordering::Greater
} }
})
} else { } else {
std::cmp::Ordering::Equal stack.into_iter()
} };
});
if ordered_arg_stack.len() == 2 && is_order_agnostic { if ordered_arg_stack.len() == 2 && is_order_agnostic {
// This is the special case where the order of args is irrelevant to the builtin // This is the special case where the order of args is irrelevant to the builtin
// An example is addInteger or multiplyInteger // An example is addInteger or multiplyInteger
BuiltinArgs::TwoArgsAnyOrder( BuiltinArgs::TwoArgsAnyOrder {
ordered_arg_stack.next().unwrap(), fst: ordered_arg_stack.next().unwrap(),
ordered_arg_stack.next().unwrap(), snd: ordered_arg_stack.next(),
) }
} else if ordered_arg_stack.len() == 2 { } else if ordered_arg_stack.len() == 2 {
BuiltinArgs::TwoArgs( BuiltinArgs::TwoArgs {
ordered_arg_stack.next().unwrap(), fst: ordered_arg_stack.next().unwrap(),
ordered_arg_stack.next().unwrap(), snd: ordered_arg_stack.next(),
) }
} else { } else {
// println!("ARG STACK FOR FUNC {:#?}, {:#?}", ordered_arg_stack, func); BuiltinArgs::ThreeArgs {
BuiltinArgs::ThreeArgs( fst: ordered_arg_stack.next().unwrap(),
ordered_arg_stack.next().unwrap(), snd: ordered_arg_stack.next(),
ordered_arg_stack.next().unwrap(), thd: ordered_arg_stack.next(),
ordered_arg_stack.next().unwrap(), }
)
} }
} }