rename 'constr_{fields,index}' to 'unconstr_{field,index}'

Better match the conventions so far used across the existing builtins.
This commit is contained in:
KtorZ 2024-12-13 15:18:15 +01:00
parent 977e24c725
commit 67bf64967b
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
3 changed files with 36 additions and 23 deletions

View File

@ -4,9 +4,11 @@
### Added
- **aiken**: Generate a default 'placeholder' validator when using `aiken new`. See [#1061](https://github.com/aiken-lang/aiken/pull/1061) @Waalge
- **aiken-lang**: New builtins 'constr_fields' and 'constr_index'. @Microproofs
- **aiken-lang**: New builtins from Chang2 hardfork (except for writeBits). @Microproofs, @KtorZ
- **aiken**: Generate a default _'placeholder.ak'_ validator when using `aiken new`. See [#1061](https://github.com/aiken-lang/aiken/pull/1061) @Waalge
- **aiken-lang**: New builtins [`unconstr_fields`](https://aiken-lang.github.io/prelude/aiken/builtin.html#unconstr_fields) and [`unconstr_index`](https://aiken-lang.github.io/prelude/aiken/builtin.html#unconstr_index). @Microproofs
- **aiken-lang**: Added builtins from Chang2 hardfork (except for writeBits). @Microproofs, @KtorZ
- [Bitwise operations](https://aiken-lang.github.io/prelude/aiken/builtin.html#Bitwise)
- [Ripemd-160 hashing](https://aiken-lang.github.io/prelude/aiken/builtin.html#ripemd_160)
- **aiken-projects**: The generated documentation may now include maths typesetting rendered using [KaTex](https://katex.org/). See [#1070](https://github.com/aiken-lang/aiken/pull/1070) @adrian052.
- Both inline (delimited by single `$` symbols) and blocks (delimited by doubled `$$` symbols) are now parsed and rendered as SVG upon generating documentation. For example:

View File

@ -519,11 +519,11 @@ pub fn plutus(id_gen: &IdGenerator) -> TypeInfo {
let index_tipo = Type::function(vec![Type::data()], Type::int());
plutus.values.insert(
"constr_index".to_string(),
"unconstr_index".to_string(),
ValueConstructor::public(
index_tipo,
ValueConstructorVariant::ModuleFn {
name: "constr_index".to_string(),
name: "unconstr_index".to_string(),
field_map: None,
module: "aiken/builtin".to_string(),
arity: 1,
@ -535,11 +535,11 @@ pub fn plutus(id_gen: &IdGenerator) -> TypeInfo {
let fields_tipo = Type::function(vec![Type::data()], Type::list(Type::data()));
plutus.values.insert(
"constr_fields".to_string(),
"unconstr_fields".to_string(),
ValueConstructor::public(
fields_tipo,
ValueConstructorVariant::ModuleFn {
name: "constr_fields".to_string(),
name: "unconstr_fields".to_string(),
field_map: None,
module: "aiken/builtin".to_string(),
arity: 1,
@ -1043,7 +1043,7 @@ pub fn prelude_functions(
) -> IndexMap<FunctionAccessKey, TypedFunction> {
let mut functions = IndexMap::new();
let constr_index_body = TypedExpr::Call {
let unconstr_index_body = TypedExpr::Call {
location: Span::empty(),
tipo: Type::int(),
fun: TypedExpr::local_var(
@ -1069,7 +1069,7 @@ pub fn prelude_functions(
}],
};
let constr_index_func = Function {
let unconstr_index_func = Function {
arguments: vec![TypedArg {
arg_name: ArgName::Named {
name: "constr".to_string(),
@ -1091,23 +1091,23 @@ pub fn prelude_functions(
}.to_string()
),
location: Span::empty(),
name: "constr_index".to_string(),
name: "unconstr_index".to_string(),
public: true,
return_annotation: None,
return_type: Type::int(),
end_position: 0,
body: constr_index_body,
body: unconstr_index_body,
};
functions.insert(
FunctionAccessKey {
module_name: "aiken/builtin".to_string(),
function_name: "constr_index".to_string(),
function_name: "unconstr_index".to_string(),
},
constr_index_func,
unconstr_index_func,
);
let constr_fields_body = TypedExpr::Call {
let unconstr_fields_body = TypedExpr::Call {
location: Span::empty(),
tipo: Type::list(Type::data()),
fun: TypedExpr::local_var(
@ -1133,7 +1133,7 @@ pub fn prelude_functions(
}],
};
let constr_fields_func = Function {
let unconstr_fields_func = Function {
arguments: vec![TypedArg {
arg_name: ArgName::Named {
name: "constr".to_string(),
@ -1155,20 +1155,20 @@ pub fn prelude_functions(
}.to_string()
),
location: Span::empty(),
name: "constr_fields".to_string(),
name: "unconstr_fields".to_string(),
public: true,
return_annotation: None,
return_type: Type::list(Type::data()),
end_position: 0,
body: constr_fields_body,
body: unconstr_fields_body,
};
functions.insert(
FunctionAccessKey {
module_name: "aiken/builtin".to_string(),
function_name: "constr_fields".to_string(),
function_name: "unconstr_fields".to_string(),
},
constr_fields_func,
unconstr_fields_func,
);
// /// Negate the argument. Useful for map/fold and pipelines.

View File

@ -1,12 +1,23 @@
use aiken/builtin.{constr_index}
use aiken/builtin.{unconstr_fields, unconstr_index}
test baz() {
test bar() {
let x = Some("bar")
expect [bar] = x |> builtin.constr_fields
expect [bar] = x |> builtin.unconstr_fields
and {
constr_index(x) == 0,
unconstr_index(x) == 0,
builtin.un_b_data(bar) == "bar",
}
}
test baz() {
let x = Some("baz")
expect [baz] = x |> unconstr_fields
and {
builtin.unconstr_index(x) == 0,
builtin.un_b_data(baz) == "baz",
}
}