Skip to content

Commit

Permalink
feat: export now supports return type closes #968
Browse files Browse the repository at this point in the history
  • Loading branch information
rvcas committed Dec 26, 2024
1 parent 3e2ca75 commit 9385f63
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 40 additions & 1 deletion crates/aiken-project/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -22,6 +26,8 @@ pub struct Export {
#[serde(default)]
pub parameters: Vec<Parameter>,

pub return_type: Parameter,

#[serde(flatten)]
pub program: SerializableProgram,

Expand Down Expand Up @@ -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()
Expand All @@ -79,6 +117,7 @@ impl Export {
name: format!("{}.{}", &module.name, &func.name),
doc: func.doc.clone(),
parameters,
return_type,
program,
definitions,
})
Expand Down

0 comments on commit 9385f63

Please sign in to comment.