Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions crates/tx3-lang/src/applying.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ fn arg_value_into_expr(arg: ArgValue) -> ir::Expression {
ArgValue::Bytes(x) => ir::Expression::Bytes(x),
ArgValue::UtxoSet(x) => ir::Expression::UtxoSet(x),
ArgValue::UtxoRef(x) => ir::Expression::UtxoRefs(vec![x]),
ArgValue::List(x) => ir::Expression::List(x.into_iter().map(arg_value_into_expr).collect()),
ArgValue::Custom(x) => ir::Expression::Struct(ir::StructExpr {
constructor: x.constructor,
fields: x.fields.into_iter().map(arg_value_into_expr).collect(),
}),
}
}

Expand Down
8 changes: 8 additions & 0 deletions crates/tx3-lang/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ impl Eq for Utxo {}

pub type UtxoSet = HashSet<Utxo>;

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct CustomValue {
pub constructor: usize,
pub fields: Vec<ArgValue>,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum ArgValue {
Int(i128),
Expand All @@ -101,6 +107,8 @@ pub enum ArgValue {
Address(Vec<u8>),
UtxoSet(UtxoSet),
UtxoRef(UtxoRef),
List(Vec<ArgValue>),
Custom(CustomValue),
}

impl From<Vec<u8>> for ArgValue {
Expand Down
13 changes: 10 additions & 3 deletions crates/tx3-lang/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,7 @@ impl IntoLower for ast::PolicyDef {

impl IntoLower for ast::Type {
type Output = ir::Type;

fn into_lower(&self, _: &Context) -> Result<Self::Output, Error> {
fn into_lower(&self, ctx: &Context) -> Result<Self::Output, Error> {
match self {
ast::Type::Undefined => Ok(ir::Type::Undefined),
ast::Type::Unit => Ok(ir::Type::Unit),
Expand All @@ -350,7 +349,15 @@ impl IntoLower for ast::Type {
ast::Type::AnyAsset => Ok(ir::Type::AnyAsset),
ast::Type::List(_) => Ok(ir::Type::List),
ast::Type::Map(_, _) => Ok(ir::Type::Map),
ast::Type::Custom(x) => Ok(ir::Type::Custom(x.value.clone())),
ast::Type::Custom(x) => {
// Check if this custom type is actually a type alias
if let Some(symbol) = &x.symbol {
if let Some(alias_def) = symbol.as_alias_def() {
return alias_def.alias_type.into_lower(ctx);
}
}
Ok(ir::Type::Custom(x.value.clone()))
}
}
}
}
Expand Down