feat: export now supports return type closes #968
This commit is contained in:
parent
3e2ca757cd
commit
9385f637f9
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
## unreleased
|
## unreleased
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- **aiken-project**: `export` output now supports the functions `return_type`. @rvcas
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- **aiken-project**: The `aiken.toml` file no longer supports `v1` and `v2` for the plutus version field. @rvcas
|
- **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},
|
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 miette::NamedSource;
|
||||||
use uplc::ast::SerializableProgram;
|
use uplc::ast::SerializableProgram;
|
||||||
|
|
||||||
|
@ -22,6 +26,8 @@ pub struct Export {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub parameters: Vec<Parameter>,
|
pub parameters: Vec<Parameter>,
|
||||||
|
|
||||||
|
pub return_type: Parameter,
|
||||||
|
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub program: SerializableProgram,
|
pub program: SerializableProgram,
|
||||||
|
|
||||||
|
@ -64,6 +70,38 @@ impl Export {
|
||||||
})
|
})
|
||||||
.collect::<Result<_, _>>()?;
|
.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
|
let program = generator
|
||||||
.generate_raw(&func.body, &func.arguments, &module.name)
|
.generate_raw(&func.body, &func.arguments, &module.name)
|
||||||
.to_debruijn()
|
.to_debruijn()
|
||||||
|
@ -79,6 +117,7 @@ impl Export {
|
||||||
name: format!("{}.{}", &module.name, &func.name),
|
name: format!("{}.{}", &module.name, &func.name),
|
||||||
doc: func.doc.clone(),
|
doc: func.doc.clone(),
|
||||||
parameters,
|
parameters,
|
||||||
|
return_type,
|
||||||
program,
|
program,
|
||||||
definitions,
|
definitions,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue