chore: change how we depend on pallas

This commit is contained in:
rvcas
2024-01-24 21:26:48 -05:00
parent 9d563612f3
commit 589bb9a4b3
30 changed files with 163 additions and 152 deletions

View File

@@ -1,6 +1,6 @@
use std::collections::HashMap;
use pallas_primitives::babbage::Language;
use pallas::ledger::primitives::babbage::Language;
use crate::builtins::DefaultFunction;

View File

@@ -3,7 +3,7 @@ use std::{mem::size_of, ops::Deref, rc::Rc};
use num_bigint::BigInt;
use num_integer::Integer;
use once_cell::sync::Lazy;
use pallas_primitives::babbage::{Language, PlutusData};
use pallas::ledger::primitives::babbage::{Language, PlutusData};
use crate::{
ast::{Constant, Data, Type},

View File

@@ -2,7 +2,7 @@ use std::{collections::VecDeque, mem::size_of, ops::Deref, rc::Rc};
use num_bigint::BigInt;
use num_traits::{Signed, ToPrimitive};
use pallas_primitives::babbage::{self as pallas, PlutusData};
use pallas::ledger::primitives::babbage::{self, PlutusData};
use crate::{
ast::{Constant, NamedDeBruijn, Term, Type},
@@ -394,27 +394,29 @@ fn integer_log2(i: BigInt) -> i64 {
}
}
pub fn from_pallas_bigint(n: &pallas::BigInt) -> BigInt {
pub fn from_pallas_bigint(n: &babbage::BigInt) -> BigInt {
match n {
pallas::BigInt::Int(i) => i128::from(*i).into(),
pallas::BigInt::BigUInt(bytes) => BigInt::from_bytes_be(num_bigint::Sign::Plus, bytes),
pallas::BigInt::BigNInt(bytes) => BigInt::from_bytes_be(num_bigint::Sign::Minus, bytes) - 1,
babbage::BigInt::Int(i) => i128::from(*i).into(),
babbage::BigInt::BigUInt(bytes) => BigInt::from_bytes_be(num_bigint::Sign::Plus, bytes),
babbage::BigInt::BigNInt(bytes) => {
BigInt::from_bytes_be(num_bigint::Sign::Minus, bytes) - 1
}
}
}
pub fn to_pallas_bigint(n: &BigInt) -> pallas::BigInt {
pub fn to_pallas_bigint(n: &BigInt) -> babbage::BigInt {
if let Some(i) = n.to_i64() {
let pallas_int: pallas_codec::utils::Int = i.into();
pallas::BigInt::Int(pallas_int)
let pallas_int: pallas::codec::utils::Int = i.into();
babbage::BigInt::Int(pallas_int)
} else if n.is_positive() {
let (_, bytes) = n.to_bytes_be();
pallas::BigInt::BigUInt(bytes.into())
babbage::BigInt::BigUInt(bytes.into())
} else {
// Note that this would break if n == 0
// BUT n == 0 always fits into 64bits and hence would end up in the first branch.
let n: BigInt = n + 1;
let (_, bytes) = n.to_bytes_be();
pallas::BigInt::BigNInt(bytes.into())
babbage::BigInt::BigNInt(bytes.into())
}
}