From ca19c65b02b2e4bd14438b38df9b45b0992701ae Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Mon, 5 Aug 2024 15:04:34 -0400 Subject: [PATCH] xo-expression: fix: ns xo::ref::rp -> xo::rp --- include/xo/expression/Apply.hpp | 26 ++++++------- include/xo/expression/Constant.hpp | 6 +-- include/xo/expression/Expression.hpp | 4 +- include/xo/expression/GlobalEnv.hpp | 4 +- include/xo/expression/IfExpr.hpp | 40 ++++++++++---------- include/xo/expression/Lambda.hpp | 30 +++++++-------- include/xo/expression/LocalEnv.hpp | 10 ++--- include/xo/expression/PrimitiveInterface.hpp | 2 +- include/xo/expression/Variable.hpp | 10 ++--- src/expression/Apply.cpp | 2 - src/expression/IfExpr.cpp | 2 - src/expression/Lambda.cpp | 9 ++--- 12 files changed, 70 insertions(+), 75 deletions(-) diff --git a/include/xo/expression/Apply.hpp b/include/xo/expression/Apply.hpp index e6de3ac4..f06b8b8b 100644 --- a/include/xo/expression/Apply.hpp +++ b/include/xo/expression/Apply.hpp @@ -25,16 +25,16 @@ namespace xo { public: /** create new apply-expression instance **/ - static ref::rp make(const ref::rp & fn, - const std::vector> & argv); + static rp make(const rp & fn, + const std::vector> & argv); /** downcast from Expression **/ static ref::brw from(ref::brw x) { return ref::brw::from(x); } - const ref::rp & fn() const { return fn_; } - const std::vector> & argv() const { return argv_; } + const rp & fn() const { return fn_; } + const std::vector> & argv() const { return argv_; } virtual std::set get_free_variables() const override { std::set retval = fn_->get_free_variables(); @@ -76,7 +76,7 @@ namespace xo { return n; } - virtual ref::rp xform_layer(TransformFn xform_fn) override { + virtual rp xform_layer(TransformFn xform_fn) override { this->fn_ = fn_->xform_layer(xform_fn); for (auto & arg : argv_) @@ -96,17 +96,17 @@ namespace xo { private: Apply(TypeDescr apply_valuetype, - const ref::rp & fn, - const std::vector> & argv) + const rp & fn, + const std::vector> & argv) : Expression(exprtype::apply, apply_valuetype), fn_{fn}, argv_(argv) {} private: /** function to invoke **/ - ref::rp fn_; + rp fn_; /** argument expressions, in l-to-r order **/ - std::vector> argv_; + std::vector> argv_; }; /*Apply*/ #ifdef NOT_USING @@ -136,10 +136,10 @@ namespace xo { #endif /* reminder: initializer-lists are compile-time only */ - inline ref::rp - make_apply(const ref::rp & fn, - const std::initializer_list> args) { - std::vector> argv(args); + inline rp + make_apply(const rp & fn, + const std::initializer_list> args) { + std::vector> argv(args); return Apply::make(fn, argv); } /*make_apply*/ diff --git a/include/xo/expression/Constant.hpp b/include/xo/expression/Constant.hpp index 3ecf1fe3..77098a5b 100644 --- a/include/xo/expression/Constant.hpp +++ b/include/xo/expression/Constant.hpp @@ -30,7 +30,7 @@ namespace xo { public: /** create constant expression representing literal value x **/ - static ref::rp make(const T & x) { + static rp make(const T & x) { TypeDescr x_valuetype = Reflect::require(); return new Constant(x_valuetype, x); @@ -61,7 +61,7 @@ namespace xo { return 1; } - virtual ref::rp xform_layer(TransformFn xform_fn) override { + virtual rp xform_layer(TransformFn xform_fn) override { return xform_fn(this); } @@ -89,7 +89,7 @@ namespace xo { }; /*Constant*/ template - ref::rp>> + rp>> make_constant(const T & x) { return Constant::make(x); } diff --git a/include/xo/expression/Expression.hpp b/include/xo/expression/Expression.hpp index 89a876d4..cbea3a35 100644 --- a/include/xo/expression/Expression.hpp +++ b/include/xo/expression/Expression.hpp @@ -38,7 +38,7 @@ namespace xo { using VisitFn = std::function )>; using TransformFn = std::function - (ref::brw)>; + (ref::brw)>; using TypeDescr = xo::reflect::TypeDescr; public: @@ -69,7 +69,7 @@ namespace xo { virtual std::size_t visit_layer(VisitFn visitor_fn) = 0; /** traverse ast @ref visit_preorder but do not visit Lambdas **/ - virtual ref::rp xform_layer(TransformFn visitor_fn) = 0; + virtual rp xform_layer(TransformFn visitor_fn) = 0; /** attach an environment to each lambda expression X in this subtree, * that will: diff --git a/include/xo/expression/GlobalEnv.hpp b/include/xo/expression/GlobalEnv.hpp index 010dc296..9cbf328f 100644 --- a/include/xo/expression/GlobalEnv.hpp +++ b/include/xo/expression/GlobalEnv.hpp @@ -14,7 +14,7 @@ namespace xo { class GlobalEnv : public Environment { public: /** create instance. Probably only need one of these **/ - static ref::rp make() { return new GlobalEnv(); } + static rp make() { return new GlobalEnv(); } ref::brw require_global(const std::string & vname, ref::brw expr) { @@ -51,7 +51,7 @@ namespace xo { /* for assignable globals, need to allocate memory * addresses for these. */ - std::map> global_map_; + std::map> global_map_; }; } /*namespace ast*/ } /*namespace xo*/ diff --git a/include/xo/expression/IfExpr.hpp b/include/xo/expression/IfExpr.hpp index bfe1e116..0f62f86d 100644 --- a/include/xo/expression/IfExpr.hpp +++ b/include/xo/expression/IfExpr.hpp @@ -25,18 +25,18 @@ namespace xo { * @p when_true or @p when_false, depending on result * of evaluating expression @p test **/ - static ref::rp make(const ref::rp & test, - const ref::rp & when_true, - const ref::rp & when_false); + static rp make(const rp & test, + const rp & when_true, + const rp & when_false); /** downcast from Expression **/ static ref::brw from(ref::brw x) { return ref::brw::from(x); } - const ref::rp & test() const { return test_; } - const ref::rp & when_true() const { return when_true_; } - const ref::rp & when_false() const { return when_false_; } + const rp & test() const { return test_; } + const rp & when_true() const { return when_true_; } + const rp & when_false() const { return when_false_; } // ----- Expression ----- @@ -79,7 +79,7 @@ namespace xo { return n; } - virtual ref::rp xform_layer(TransformFn xform_fn) override { + virtual rp xform_layer(TransformFn xform_fn) override { this->test_ = this->test_->xform_layer(xform_fn); this->when_true_ = this->when_true_->xform_layer(xform_fn); this->when_false_= this->when_false_->xform_layer(xform_fn); @@ -113,13 +113,13 @@ namespace xo { * @p when_false else-branch; executes only when test fails **/ IfExpr(TypeDescr ifexpr_type, - const ref::rp & test, - const ref::rp & when_true, - const ref::rp & when_false) + rp test, + rp when_true, + rp when_false) : Expression(exprtype::ifexpr, ifexpr_type), - test_{test}, - when_true_{when_true}, - when_false_{when_false} {} + test_{std::move(test)}, + when_true_{std::move(when_true)}, + when_false_{std::move(when_false)} {} private: /** if: @@ -127,15 +127,15 @@ namespace xo { * * executes x; if true execute y; otherwise execute z **/ - ref::rp test_; - ref::rp when_true_; - ref::rp when_false_; + rp test_; + rp when_true_; + rp when_false_; }; /*IfExpr*/ - inline ref::rp - make_ifexpr(const ref::rp & test, - const ref::rp & when_true, - const ref::rp & when_false) + inline rp + make_ifexpr(const rp & test, + const rp & when_true, + const rp & when_false) { return IfExpr::make(test, when_true, when_false); } diff --git a/include/xo/expression/Lambda.hpp b/include/xo/expression/Lambda.hpp index 40083875..e5d4a84e 100644 --- a/include/xo/expression/Lambda.hpp +++ b/include/xo/expression/Lambda.hpp @@ -27,9 +27,9 @@ namespace xo { * @p argv Formal parameters, in left-to-right order * @p body Expression for body of this function **/ - static ref::rp make(const std::string & name, - const std::vector> & argv, - const ref::rp & body); + static rp make(const std::string & name, + const std::vector> & argv, + const rp & body); /** downcast from Expression **/ static ref::brw from(ref::brw x) { @@ -37,8 +37,8 @@ namespace xo { } const std::string & type_str() const { return type_str_; } - const std::vector> & argv() const { return local_env_->argv(); } - const ref::rp & body() const { return body_; } + const std::vector> & argv() const { return local_env_->argv(); } + const rp & body() const { return body_; } bool needs_closure_flag() const { return !free_var_set_.empty(); } @@ -77,7 +77,7 @@ namespace xo { return n; } - virtual ref::rp xform_layer(TransformFn /*xform_fn*/) override { + virtual rp xform_layer(TransformFn /*xform_fn*/) override { /* a layer is bounded by lambdas, don't enter them */ return this; } @@ -92,8 +92,8 @@ namespace xo { **/ Lambda(const std::string & name, TypeDescr lambda_type, - const ref::rp & local_env, - const ref::rp & body); + const rp & local_env, + const rp & body); /** compute free-variable set for this lambda **/ std::set calc_free_variables() const; @@ -104,7 +104,7 @@ namespace xo { * Goal is to unify variables that can use the same binding * path to determine memory location at runtime. **/ - std::map> regularize_layer_vars(); + std::map> regularize_layer_vars(); private: /** lambda name. Initially supporting only form like @@ -120,7 +120,7 @@ namespace xo { **/ std::string type_str_; /** function body **/ - ref::rp body_; + rp body_; /** free variables for this lambda **/ std::set free_var_set_; @@ -136,7 +136,7 @@ namespace xo { * - any variables appearing in nested lambdas * (whether formals or free variables) **/ - std::map> layer_var_map_; + std::map> layer_var_map_; /** all lambdas nested once inside this lambda's body **/ std::map> nested_lambda_map_; @@ -147,13 +147,13 @@ namespace xo { * when Lambda constructor runs, so we need to assign @ref local_env_ * later. **/ - ref::rp local_env_; + rp local_env_; }; /*Lambda*/ - inline ref::rp + inline rp make_lambda(const std::string & name, - const std::vector> & argv, - const ref::rp & body) + const std::vector> & argv, + const rp & body) { return Lambda::make(name, argv, body); } diff --git a/include/xo/expression/LocalEnv.hpp b/include/xo/expression/LocalEnv.hpp index ec3d4c81..d4facdba 100644 --- a/include/xo/expression/LocalEnv.hpp +++ b/include/xo/expression/LocalEnv.hpp @@ -26,12 +26,12 @@ namespace xo { public: /** named ctor idiom. Create instance with local variables per @p argv **/ - static ref::rp make(const std::vector> & argv) { + static rp make(const std::vector> & argv) { return new LocalEnv(argv); } Lambda * origin() const { return origin_; } - const std::vector> & argv() const { return argv_; } + const std::vector> & argv() const { return argv_; } int n_arg() const { return argv_.size(); } TypeDescr fn_arg(uint32_t i) const { return argv_[i]->valuetype(); } @@ -71,7 +71,7 @@ namespace xo { } private: - LocalEnv(const std::vector> & argv) + LocalEnv(const std::vector> & argv) : origin_{nullptr}, argv_(argv) {} private: @@ -85,12 +85,12 @@ namespace xo { Lambda * origin_ = nullptr; /** formal argument names **/ - std::vector> argv_; + std::vector> argv_; /** parent environment. A free variable in this lambda's * body will be resolved by referring them to @ref parent_env_. **/ - ref::rp parent_env_; + rp parent_env_; }; } /*namespace ast*/ } /*namespace xo*/ diff --git a/include/xo/expression/PrimitiveInterface.hpp b/include/xo/expression/PrimitiveInterface.hpp index 12d4c4a7..c8b0758b 100644 --- a/include/xo/expression/PrimitiveInterface.hpp +++ b/include/xo/expression/PrimitiveInterface.hpp @@ -62,7 +62,7 @@ namespace xo { return 1; } - virtual ref::rp xform_layer(TransformFn xform_fn) override { + virtual rp xform_layer(TransformFn xform_fn) override { return xform_fn(this); } diff --git a/include/xo/expression/Variable.hpp b/include/xo/expression/Variable.hpp index 7d965dea..43936f70 100644 --- a/include/xo/expression/Variable.hpp +++ b/include/xo/expression/Variable.hpp @@ -20,13 +20,13 @@ namespace xo { * identified by @p name, that can take on values * described by @p var_type. **/ - static ref::rp make(const std::string & name, - TypeDescr var_type) { + static rp make(const std::string & name, + TypeDescr var_type) { return new Variable(name, var_type); } /** return copy of x: same var, different object identity **/ - static ref::rp copy(ref::brw x) { + static rp copy(ref::brw x) { return new Variable(x->name(), x->valuetype()); } @@ -53,7 +53,7 @@ namespace xo { return 1; } - virtual ref::rp xform_layer(TransformFn xform_fn) override { + virtual rp xform_layer(TransformFn xform_fn) override { return xform_fn(this); } @@ -76,7 +76,7 @@ namespace xo { binding_path path_; }; /*Variable*/ - inline ref::rp + inline rp make_var(const std::string & name, reflect::TypeDescr var_type) { return Variable::make(name, var_type); diff --git a/src/expression/Apply.cpp b/src/expression/Apply.cpp index 12926ddb..36e2428a 100644 --- a/src/expression/Apply.cpp +++ b/src/expression/Apply.cpp @@ -4,8 +4,6 @@ #include "xo/indentlog/print/vector.hpp" namespace xo { - using xo::ref::rp; - namespace ast { rp Apply::make(const rp & fn, diff --git a/src/expression/IfExpr.cpp b/src/expression/IfExpr.cpp index 31389b60..bd5d231f 100644 --- a/src/expression/IfExpr.cpp +++ b/src/expression/IfExpr.cpp @@ -4,8 +4,6 @@ #include "xo/indentlog/print/vector.hpp" namespace xo { - using xo::ref::rp; - namespace ast { rp IfExpr::make(const rp & test, diff --git a/src/expression/Lambda.cpp b/src/expression/Lambda.cpp index cf9112cd..d18468cd 100644 --- a/src/expression/Lambda.cpp +++ b/src/expression/Lambda.cpp @@ -9,14 +9,13 @@ namespace xo { using xo::reflect::TypeDescrBase; using xo::reflect::FunctionTdxInfo; - using xo::ref::rp; using std::stringstream; namespace ast { rp Lambda::make(const std::string & name, const std::vector> & argv, - const ref::rp & body) + const rp & body) { using xo::reflect::FunctionTdx; @@ -69,7 +68,7 @@ namespace xo { return retval; } /*calc_free_variables*/ - std::map> + std::map> Lambda::regularize_layer_vars() { /* regularize local_env+body: make sure exactly one instance @@ -83,7 +82,7 @@ namespace xo { * Motivation is to unify Variables that would use the same * binding_path to resolve their runtime location. */ - std::map> var_map; + std::map> var_map; for (const auto & arg : local_env_->argv()) { /* each arg name can appear at most once @@ -96,7 +95,7 @@ namespace xo { this->body_ = (body_->xform_layer - ([&var_map](ref::brw x) -> ref::rp + ([&var_map](ref::brw x) -> rp { if (x->extype() == exprtype::variable) { ref::brw var = Variable::from(x);