/* @file Apply.cpp */ #include "Apply.hpp" #include "Primitive.hpp" #include "exprtype.hpp" #include "xo/indentlog/print/vector.hpp" #include namespace xo { namespace ast { rp Apply::make(const rp & fn, const std::vector> & 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); } rp Apply::make_add2_f64(const rp & lhs, const rp & rhs) { return Apply::make(Primitive_f64::make_add2_f64(), {lhs, rhs}); } rp Apply::make_sub2_f64(const rp & lhs, const rp & rhs) { return Apply::make(Primitive_f64::make_sub2_f64(), {lhs, rhs}); } rp Apply::make_mul2_f64(const rp & lhs, const rp & rhs) { return Apply::make(Primitive_f64::make_mul2_f64(), {lhs, rhs}); } rp Apply::make_div2_f64(const rp & lhs, const rp & rhs) { return Apply::make(Primitive_f64::make_div2_f64(), {lhs, rhs}); } void Apply::attach_envs(bp p) { fn_->attach_envs(p); for (const auto & arg : argv_) arg->attach_envs(p); } void Apply::display(std::ostream & os) const { os << ""; } std::uint32_t Apply::pretty_print(ppstate * pps, bool upto) const { if (upto) { std::uint32_t saved = pps->pos(); if (!pps->has_margin()) return false; if (!pps->print_upto("print_upto(xtag("fn", fn_))) return false; if (!pps->print_upto(xtag("argv", argv_))) return false; return pps->scan_no_newline(saved); } else { std::uint32_t ci0 = pps->lpos(); std::uint32_t ci1 = ci0 + pps->indent_width(); pps->write("newline_indent(ci1); pps->pretty(xtag("fn", fn_)); pps->newline_indent(ci1); pps->pretty(xtag("argv", argv_)); pps->write(">"); return false; } } } /*namespace ast*/ } /*namespace xo*/ /* end Apply.cpp */