DRY builtins types creation to ensure proper consistency.

This commit is contained in:
KtorZ
2024-08-16 15:26:52 +02:00
parent 5b61a75088
commit 7ec3f2e8df
23 changed files with 1182 additions and 1312 deletions

View File

@@ -153,7 +153,7 @@ impl From<&Config> for Preamble {
#[cfg(test)]
mod tests {
use super::*;
use aiken_lang::builtins;
use aiken_lang::tipo::Type;
use schema::{Data, Declaration, Items, Schema};
use serde_json::{self, json};
use std::collections::HashMap;
@@ -225,17 +225,17 @@ mod tests {
fn serialize_with_definitions() {
let mut definitions = Definitions::new();
definitions
.register::<_, Error>(&builtins::int(), &HashMap::new(), |_| {
.register::<_, Error>(&Type::int(), &HashMap::new(), |_| {
Ok(Schema::Data(Data::Integer).into())
})
.unwrap();
definitions
.register::<_, Error>(
&builtins::list(builtins::byte_array()),
&Type::list(Type::byte_array()),
&HashMap::new(),
|definitions| {
let ref_bytes = definitions.register::<_, Error>(
&builtins::byte_array(),
&Type::byte_array(),
&HashMap::new(),
|_| Ok(Schema::Data(Data::Bytes).into()),
)?;

View File

@@ -4,7 +4,6 @@ use crate::{
};
use aiken_lang::{
ast::{Definition, TypedDataType, TypedDefinition},
builtins::wrapped_redeemer,
tipo::{pretty, Type, TypeVar},
};
use owo_colors::{OwoColorize, Stream::Stdout};
@@ -142,7 +141,7 @@ impl Annotated<Schema> {
) -> Reference {
definitions
.register(
&wrapped_redeemer(type_info),
&Type::wrapped_redeemer(type_info),
&HashMap::new(),
|_| {
Ok::<_, Error>(Annotated {

View File

@@ -272,7 +272,7 @@ mod tests {
use aiken_lang::{
self,
ast::{TraceLevel, Tracing},
builtins,
tipo::Type,
};
use std::collections::HashMap;
use uplc::ast as uplc_ast;
@@ -336,7 +336,7 @@ mod tests {
// "dataType": "integer"
// }
definitions
.register::<_, Error>(&builtins::int(), &HashMap::new(), |_| {
.register::<_, Error>(&Type::int(), &HashMap::new(), |_| {
Ok(Schema::Data(Data::Integer).into())
})
.unwrap();
@@ -347,7 +347,7 @@ mod tests {
// "dataType": "bytes"
// }
definitions
.register::<_, Error>(&builtins::byte_array(), &HashMap::new(), |_| {
.register::<_, Error>(&Type::byte_array(), &HashMap::new(), |_| {
Ok(Schema::Data(Data::Bytes).into())
})
.unwrap();

View File

@@ -1,7 +1,6 @@
use aiken_lang::ast::OnTestFailure;
pub(crate) use aiken_lang::{
ast::{BinOp, DataTypeKey, IfBranch, Span, TypedArg, TypedDataType, TypedTest},
builtins::bool,
expr::{TypedExpr, UntypedExpr},
format::Formatter,
gen_uplc::CodeGenerator,
@@ -1056,7 +1055,7 @@ impl TryFrom<TypedExpr> for Assertion<TypedExpr> {
left,
right,
..
} if tipo == bool() => {
} if tipo == Type::bool() => {
// 'and' and 'or' are left-associative operators.
match (*right).clone().try_into() {
Ok(Assertion {
@@ -1094,7 +1093,7 @@ impl TryFrom<TypedExpr> for Assertion<TypedExpr> {
let then_is_true = match body {
TypedExpr::Var {
name, constructor, ..
} => name == "True" && constructor.tipo == bool(),
} => name == "True" && constructor.tipo == Type::bool(),
_ => false,
};
@@ -1102,7 +1101,7 @@ impl TryFrom<TypedExpr> for Assertion<TypedExpr> {
TypedExpr::Trace { then, .. } => match *then {
TypedExpr::Var {
name, constructor, ..
} => name == "False" && constructor.tipo == bool(),
} => name == "False" && constructor.tipo == Type::bool(),
_ => false,
},
_ => false,