xo-expression: + Apply expressions
This commit is contained in:
parent
2d94fd51bf
commit
d6371ee369
6 changed files with 64 additions and 6 deletions
|
|
@ -11,21 +11,47 @@
|
|||
|
||||
namespace xo {
|
||||
namespace ast {
|
||||
|
||||
/** @class Apply
|
||||
* @brief syntax for a function call.
|
||||
*
|
||||
* In general we don't know function to be invoked
|
||||
* until runtime, depending on the nature of Expression.
|
||||
*
|
||||
* For first cut, we'll just handle the case of a Constant
|
||||
* that refers to a known function
|
||||
**/
|
||||
class Apply : public Expression {
|
||||
ref::rp<Expression> fn_;
|
||||
std::vector<ref::rp<Expression>> args_;
|
||||
};
|
||||
} /*namespace ast*/
|
||||
public:
|
||||
Apply(const ref::rp<Expression> & fn,
|
||||
const std::vector<ref::rp<Expression>> & argv)
|
||||
: Expression(exprtype::apply), fn_{fn}, argv_(argv)
|
||||
{}
|
||||
|
||||
/** downcast from Expression **/
|
||||
static ref::brw<Apply> from(ref::brw<Expression> x) {
|
||||
return ref::brw<Apply>::from(x);
|
||||
}
|
||||
|
||||
const ref::rp<Expression> & fn() const { return fn_; }
|
||||
const std::vector<ref::rp<Expression>> & argv() const { return argv_; }
|
||||
|
||||
virtual void display(std::ostream & os) const;
|
||||
|
||||
private:
|
||||
/** function to invoke **/
|
||||
ref::rp<Expression> fn_;
|
||||
/** argument expressions, in l-to-r order **/
|
||||
std::vector<ref::rp<Expression>> argv_;
|
||||
}; /*Apply*/
|
||||
|
||||
inline ref::rp<Apply>
|
||||
make_apply(const ref::rp<Expression> & fn,
|
||||
const ref::rp<Expression> & arg1) {
|
||||
std::vector<ref::rp<Expression>> argv;
|
||||
argv.push_back(arg1);
|
||||
|
||||
return new Apply(fn, argv);
|
||||
} /*make_apply*/
|
||||
|
||||
} /*namespace ast*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue