diff --git a/crates/uplc/src/machine/runtime.rs b/crates/uplc/src/machine/runtime.rs index 795acb82..3d59307a 100644 --- a/crates/uplc/src/machine/runtime.rs +++ b/crates/uplc/src/machine/runtime.rs @@ -663,7 +663,7 @@ impl DefaultFunction { let constr_data = PlutusData::Constr(Constr { // TODO: handle other types of constructor tags - tag: (*i as u64) + 121, + tag: convert_constr_to_tag(*i as u64), any_constructor: None, fields: MaybeIndefArray::Indef(data_list), }); @@ -724,7 +724,7 @@ impl DefaultFunction { Type::Integer, Type::List(Box::new(Type::Data)), // TODO: handle other types of constructor tags - Box::new(Constant::Integer(c.tag as isize - 121)), + Box::new(Constant::Integer(convert_tag_to_constr(c.tag as isize))), Box::new(Constant::ProtoList( Type::Data, c.fields @@ -813,3 +813,23 @@ impl DefaultFunction { } } } + +fn convert_tag_to_constr(tag: isize) -> isize { + if tag < 128 { + tag - 121 + } else if (1280..1401).contains(&tag) { + tag - 1280 + } else { + todo!() + } +} + +fn convert_constr_to_tag(constr: u64) -> u64 { + if constr < 7 { + constr + 121 + } else if constr < 128 { + constr + 1280 + } else { + todo!() + } +} diff --git a/crates/uplc/src/pretty.rs b/crates/uplc/src/pretty.rs index 551f6f18..fd9afaae 100644 --- a/crates/uplc/src/pretty.rs +++ b/crates/uplc/src/pretty.rs @@ -186,13 +186,13 @@ impl Constant { RcDoc::text(","), )) .append(RcDoc::text("]")), - Constant::ProtoPair(r#type1, r#type2, left, right) => RcDoc::text("(") + Constant::ProtoPair(type1, type2, left, right) => RcDoc::text("(") .append( RcDoc::text("pair") .append(RcDoc::line()) - .append(r#type1.to_doc()) + .append(type1.to_doc()) .append(RcDoc::line()) - .append(r#type2.to_doc()), + .append(type2.to_doc()), ) .append(RcDoc::line_()) .append(RcDoc::text(")")) @@ -250,13 +250,13 @@ impl Type { ) .append(RcDoc::line_()) .append(RcDoc::text(")")), - Type::Pair(r#type1, r#type2) => RcDoc::text("(") + Type::Pair(type1, type2) => RcDoc::text("(") .append( RcDoc::text("list") .append(RcDoc::line()) - .append(r#type1.to_doc()) + .append(type1.to_doc()) .append(RcDoc::line()) - .append(r#type2.to_doc()), + .append(type2.to_doc()), ) .append(RcDoc::line_()) .append(RcDoc::text(")")),