xo-expression: add explicit types to all Expressions

This commit is contained in:
Roland Conybeare 2024-06-18 16:55:46 -04:00
commit 9ff173f68a
12 changed files with 223 additions and 54 deletions

View file

@ -4,7 +4,29 @@
#include "xo/indentlog/print/vector.hpp"
namespace xo {
using xo::ref::rp;
namespace ast {
rp<Apply>
Apply::make(const rp<Expression> & fn,
const std::vector<rp<Expression>> & argv)
{
/* extract result type from function type */
TypeDescr fn_valuetype = fn->valuetype();
if (!fn_valuetype->is_function()) {
throw std::runtime_error
(tostr("Apply::make: found expression F in function position,"
" with value-type FT where a function type expected",
xtag("FT", fn_valuetype->short_name()),
xtag("F", fn_valuetype)));
}
TypeDescr fn_retval_type = fn_valuetype->fn_retval();
return new Apply(fn_retval_type, fn, argv);
}
void
Apply::display(std::ostream & os) const {
os << "<Apply"