67 lines
2.1 KiB
C++
67 lines
2.1 KiB
C++
/** @file Lambda.hpp
|
|
*
|
|
* Author: Roland Conybeare
|
|
**/
|
|
|
|
#pragma once
|
|
|
|
#include "Expression.hpp"
|
|
#include <vector>
|
|
#include <string>
|
|
//#include <cstdint>
|
|
|
|
namespace xo {
|
|
namespace ast {
|
|
/** @class Lambda
|
|
* @brief abstract syntax tree for a function definition
|
|
*
|
|
**/
|
|
class Lambda : public Expression {
|
|
public:
|
|
/** @p argv Formal parameters, in left-to-right order
|
|
* @p body Expression for body of this function
|
|
**/
|
|
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} {}
|
|
|
|
/** downcast from Expression **/
|
|
static ref::brw<Lambda> from(ref::brw<Expression> x) {
|
|
return ref::brw<Lambda>::from(x);
|
|
}
|
|
|
|
const std::string & name() const { return name_; }
|
|
const std::vector<std::string> & argv() const { return argv_; }
|
|
const ref::rp<Expression> & body() const { return body_; }
|
|
|
|
// ----- Expression -----
|
|
|
|
virtual void display(std::ostream & os) const override;
|
|
|
|
private:
|
|
/** lambda name. Initially supporting only form like
|
|
* (define (foo x y z)
|
|
* (+ (* x x) (* y y) (* z z)))
|
|
*
|
|
* In any case need to supply names for distinct things-for-which-code-is-generated
|
|
* so that they can be linked etc.
|
|
**/
|
|
std::string name_;
|
|
/** formal argument names **/
|
|
std::vector<std::string> argv_;
|
|
/** function body **/
|
|
ref::rp<Expression> body_;
|
|
}; /*Lambda*/
|
|
|
|
inline ref::rp<Lambda>
|
|
make_lambda(const std::string & name,
|
|
const std::vector<std::string> & argv,
|
|
const ref::rp<Expression> & body)
|
|
{
|
|
return new Lambda(name, argv, body);
|
|
}
|
|
} /*namespace ast*/
|
|
} /*namespace xo*/
|
|
|
|
/** end Lambda.hpp **/
|