feat: export now supports return type closes #968
This commit is contained in:
parent
3e2ca757cd
commit
9385f637f9
|
@ -2,6 +2,10 @@
|
|||
|
||||
## unreleased
|
||||
|
||||
### Added
|
||||
|
||||
- **aiken-project**: `export` output now supports the functions `return_type`. @rvcas
|
||||
|
||||
### Changed
|
||||
|
||||
- **aiken-project**: The `aiken.toml` file no longer supports `v1` and `v2` for the plutus version field. @rvcas
|
||||
|
|
|
@ -7,7 +7,11 @@ use crate::{
|
|||
},
|
||||
module::{CheckedModule, CheckedModules},
|
||||
};
|
||||
use aiken_lang::{ast::TypedFunction, gen_uplc::CodeGenerator, plutus_version::PlutusVersion};
|
||||
use aiken_lang::{
|
||||
ast::{ArgName, Span, TypedArg, TypedFunction},
|
||||
gen_uplc::CodeGenerator,
|
||||
plutus_version::PlutusVersion,
|
||||
};
|
||||
use miette::NamedSource;
|
||||
use uplc::ast::SerializableProgram;
|
||||
|
||||
|
@ -22,6 +26,8 @@ pub struct Export {
|
|||
#[serde(default)]
|
||||
pub parameters: Vec<Parameter>,
|
||||
|
||||
pub return_type: Parameter,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub program: SerializableProgram,
|
||||
|
||||
|
@ -64,6 +70,38 @@ impl Export {
|
|||
})
|
||||
.collect::<Result<_, _>>()?;
|
||||
|
||||
let return_type = Annotated::from_type(
|
||||
modules.into(),
|
||||
blueprint::validator::tipo_or_annotation(
|
||||
module,
|
||||
&TypedArg {
|
||||
arg_name: ArgName::Discarded {
|
||||
name: "".to_string(),
|
||||
label: "".to_string(),
|
||||
location: Span::empty(),
|
||||
},
|
||||
location: Span::empty(),
|
||||
annotation: func.return_annotation.clone(),
|
||||
doc: None,
|
||||
is_validator_param: false,
|
||||
tipo: func.return_type.clone(),
|
||||
},
|
||||
),
|
||||
&mut definitions,
|
||||
)
|
||||
.map(|schema| Parameter {
|
||||
title: Some("return_type".to_string()),
|
||||
schema: Declaration::Referenced(schema),
|
||||
})
|
||||
.map_err(|error| blueprint::Error::Schema {
|
||||
error,
|
||||
location: func.location,
|
||||
source_code: NamedSource::new(
|
||||
module.input_path.display().to_string(),
|
||||
module.code.clone(),
|
||||
),
|
||||
})?;
|
||||
|
||||
let program = generator
|
||||
.generate_raw(&func.body, &func.arguments, &module.name)
|
||||
.to_debruijn()
|
||||
|
@ -79,6 +117,7 @@ impl Export {
|
|||
name: format!("{}.{}", &module.name, &func.name),
|
||||
doc: func.doc.clone(),
|
||||
parameters,
|
||||
return_type,
|
||||
program,
|
||||
definitions,
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue