fix: it's more consistent to have snakecase builtins

This commit is contained in:
rvcas 2022-11-24 18:35:19 -05:00 committed by Lucas
parent 67d160230b
commit d5087dbcc7
5 changed files with 78 additions and 18 deletions

View File

@ -240,10 +240,7 @@ pub fn plutus(id_gen: &IdGenerator) -> TypeInfo {
for builtin in DefaultFunction::iter() { for builtin in DefaultFunction::iter() {
if let Some(value) = from_default_function(builtin, id_gen) { if let Some(value) = from_default_function(builtin, id_gen) {
plutus.values.insert( plutus.values.insert(builtin.aiken_name(), value);
builtin.to_string().replace("ByteString", "ByteArray"),
value,
);
} }
} }
@ -403,7 +400,7 @@ pub fn from_default_function(
ValueConstructor::public( ValueConstructor::public(
tipo, tipo,
ValueConstructorVariant::ModuleFn { ValueConstructorVariant::ModuleFn {
name: builtin.to_string().replace("ByteString", "ByteArray"), name: builtin.aiken_name(),
field_map: None, field_map: None,
module: "".to_string(), module: "".to_string(),
arity, arity,

View File

@ -325,3 +325,66 @@ impl Display for DefaultFunction {
} }
} }
} }
impl DefaultFunction {
pub fn aiken_name(&self) -> String {
use DefaultFunction::*;
match self {
AddInteger => "add_integer".to_string(),
SubtractInteger => "subtract_integer".to_string(),
MultiplyInteger => "multiply_integer".to_string(),
DivideInteger => "divide_integer".to_string(),
QuotientInteger => "quotient_integer".to_string(),
RemainderInteger => "remainder_integer".to_string(),
ModInteger => "mod_integer".to_string(),
EqualsInteger => "equals_integer".to_string(),
LessThanInteger => "less_than_integer".to_string(),
LessThanEqualsInteger => "less_than_equals_integer".to_string(),
AppendByteString => "append_bytearray".to_string(),
ConsByteString => "cons_bytearray".to_string(),
SliceByteString => "slice_bytearray".to_string(),
LengthOfByteString => "length_of_bytearray".to_string(),
IndexByteString => "index_bytearray".to_string(),
EqualsByteString => "equals_bytearray".to_string(),
LessThanByteString => "less_than_bytearray".to_string(),
LessThanEqualsByteString => "less_than_equals_bytearray".to_string(),
Sha2_256 => "sha2_256".to_string(),
Sha3_256 => "sha3_256".to_string(),
Blake2b_256 => "blake2b_256".to_string(),
VerifyEd25519Signature => "verify_signature".to_string(),
VerifyEcdsaSecp256k1Signature => "verify_ecdsa_secp256k1_signature".to_string(),
VerifySchnorrSecp256k1Signature => "verify_schnorr_secp256k1_signature".to_string(),
AppendString => "append_string".to_string(),
EqualsString => "equals_string".to_string(),
EncodeUtf8 => "encode_utf8".to_string(),
DecodeUtf8 => "decode_utf8".to_string(),
IfThenElse => "if_then_else".to_string(),
ChooseUnit => "choose_unit".to_string(),
Trace => "trace".to_string(),
FstPair => "fst_pair".to_string(),
SndPair => "snd_pair".to_string(),
ChooseList => "choose_list".to_string(),
MkCons => "mk_cons".to_string(),
HeadList => "head_list".to_string(),
TailList => "tail_list".to_string(),
NullList => "null_list".to_string(),
ChooseData => "choose_data".to_string(),
ConstrData => "constr_data".to_string(),
MapData => "map_data".to_string(),
ListData => "list_data".to_string(),
IData => "i_data".to_string(),
BData => "b_data".to_string(),
UnConstrData => "un_constr_data".to_string(),
UnMapData => "un_map_data".to_string(),
UnListData => "un_list_data".to_string(),
UnIData => "un_i_data".to_string(),
UnBData => "un_b_data".to_string(),
EqualsData => "equals_data".to_string(),
SerialiseData => "serialise_data".to_string(),
MkPairData => "mk_pair_data".to_string(),
MkNilData => "mk_nil_data".to_string(),
MkNilPairData => "mk_nil_pair_data".to_string(),
}
}
}

View File

@ -1,11 +1,11 @@
use aiken/builtin use aiken/builtin
pub fn slice(bytes: ByteArray, start: Int, end: Int) -> ByteArray { pub fn slice(bytes: ByteArray, start: Int, end: Int) -> ByteArray {
builtin.sliceByteArray(start, end, bytes) builtin.slice_bytearray(start, end, bytes)
} }
pub fn length(bytes: ByteArray) -> Int { pub fn length(bytes: ByteArray) -> Int {
builtin.lengthOfByteArray(bytes) builtin.length_of_bytearray(bytes)
} }
pub fn is_empty(bytes: ByteArray) -> Bool { pub fn is_empty(bytes: ByteArray) -> Bool {
@ -13,9 +13,9 @@ pub fn is_empty(bytes: ByteArray) -> Bool {
} }
pub fn concat(left front: ByteArray, right back: ByteArray) -> ByteArray { pub fn concat(left front: ByteArray, right back: ByteArray) -> ByteArray {
builtin.appendByteArray(front, back) builtin.append_bytearray(front, back)
} }
pub fn prepend(rest: ByteArray, byte: Int) -> ByteArray { pub fn prepend(rest: ByteArray, byte: Int) -> ByteArray {
builtin.consByteArray(byte, rest) builtin.cons_bytearray(byte, rest)
} }

View File

@ -47,8 +47,8 @@ pub type Transaction {
id: TransactionId, id: TransactionId,
} }
pub type TransactionId = { pub type TransactionId {
hash: Hash(Transaction) hash: Hash(Transaction),
} }
pub type Input { pub type Input {
@ -64,12 +64,12 @@ pub type OutputReference {
pub type PolicyId = pub type PolicyId =
ByteArray ByteArray
pub type StakeCredential = { pub type StakeCredential {
StakeHash(Credential) StakeHash(Credential)
StakePointer(Int, Int, Int) StakePointer(Int, Int, Int)
} }
pub type Credential = { pub type Credential {
PublicKeyCredential(PublicKeyHash) PublicKeyCredential(PublicKeyHash)
ScriptCredential(ScriptHash) ScriptCredential(ScriptHash)
} }
@ -86,19 +86,19 @@ pub type PublicKeyHash =
pub type PoolId = pub type PoolId =
Hash(VerificationKey) Hash(VerificationKey)
pub type Output = { pub type Output {
address: Address, address: Address,
value: Value, value: Value,
datum: DatumOption, datum: DatumOption,
reference_script: Option(ScriptHash), reference_script: Option(ScriptHash),
} }
pub type Address = { pub type Address {
payment_credential: Credential, payment_credential: Credential,
stake_credential: Option(StakeCredential), stake_credential: Option(StakeCredential),
} }
pub type DatumOption = { pub type DatumOption {
NoDatum NoDatum
DatumHash(Hash(Data)) DatumHash(Hash(Data))
Datum(Data) Datum(Data)

View File

@ -63,7 +63,7 @@ pub fn range(from: Int, to: Int) -> List(Int) {
pub fn head(xs: List(a)) -> Option(a) { pub fn head(xs: List(a)) -> Option(a) {
when xs is { when xs is {
[] -> None [] -> None
_ -> Some(builtin.headList(xs)) _ -> Some(builtin.head_list(xs))
} }
} }