finish uplc code gen for complex clauses with constr

This commit is contained in:
Kasey White 2022-12-03 04:57:37 -05:00 committed by Lucas
parent f48039fd4f
commit 8cbdf97d22
1 changed files with 125 additions and 17 deletions

View File

@ -1751,7 +1751,10 @@ impl<'a> CodeGenerator<'a> {
arg_stack.push(term); arg_stack.push(term);
} }
IR::Clause { IR::Clause {
tipo, subject_name, .. tipo,
subject_name,
complex_clause,
..
} => { } => {
// clause to compare // clause to compare
let clause = arg_stack.pop().unwrap(); let clause = arg_stack.pop().unwrap();
@ -1804,6 +1807,42 @@ impl<'a> CodeGenerator<'a> {
} }
}; };
if complex_clause {
term = Term::Apply {
function: Term::Lambda {
parameter_name: Name {
text: "__other_clauses_delayed".to_string(),
unique: 0.into(),
},
body: Term::Apply {
function: Term::Apply {
function: Term::Apply {
function: Term::Builtin(DefaultFunction::IfThenElse)
.force_wrap()
.into(),
argument: Term::Apply {
function: checker.into(),
argument: clause.into(),
}
.into(),
}
.into(),
argument: Term::Delay(body.into()).into(),
}
.into(),
argument: Term::Var(Name {
text: "__other_clauses_delayed".to_string(),
unique: 0.into(),
})
.into(),
}
.into(),
}
.into(),
argument: Term::Delay(term.into()).into(),
}
.force_wrap()
} else {
term = Term::Apply { term = Term::Apply {
function: Term::Apply { function: Term::Apply {
function: Term::Apply { function: Term::Apply {
@ -1821,15 +1860,84 @@ impl<'a> CodeGenerator<'a> {
argument: Term::Delay(term.into()).into(), argument: Term::Delay(term.into()).into(),
} }
.force_wrap(); .force_wrap();
}
arg_stack.push(term); arg_stack.push(term);
} }
IR::ClauseGuard { .. } => { IR::ClauseGuard {
let _condition = arg_stack.pop().unwrap(); subject_name, tipo, ..
} => {
let condition = arg_stack.pop().unwrap();
let _then = arg_stack.pop().unwrap(); let then = arg_stack.pop().unwrap();
todo!(); let checker = if tipo.is_int() {
Term::Apply {
function: DefaultFunction::EqualsInteger.into(),
argument: Term::Var(Name {
text: subject_name,
unique: 0.into(),
})
.into(),
}
} else if tipo.is_bytearray() {
Term::Apply {
function: DefaultFunction::EqualsByteString.into(),
argument: Term::Var(Name {
text: subject_name,
unique: 0.into(),
})
.into(),
}
} else if tipo.is_bool() {
todo!()
} else if tipo.is_string() {
Term::Apply {
function: DefaultFunction::EqualsString.into(),
argument: Term::Var(Name {
text: subject_name,
unique: 0.into(),
})
.into(),
}
} else if tipo.is_list() {
todo!()
} else {
Term::Apply {
function: DefaultFunction::EqualsInteger.into(),
argument: Term::Var(Name {
text: subject_name,
unique: 0.into(),
})
.into(),
}
};
let term = Term::Apply {
function: Term::Apply {
function: Term::Apply {
function: Term::Builtin(DefaultFunction::IfThenElse)
.force_wrap()
.into(),
argument: Term::Apply {
function: checker.into(),
argument: condition.into(),
}
.into(),
}
.into(),
argument: Term::Delay(then.into()).into(),
}
.into(),
argument: Term::Var(Name {
text: "__other_clauses_delayed".to_string(),
unique: 0.into(),
})
.into(),
}
.force_wrap();
arg_stack.push(term);
} }
IR::Finally { .. } => { IR::Finally { .. } => {
let _clause = arg_stack.pop().unwrap(); let _clause = arg_stack.pop().unwrap();