fix: changed how list_access_to_uplc handles discards fixing unit test 55
Also fix incorrect error message in runtime in machine
This commit is contained in:
parent
ddef61a855
commit
e92d9af3c2
|
@ -552,28 +552,125 @@ pub fn list_access_to_uplc(
|
||||||
};
|
};
|
||||||
|
|
||||||
if names.len() == 1 && tail {
|
if names.len() == 1 && tail {
|
||||||
Term::Lambda {
|
if first == "_" && names[0] == "_" {
|
||||||
parameter_name: Name {
|
Term::Lambda {
|
||||||
text: format!("tail_index_{}_{}", current_index, id_list[current_index]),
|
parameter_name: Name {
|
||||||
unique: 0.into(),
|
text: "_".to_string(),
|
||||||
|
unique: 0.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
body: term.into(),
|
||||||
}
|
}
|
||||||
.into(),
|
} else if first == "_" {
|
||||||
body: apply_wrap(
|
Term::Lambda {
|
||||||
Term::Lambda {
|
parameter_name: Name {
|
||||||
parameter_name: Name {
|
text: format!("tail_index_{}_{}", current_index, id_list[current_index]),
|
||||||
text: first.clone(),
|
unique: 0.into(),
|
||||||
unique: 0.into(),
|
}
|
||||||
}
|
.into(),
|
||||||
.into(),
|
body: apply_wrap(
|
||||||
body: apply_wrap(
|
Term::Lambda {
|
||||||
Term::Lambda {
|
parameter_name: Name {
|
||||||
parameter_name: Name {
|
text: names[0].clone(),
|
||||||
text: names[0].clone(),
|
unique: 0.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
body: term.into(),
|
||||||
|
},
|
||||||
|
apply_wrap(
|
||||||
|
Term::Builtin(DefaultFunction::TailList).force_wrap(),
|
||||||
|
Term::Var(
|
||||||
|
Name {
|
||||||
|
text: format!(
|
||||||
|
"tail_index_{}_{}",
|
||||||
|
current_index, id_list[current_index]
|
||||||
|
),
|
||||||
unique: 0.into(),
|
unique: 0.into(),
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
body: term.into(),
|
),
|
||||||
},
|
),
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
}
|
||||||
|
} else if names[0] == "_" {
|
||||||
|
Term::Lambda {
|
||||||
|
parameter_name: Name {
|
||||||
|
text: format!("tail_index_{}_{}", current_index, id_list[current_index]),
|
||||||
|
unique: 0.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
body: apply_wrap(
|
||||||
|
Term::Lambda {
|
||||||
|
parameter_name: Name {
|
||||||
|
text: first.clone(),
|
||||||
|
unique: 0.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
body: term.into(),
|
||||||
|
},
|
||||||
|
head_list,
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Term::Lambda {
|
||||||
|
parameter_name: Name {
|
||||||
|
text: format!("tail_index_{}_{}", current_index, id_list[current_index]),
|
||||||
|
unique: 0.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
body: apply_wrap(
|
||||||
|
Term::Lambda {
|
||||||
|
parameter_name: Name {
|
||||||
|
text: first.clone(),
|
||||||
|
unique: 0.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
body: apply_wrap(
|
||||||
|
Term::Lambda {
|
||||||
|
parameter_name: Name {
|
||||||
|
text: names[0].clone(),
|
||||||
|
unique: 0.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
body: term.into(),
|
||||||
|
},
|
||||||
|
apply_wrap(
|
||||||
|
Term::Builtin(DefaultFunction::TailList).force_wrap(),
|
||||||
|
Term::Var(
|
||||||
|
Name {
|
||||||
|
text: format!(
|
||||||
|
"tail_index_{}_{}",
|
||||||
|
current_index, id_list[current_index]
|
||||||
|
),
|
||||||
|
unique: 0.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
},
|
||||||
|
head_list,
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if names.is_empty() {
|
||||||
|
if first == "_" {
|
||||||
|
Term::Lambda {
|
||||||
|
parameter_name: Name {
|
||||||
|
text: if check_last_item {
|
||||||
|
format!("tail_index_{}_{}", current_index, id_list[current_index])
|
||||||
|
} else {
|
||||||
|
"_".to_string()
|
||||||
|
},
|
||||||
|
unique: 0.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
body: if check_last_item {
|
||||||
|
delayed_choose_list(
|
||||||
apply_wrap(
|
apply_wrap(
|
||||||
Term::Builtin(DefaultFunction::TailList).force_wrap(),
|
Term::Builtin(DefaultFunction::TailList).force_wrap(),
|
||||||
Term::Var(
|
Term::Var(
|
||||||
|
@ -587,15 +684,29 @@ pub fn list_access_to_uplc(
|
||||||
.into(),
|
.into(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
term,
|
||||||
|
apply_wrap(
|
||||||
|
apply_wrap(
|
||||||
|
Term::Builtin(DefaultFunction::Trace).force_wrap(),
|
||||||
|
Term::Constant(
|
||||||
|
UplcConstant::String(
|
||||||
|
"List/Tuple/Constr contains more items than expected"
|
||||||
|
.to_string(),
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Term::Delay(Term::Error.into()),
|
||||||
|
)
|
||||||
|
.force_wrap(),
|
||||||
)
|
)
|
||||||
.into(),
|
.into()
|
||||||
|
} else {
|
||||||
|
term.into()
|
||||||
},
|
},
|
||||||
head_list,
|
}
|
||||||
)
|
} else {
|
||||||
.into(),
|
Term::Lambda {
|
||||||
}
|
|
||||||
} else if names.is_empty() {
|
|
||||||
Term::Lambda {
|
|
||||||
parameter_name: Name {
|
parameter_name: Name {
|
||||||
text: format!("tail_index_{}_{}", current_index, id_list[current_index]),
|
text: format!("tail_index_{}_{}", current_index, id_list[current_index]),
|
||||||
unique: 0.into(),
|
unique: 0.into(),
|
||||||
|
@ -629,7 +740,7 @@ pub fn list_access_to_uplc(
|
||||||
Term::Builtin(DefaultFunction::Trace).force_wrap(),
|
Term::Builtin(DefaultFunction::Trace).force_wrap(),
|
||||||
Term::Constant(
|
Term::Constant(
|
||||||
UplcConstant::String(
|
UplcConstant::String(
|
||||||
"List/Tuple/Constr contains more items than it should"
|
"List/Tuple/Constr contains more items than it expected"
|
||||||
.to_string(),
|
.to_string(),
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
|
@ -648,51 +759,172 @@ pub fn list_access_to_uplc(
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
Term::Lambda {
|
} else if first == "_" {
|
||||||
parameter_name: Name {
|
let mut list_access_inner = list_access_to_uplc(
|
||||||
text: format!("tail_index_{}_{}", current_index, id_list[current_index]),
|
names,
|
||||||
unique: 0.into(),
|
id_list,
|
||||||
}
|
tail,
|
||||||
.into(),
|
current_index + 1,
|
||||||
body: apply_wrap(
|
term,
|
||||||
Term::Lambda {
|
tipos.to_owned(),
|
||||||
parameter_name: Name {
|
check_last_item,
|
||||||
text: first.clone(),
|
is_list_accessor,
|
||||||
unique: 0.into(),
|
);
|
||||||
|
|
||||||
|
list_access_inner = match &list_access_inner {
|
||||||
|
Term::Lambda {
|
||||||
|
parameter_name,
|
||||||
|
body,
|
||||||
|
} => {
|
||||||
|
if ¶meter_name.text == "_" {
|
||||||
|
body.as_ref().clone()
|
||||||
|
} else {
|
||||||
|
Term::Lambda {
|
||||||
|
parameter_name: Name {
|
||||||
|
text: format!(
|
||||||
|
"tail_index_{}_{}",
|
||||||
|
current_index, id_list[current_index]
|
||||||
|
),
|
||||||
|
unique: 0.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
body: apply_wrap(
|
||||||
|
list_access_inner,
|
||||||
|
apply_wrap(
|
||||||
|
Term::Builtin(DefaultFunction::TailList).force_wrap(),
|
||||||
|
Term::Var(
|
||||||
|
Name {
|
||||||
|
text: format!(
|
||||||
|
"tail_index_{}_{}",
|
||||||
|
current_index, id_list[current_index]
|
||||||
|
),
|
||||||
|
unique: 0.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
}
|
}
|
||||||
.into(),
|
}
|
||||||
body: apply_wrap(
|
}
|
||||||
list_access_to_uplc(
|
_ => list_access_inner,
|
||||||
names,
|
};
|
||||||
id_list,
|
|
||||||
tail,
|
match &list_access_inner {
|
||||||
current_index + 1,
|
Term::Lambda { .. } => list_access_inner,
|
||||||
term,
|
_ => Term::Lambda {
|
||||||
tipos.to_owned(),
|
parameter_name: Name {
|
||||||
check_last_item,
|
text: "_".to_string(),
|
||||||
is_list_accessor,
|
unique: 0.into(),
|
||||||
),
|
}
|
||||||
apply_wrap(
|
.into(),
|
||||||
Term::Builtin(DefaultFunction::TailList).force_wrap(),
|
body: list_access_inner.into(),
|
||||||
Term::Var(
|
},
|
||||||
Name {
|
}
|
||||||
text: format!(
|
} else {
|
||||||
"tail_index_{}_{}",
|
let mut list_access_inner = list_access_to_uplc(
|
||||||
current_index, id_list[current_index]
|
names,
|
||||||
),
|
id_list,
|
||||||
|
tail,
|
||||||
|
current_index + 1,
|
||||||
|
term,
|
||||||
|
tipos.to_owned(),
|
||||||
|
check_last_item,
|
||||||
|
is_list_accessor,
|
||||||
|
);
|
||||||
|
|
||||||
|
list_access_inner = match &list_access_inner {
|
||||||
|
Term::Lambda {
|
||||||
|
parameter_name,
|
||||||
|
body,
|
||||||
|
} => {
|
||||||
|
if ¶meter_name.text == "_" {
|
||||||
|
Term::Lambda {
|
||||||
|
parameter_name: Name {
|
||||||
|
text: format!(
|
||||||
|
"tail_index_{}_{}",
|
||||||
|
current_index, id_list[current_index]
|
||||||
|
),
|
||||||
|
unique: 0.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
body: apply_wrap(
|
||||||
|
Term::Lambda {
|
||||||
|
parameter_name: Name {
|
||||||
|
text: first.clone(),
|
||||||
unique: 0.into(),
|
unique: 0.into(),
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
|
body: body.as_ref().clone().into(),
|
||||||
|
},
|
||||||
|
head_list,
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Term::Lambda {
|
||||||
|
parameter_name: Name {
|
||||||
|
text: format!(
|
||||||
|
"tail_index_{}_{}",
|
||||||
|
current_index, id_list[current_index]
|
||||||
),
|
),
|
||||||
),
|
unique: 0.into(),
|
||||||
)
|
}
|
||||||
.into(),
|
.into(),
|
||||||
},
|
body: apply_wrap(
|
||||||
head_list,
|
Term::Lambda {
|
||||||
)
|
parameter_name: Name {
|
||||||
.into(),
|
text: first.clone(),
|
||||||
}
|
unique: 0.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
body: apply_wrap(
|
||||||
|
list_access_inner,
|
||||||
|
apply_wrap(
|
||||||
|
Term::Builtin(DefaultFunction::TailList).force_wrap(),
|
||||||
|
Term::Var(
|
||||||
|
Name {
|
||||||
|
text: format!(
|
||||||
|
"tail_index_{}_{}",
|
||||||
|
current_index, id_list[current_index]
|
||||||
|
),
|
||||||
|
unique: 0.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
},
|
||||||
|
head_list,
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => Term::Lambda {
|
||||||
|
parameter_name: Name {
|
||||||
|
text: format!("tail_index_{}_{}", current_index, id_list[current_index]),
|
||||||
|
unique: 0.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
body: apply_wrap(
|
||||||
|
Term::Lambda {
|
||||||
|
parameter_name: Name {
|
||||||
|
text: first.clone(),
|
||||||
|
unique: 0.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
body: list_access_inner.into(),
|
||||||
|
},
|
||||||
|
head_list,
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
list_access_inner
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
term
|
term
|
||||||
|
|
|
@ -1042,7 +1042,7 @@ impl DefaultFunction {
|
||||||
)
|
)
|
||||||
.into()),
|
.into()),
|
||||||
v => Err(Error::DeserialisationError(
|
v => Err(Error::DeserialisationError(
|
||||||
"UnMapData".to_string(),
|
"UnListData".to_string(),
|
||||||
Value::Con(v.clone().into()),
|
Value::Con(v.clone().into()),
|
||||||
)),
|
)),
|
||||||
},
|
},
|
||||||
|
@ -1057,7 +1057,7 @@ impl DefaultFunction {
|
||||||
Ok(Value::Con(Constant::Integer(from_pallas_bigint(b)).into()).into())
|
Ok(Value::Con(Constant::Integer(from_pallas_bigint(b)).into()).into())
|
||||||
}
|
}
|
||||||
v => Err(Error::DeserialisationError(
|
v => Err(Error::DeserialisationError(
|
||||||
"UnMapData".to_string(),
|
"UnIData".to_string(),
|
||||||
Value::Con(v.clone().into()),
|
Value::Con(v.clone().into()),
|
||||||
)),
|
)),
|
||||||
},
|
},
|
||||||
|
@ -1072,7 +1072,7 @@ impl DefaultFunction {
|
||||||
Ok(Value::Con(Constant::ByteString(b.to_vec()).into()).into())
|
Ok(Value::Con(Constant::ByteString(b.to_vec()).into()).into())
|
||||||
}
|
}
|
||||||
v => Err(Error::DeserialisationError(
|
v => Err(Error::DeserialisationError(
|
||||||
"UnMapData".to_string(),
|
"UnBData".to_string(),
|
||||||
Value::Con(v.clone().into()),
|
Value::Con(v.clone().into()),
|
||||||
)),
|
)),
|
||||||
},
|
},
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
"title": "Data",
|
"title": "Data",
|
||||||
"description": "Any Plutus data."
|
"description": "Any Plutus data."
|
||||||
},
|
},
|
||||||
"compiledCode": "59013d010000323232323232322225333004323232323233001003232323322323232323330120014a0944004c94ccc0500045288a5000133223233223253330153370e00290010801099190009bab301b00130110033015375400400297adef6c6033223300800200100200100100237566601260140049001001a441050000000000003001001222533301000213374a900125eb804c8c8c8c94ccc044cdc7802800899ba548000cc054dd300125eb804ccc01c01c00c014dd718088019bab3011002301400330120023001001222533300d00214a026464a666018600600429444ccc01401400400cc04400cc03c008dd6198009801198009801001a400090021119199800800a4000006444666601466e1c01000803c8ccc010010cdc0001a400460220020024600e6ea8004526165734aae7555cf2ab9f5740ae855d101",
|
"compiledCode": "59015f010000323232323232323232322225333006323232323233001003232323322323232323330140014a0944004c94ccc05c0045288a5000133223233223253330173370e00290010801099190009bab301e00130110033018375400400297adef6c6033223300800200100200100100237566601260140049001001a441050000000000003001001222533301300213374a900125eb804c8c8c8c94ccc04ccdc7802800899ba548000cc060dd300125eb804ccc01c01c00c014dd7180a0019bab3014002301700330150023001001222533301000214a026464a66601c600600429444ccc01401400400cc05000cc048008dd6198009801198009801001a400090021119199800800a4000006444666601866e1c0100080488ccc010010cdc0001a40046028002002460146ea8004526163001001222533300800214984cc014c004c028008ccc00c00cc02c0080055cd2b9b5573aaae7955cfaba05742ae89",
|
||||||
"hash": "cd1b163efdcf1680c020a03752dca86a4cc9c4fd37148bc7c9be87ec"
|
"hash": "3f46b921ead33594e1da4afa1f1ba31807c0d8deca029f96fe9fe394"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -29,8 +29,8 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"compiledCode": "500100003222253330044a22930b2b9a01",
|
"compiledCode": "583b0100003232323232323222253330064a22930b180080091129998030010a4c26600a6002600e0046660060066010004002ae695cdaab9f5742ae89",
|
||||||
"hash": "90592520b329fe08f0e93946ecd405e49b7480795e27cb618f002d88"
|
"hash": "e37db487fbd58c45d059bcbf5cd6b1604d3bec16cf888f1395a4ebc4"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -15,8 +15,8 @@
|
||||||
"title": "Data",
|
"title": "Data",
|
||||||
"description": "Any Plutus data."
|
"description": "Any Plutus data."
|
||||||
},
|
},
|
||||||
"compiledCode": "582b010000323222253330043370e64640026eb4c0180052f7b630010104000101010048020526165734aae741",
|
"compiledCode": "586001000032323232323232323222253330063370e6464640046eb4c02c008dd69804800a5ef6c6010104000101010048020526163001001222533300800214984cc014c004c024008ccc00c00cc0280080055cd2b9b5573aaae7955cfaba157441",
|
||||||
"hash": "5d97657f60a5566b7bf85d235541761df0468a5be3c30946f9ed304e"
|
"hash": "7ecbfc3ae91c4d5ba3799b4d283e385d457c860cd22034d825379ae2"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
Loading…
Reference in New Issue