Allow to trace expressions (and not only string literals)

This however enforces that the argument unifies to a `String`. So this
  is more flexible than the previous form, but does fundamentally the
  same thing.

  Fixes #378.
This commit is contained in:
KtorZ
2023-02-15 18:46:07 +01:00
parent 4e51e49fe6
commit 7abd76b6ad
10 changed files with 185 additions and 42 deletions

View File

@@ -651,19 +651,21 @@ impl<'a> CodeGenerator<'a> {
ir_stack.append(&mut elems_air);
}
TypedExpr::Trace {
tipo, then, text, ..
} => {
let mut scope = scope;
ir_stack.push(Air::Trace {
text: text.clone(),
tipo: tipo.clone(),
scope: scope.clone(),
});
scope.push(self.id_gen.next());
self.build_ir(text, ir_stack, scope.clone());
scope.push(self.id_gen.next());
self.build_ir(then, ir_stack, scope);
}
@@ -3504,13 +3506,12 @@ impl<'a> CodeGenerator<'a> {
label,
};
}
Air::Trace { tipo, scope, text } => {
Air::Trace { tipo, scope } => {
let mut replaced_type = tipo.clone();
replace_opaque_type(&mut replaced_type, self.data_types.clone());
ir_stack[index] = Air::Trace {
scope,
text,
tipo: replaced_type,
};
}
@@ -5631,19 +5632,13 @@ impl<'a> CodeGenerator<'a> {
arg_stack.push(term);
}
Air::Trace { text, .. } => {
Air::Trace { .. } => {
let text = arg_stack.pop().unwrap();
let term = arg_stack.pop().unwrap();
let term = apply_wrap(
apply_wrap(
Term::Builtin(DefaultFunction::Trace).force_wrap(),
Term::Constant(
UplcConstant::String(
text.unwrap_or_else(|| "aiken::trace".to_string()),
)
.into(),
),
),
apply_wrap(Term::Builtin(DefaultFunction::Trace).force_wrap(), text),
Term::Delay(term.into()),
)
.force_wrap();