xo-expression: + Lambda::type_str
This commit is contained in:
parent
f71cb12831
commit
b18de1b0ce
2 changed files with 29 additions and 2 deletions
|
|
@ -23,8 +23,7 @@ namespace xo {
|
||||||
**/
|
**/
|
||||||
Lambda(const std::string & name,
|
Lambda(const std::string & name,
|
||||||
const std::vector<std::string> & argv,
|
const std::vector<std::string> & argv,
|
||||||
const ref::rp<Expression> & body)
|
const ref::rp<Expression> & body);
|
||||||
: Expression(exprtype::lambda), name_{name}, argv_{argv}, body_{body} {}
|
|
||||||
|
|
||||||
/** downcast from Expression **/
|
/** downcast from Expression **/
|
||||||
static ref::brw<Lambda> from(ref::brw<Expression> x) {
|
static ref::brw<Lambda> from(ref::brw<Expression> x) {
|
||||||
|
|
@ -32,6 +31,7 @@ namespace xo {
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string & name() const { return name_; }
|
const std::string & name() const { return name_; }
|
||||||
|
const std::string & type_str() const { return type_str_; }
|
||||||
const std::vector<std::string> & argv() const { return argv_; }
|
const std::vector<std::string> & argv() const { return argv_; }
|
||||||
const ref::rp<Expression> & body() const { return body_; }
|
const ref::rp<Expression> & body() const { return body_; }
|
||||||
|
|
||||||
|
|
@ -51,6 +51,10 @@ namespace xo {
|
||||||
* so that they can be linked etc.
|
* so that they can be linked etc.
|
||||||
**/
|
**/
|
||||||
std::string name_;
|
std::string name_;
|
||||||
|
/** e.g.
|
||||||
|
* "double(double,double)" for function of two doubles that returns a double
|
||||||
|
**/
|
||||||
|
std::string type_str_;
|
||||||
/** formal argument names **/
|
/** formal argument names **/
|
||||||
std::vector<std::string> argv_;
|
std::vector<std::string> argv_;
|
||||||
/** function body **/
|
/** function body **/
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,30 @@
|
||||||
#include "xo/indentlog/print/vector.hpp"
|
#include "xo/indentlog/print/vector.hpp"
|
||||||
|
|
||||||
namespace xo {
|
namespace xo {
|
||||||
|
using std::stringstream;
|
||||||
|
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
Lambda::Lambda(const std::string & name,
|
||||||
|
const std::vector<std::string> & argv,
|
||||||
|
const ref::rp<Expression> & body)
|
||||||
|
: Expression(exprtype::lambda),
|
||||||
|
name_{name},
|
||||||
|
argv_{argv},
|
||||||
|
body_{body}
|
||||||
|
{
|
||||||
|
stringstream ss;
|
||||||
|
ss << "double";
|
||||||
|
ss << "(";
|
||||||
|
for (std::size_t i = 0; i < argv.size(); ++i) {
|
||||||
|
if (i > 0)
|
||||||
|
ss << ",";
|
||||||
|
ss << "double";
|
||||||
|
}
|
||||||
|
ss << ")";
|
||||||
|
|
||||||
|
type_str_ = ss.str();
|
||||||
|
} /*ctor*/
|
||||||
|
|
||||||
void
|
void
|
||||||
Lambda::display(std::ostream & os) const {
|
Lambda::display(std::ostream & os) const {
|
||||||
os << "<Lambda"
|
os << "<Lambda"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue