feat(project): create export type
Co-authored-by: Kasey White <kwhitemsg@gmail.com>
This commit is contained in:
parent
9d49be46b8
commit
f50f7e42db
|
@ -0,0 +1,26 @@
|
||||||
|
use uplc::ast::{DeBruijn, Program};
|
||||||
|
|
||||||
|
use crate::blueprint::{
|
||||||
|
definitions::Definitions,
|
||||||
|
parameter::Parameter,
|
||||||
|
schema::{Annotated, Schema},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
|
pub struct Export {
|
||||||
|
pub name: String,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub doc: Option<String>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||||
|
#[serde(default)]
|
||||||
|
pub parameters: Vec<Parameter>,
|
||||||
|
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub program: Program<DeBruijn>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Definitions::is_empty")]
|
||||||
|
#[serde(default)]
|
||||||
|
pub definitions: Definitions<Annotated<Schema>>,
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ pub mod config;
|
||||||
pub mod deps;
|
pub mod deps;
|
||||||
pub mod docs;
|
pub mod docs;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
|
pub mod export;
|
||||||
pub mod format;
|
pub mod format;
|
||||||
pub mod github;
|
pub mod github;
|
||||||
pub mod module;
|
pub mod module;
|
||||||
|
@ -31,11 +32,11 @@ use crate::{
|
||||||
};
|
};
|
||||||
use aiken_lang::{
|
use aiken_lang::{
|
||||||
ast::{
|
ast::{
|
||||||
DataTypeKey, Definition, FunctionAccessKey, ModuleKind, Span, Tracing, TypedDataType,
|
DataTypeKey, Definition, FunctionAccessKey, ModuleKind, Tracing, TypedDataType,
|
||||||
TypedFunction,
|
TypedFunction,
|
||||||
},
|
},
|
||||||
builtins::{self, function},
|
builtins::{self},
|
||||||
expr::{TypedExpr, UntypedExpr},
|
expr::UntypedExpr,
|
||||||
gen_uplc::CodeGenerator,
|
gen_uplc::CodeGenerator,
|
||||||
line_numbers::LineNumbers,
|
line_numbers::LineNumbers,
|
||||||
tipo::{Type, TypeInfo},
|
tipo::{Type, TypeInfo},
|
||||||
|
@ -471,28 +472,14 @@ where
|
||||||
.get(module)
|
.get(module)
|
||||||
.and_then(|checked_module| {
|
.and_then(|checked_module| {
|
||||||
checked_module.ast.definitions().find_map(|def| match def {
|
checked_module.ast.definitions().find_map(|def| match def {
|
||||||
Definition::Fn(func) if func.name == name => {
|
Definition::Fn(func) if func.name == name => Some(func),
|
||||||
let typed_anon = TypedExpr::Fn {
|
|
||||||
location: Span::empty(),
|
|
||||||
tipo: function(
|
|
||||||
func.arguments.iter().map(|arg| arg.tipo.clone()).collect(),
|
|
||||||
func.return_type.clone(),
|
|
||||||
),
|
|
||||||
is_capture: false,
|
|
||||||
args: func.arguments.clone(),
|
|
||||||
body: func.body.clone().into(),
|
|
||||||
return_annotation: None,
|
|
||||||
};
|
|
||||||
|
|
||||||
Some(typed_anon)
|
|
||||||
}
|
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.map(|body| {
|
.map(|func| {
|
||||||
let program = generator.generate_raw(&body, &[], module);
|
let program = generator.generate_raw(&func.body, &func.arguments, module);
|
||||||
|
|
||||||
program.to_pretty()
|
program.to_debruijn().unwrap().to_hex().unwrap()
|
||||||
})
|
})
|
||||||
.ok_or_else(|| Error::ExportNotFound {
|
.ok_or_else(|| Error::ExportNotFound {
|
||||||
module: module.to_string(),
|
module: module.to_string(),
|
||||||
|
|
Loading…
Reference in New Issue