From b18de1b0ce51288254a75615f98a50b6a3b1dfd4 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Mon, 17 Jun 2024 17:00:16 -0400 Subject: [PATCH] xo-expression: + Lambda::type_str --- include/xo/expression/Lambda.hpp | 8 ++++++-- src/expression/Lambda.cpp | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/include/xo/expression/Lambda.hpp b/include/xo/expression/Lambda.hpp index 7f5ebab4..06d5857f 100644 --- a/include/xo/expression/Lambda.hpp +++ b/include/xo/expression/Lambda.hpp @@ -23,8 +23,7 @@ namespace xo { **/ Lambda(const std::string & name, const std::vector & argv, - const ref::rp & body) - : Expression(exprtype::lambda), name_{name}, argv_{argv}, body_{body} {} + const ref::rp & body); /** downcast from Expression **/ static ref::brw from(ref::brw x) { @@ -32,6 +31,7 @@ namespace xo { } const std::string & name() const { return name_; } + const std::string & type_str() const { return type_str_; } const std::vector & argv() const { return argv_; } const ref::rp & body() const { return body_; } @@ -51,6 +51,10 @@ namespace xo { * so that they can be linked etc. **/ std::string name_; + /** e.g. + * "double(double,double)" for function of two doubles that returns a double + **/ + std::string type_str_; /** formal argument names **/ std::vector argv_; /** function body **/ diff --git a/src/expression/Lambda.cpp b/src/expression/Lambda.cpp index 87f70759..cae46f6f 100644 --- a/src/expression/Lambda.cpp +++ b/src/expression/Lambda.cpp @@ -4,7 +4,30 @@ #include "xo/indentlog/print/vector.hpp" namespace xo { + using std::stringstream; + namespace ast { + Lambda::Lambda(const std::string & name, + const std::vector & argv, + const ref::rp & 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 Lambda::display(std::ostream & os) const { os << "