diff --git a/CMakeLists.txt b/CMakeLists.txt index 52e9d380..869f891d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,6 +124,32 @@ xo_add_genfacetimpl( # ---------------------------------------------------------------- +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-expression2-facetimpl-expression-applyexpr + FACET_PKG xo_expression2 + FACET Expression + REPR ApplyExpr + INPUT idl/IExpression_DApplyExpr.json5 + OUTPUT_HPP_DIR include/xo/expression2 + OUTPUT_IMPL_SUBDIR detail + OUTPUT_CPP_DIR src/expression2 +) + +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-expression2-facetimpl-printable-applyexpr + FACET_PKG xo_printable2 + FACET Printable + REPR ApplyExpr + INPUT idl/IPrintable_DApplyExpr.json5 + OUTPUT_HPP_DIR include/xo/expression2 + OUTPUT_IMPL_SUBDIR detail + OUTPUT_CPP_DIR src/expression2 +) + +# ---------------------------------------------------------------- + # note: manual target; generated code committed to git xo_add_genfacetimpl( TARGET xo-expression2-facetimpl-gcobject-uniquestring diff --git a/idl/IExpression_DApplyExpr.json5 b/idl/IExpression_DApplyExpr.json5 new file mode 100644 index 00000000..6814547c --- /dev/null +++ b/idl/IExpression_DApplyExpr.json5 @@ -0,0 +1,12 @@ +{ + mode: "implementation", + includes: [ "\"Expression.hpp\"" ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/Expression.json5", + brief: "provide AExpression interface for DApplyExpr state", + using_doxygen: true, + repr: "DApplyExpr", + doc: ["doc for IExpression+DApplyExpr" ], +} diff --git a/idl/IPrintable_DApplyExpr.json5 b/idl/IPrintable_DApplyExpr.json5 new file mode 100644 index 00000000..fe743b0b --- /dev/null +++ b/idl/IPrintable_DApplyExpr.json5 @@ -0,0 +1,13 @@ +{ + mode: "implementation", + includes: [ "", + "" ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/Printable.json5", + brief: "provide APrintable interface for DApplyExpr", + using_doxygen: true, + repr: "DApplyExpr", + doc: [ "implement APrintable for DApplyExpr" ], +} diff --git a/include/xo/expression2/DApplyExpr.hpp b/include/xo/expression2/DApplyExpr.hpp index 882cf5cd..8502c62a 100644 --- a/include/xo/expression2/DApplyExpr.hpp +++ b/include/xo/expression2/DApplyExpr.hpp @@ -20,18 +20,55 @@ namespace xo { **/ class DApplyExpr { public: + using AAllocator = xo::mm::AAllocator; using TypeDescr = xo::reflect::TypeDescr; using ppindentinfo = xo::print::ppindentinfo; - using size_type = std::size_t; + using size_type = std::uint32_t; public: + /** @defgroup scm-applyexpr-constructors **/ + ///@{ + + /** construct empty instance, but with argument expressions empty **/ + DApplyExpr(TypeRef typeref, + obj fn_expr, + size_type n_args); + + /** create apply for function with 2 arguments **/ + static obj make2(obj mm, + TypeRef typeref, + obj fn_expr, + obj arg1, + obj arg2); + + /** create apply for function with 2 arguments **/ + static DApplyExpr * _make2(obj mm, + TypeRef typeref, + obj fn_expr, + obj arg1, + obj arg2); + + /** scaffold incomplete instance. + * apply-expr using memory from @p mm. + * will construct instance with space for @p n_args arguments + * but expressions left empty. + * use @ref assign_arg for all arguments to complete. + **/ + static DApplyExpr * scaffold(obj mm, + TypeRef typeref, + obj fn_expr, + size_type n_args); + void assign_arg(size_type i_arg, obj expr); + + ///@} + /** @defgroup scm-applyexpr-access-methods **/ + ///@{ obj fn() const noexcept { return fn_; } - const DArray * args() const noexcept { return args_; } - - size_type n_arg() const noexcept { return args_->size(); } + size_type n_args() const noexcept { return n_args_; } obj arg(size_type i) const; + ///@} /** @defgroup scm-applyexpr-expression-facet **/ ///@{ @@ -40,6 +77,12 @@ namespace xo { TypeDescr valuetype() const noexcept { return typeref_.td(); } void assign_valuetype(TypeDescr td) noexcept; + ///@} + /** @defgroup scm-applyexpr-gcobject-facet **/ + ///@{ + + // shallow_copy() etc. + ///@} /** @defgroup scm-applyexpr-printable-facet **/ ///@{ @@ -55,8 +98,10 @@ namespace xo { TypeRef typeref_; /** expression for function/procedure to invoke **/ obj fn_; - /** expression for each argument vector **/ - const DArray * args_; + /** number of arguments (not counting @ref fn_ **/ + size_type n_args_ = 0; + /** args_[i] is expression for i'th argument to @ref fn_ **/ + obj args_[]; }; } } diff --git a/include/xo/expression2/detail/IExpression_DApplyExpr.hpp b/include/xo/expression2/detail/IExpression_DApplyExpr.hpp new file mode 100644 index 00000000..c8952199 --- /dev/null +++ b/include/xo/expression2/detail/IExpression_DApplyExpr.hpp @@ -0,0 +1,66 @@ +/** @file IExpression_DApplyExpr.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IExpression_DApplyExpr.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IExpression_DApplyExpr.json5] + **/ + +#pragma once + +#include "Expression.hpp" +#include "Expression.hpp" +#include "DApplyExpr.hpp" + +namespace xo { namespace scm { class IExpression_DApplyExpr; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::scm::IExpression_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IExpression_DApplyExpr + **/ + class IExpression_DApplyExpr { + public: + /** @defgroup scm-expression-dapplyexpr-type-traits **/ + ///@{ + using TypeDescr = xo::scm::AExpression::TypeDescr; + using Copaque = xo::scm::AExpression::Copaque; + using Opaque = xo::scm::AExpression::Opaque; + ///@} + /** @defgroup scm-expression-dapplyexpr-methods **/ + ///@{ + // const methods + /** expression type (constant | apply | ..) **/ + static exprtype extype(const DApplyExpr & self) noexcept; + /** placeholder for type giving possible values for this expression **/ + static TypeRef typeref(const DApplyExpr & self) noexcept; + /** type giving possible values for this expression. Maybe null before typecheck **/ + static TypeDescr valuetype(const DApplyExpr & self) noexcept; + + // non-const methods + /** assing to valuetype member. Useful when scaffolding expressions **/ + static void assign_valuetype(DApplyExpr & self, TypeDescr td) noexcept; + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/include/xo/expression2/detail/IPrintable_DApplyExpr.hpp b/include/xo/expression2/detail/IPrintable_DApplyExpr.hpp new file mode 100644 index 00000000..c05e87e2 --- /dev/null +++ b/include/xo/expression2/detail/IPrintable_DApplyExpr.hpp @@ -0,0 +1,62 @@ +/** @file IPrintable_DApplyExpr.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DApplyExpr.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DApplyExpr.json5] + **/ + +#pragma once + +#include "Printable.hpp" +#include +#include +#include "DApplyExpr.hpp" + +namespace xo { namespace scm { class IPrintable_DApplyExpr; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::print::IPrintable_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IPrintable_DApplyExpr + **/ + class IPrintable_DApplyExpr { + public: + /** @defgroup scm-printable-dapplyexpr-type-traits **/ + ///@{ + using ppindentinfo = xo::print::APrintable::ppindentinfo; + using Copaque = xo::print::APrintable::Copaque; + using Opaque = xo::print::APrintable::Opaque; + ///@} + /** @defgroup scm-printable-dapplyexpr-methods **/ + ///@{ + // const methods + /** Pretty-printing support for this object. +See [xo-indentlog/xo/indentlog/pretty.hpp] **/ + static bool pretty(const DApplyExpr & self, const ppindentinfo & ppii); + + // non-const methods + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/src/expression2/CMakeLists.txt b/src/expression2/CMakeLists.txt index 9dea6457..b8be9468 100644 --- a/src/expression2/CMakeLists.txt +++ b/src/expression2/CMakeLists.txt @@ -22,6 +22,9 @@ set(SELF_SRCS IExpression_DDefineExpr.cpp IPrintable_DDefineExpr.cpp + IExpression_DApplyExpr.cpp + IPrintable_DApplyExpr.cpp + DLocalSymtab.cpp DGlobalSymtab.cpp diff --git a/src/expression2/DApplyExpr.cpp b/src/expression2/DApplyExpr.cpp index 0c0546f3..ce5e1951 100644 --- a/src/expression2/DApplyExpr.cpp +++ b/src/expression2/DApplyExpr.cpp @@ -11,30 +11,62 @@ namespace xo { using xo::print::APrintable; using xo::facet::FacetRegistry; + using xo::reflect::typeseq; using xo::mm::AGCObject; namespace scm { + /* incomplete! */ + DApplyExpr::DApplyExpr(TypeRef typeref, + obj fn_expr, + size_type n_args) : typeref_{typeref}, + fn_{fn_expr}, + n_args_{n_args} + {} + + DApplyExpr * + DApplyExpr::scaffold(obj mm, + TypeRef typeref, + obj fn_expr, + size_type n_args) + { + void * mem = mm.alloc(typeseq::id(), + sizeof(DApplyExpr) + (n_args * sizeof(obj))); + + DApplyExpr * result = new (mem) DApplyExpr(typeref, + fn_expr, + n_args); + + return result; + } + + void + DApplyExpr::assign_arg(size_type i_arg, + obj expr) + { + if (i_arg < n_args_) { + this->args_[i_arg] = expr; + } else { + assert(false); + + throw std::runtime_error(tostr("assign out-of-range argument i_arg where [0..n_args) expected", + xtag("i_arg", i_arg), + xtag("expr", expr), + xtag("n_args", n_args_))); + + } + } + obj DApplyExpr::arg(size_type i) const { - if (i >= args_->size()) [[unlikely]] { + if (i >= n_args_) [[unlikely]] { throw std::runtime_error(tostr("attempt to fetch argument i where [0..n) expected", xtag("i", i), - xtag("n", args_->size()), + xtag("n", n_args_), xtag("src", "DApplyExpr::arg"))); } - obj arg_i = args_->at(i); - - auto expr_i = FacetRegistry::instance().variant(arg_i); - - if (!expr_i) [[unlikely]] { - throw std::runtime_error(tostr("expected expression interface on argument i", - xtag("i", i), - xtag("arg[i]", arg_i))); - } - - return expr_i; + return args_[i]; } void @@ -60,9 +92,9 @@ namespace xo { return false; } - for (size_t i_arg = 0, n_arg = this->n_arg(); i_arg < n_arg; ++i_arg) { + for (size_t i_arg = 0; i_arg < n_args_; ++i_arg) { obj arg_i - = FacetRegistry::instance().variant(this->arg(i_arg)); + = FacetRegistry::instance().variant(args_[i_arg]); if (!pps->print_upto(refrtag(concat("arg", 1+i_arg), arg_i))) return false; @@ -78,13 +110,14 @@ namespace xo { pps->newline_indent(ppii.ci1()); pps->pretty(refrtag("fn", fn)); - for (size_t i_arg = 0, n_arg = this->n_arg(); i_arg < n_arg; ++i_arg) { + for (size_t i_arg = 0; i_arg < n_args_; ++i_arg) { obj arg_i - = FacetRegistry::instance().variant(fn_); + = FacetRegistry::instance().variant(args_[i_arg]); pps->newline_indent(ppii.ci1()); pps->pretty(refrtag(concat("arg", 1+i_arg), arg_i)); } + return false; } } diff --git a/src/expression2/IExpression_DApplyExpr.cpp b/src/expression2/IExpression_DApplyExpr.cpp new file mode 100644 index 00000000..2098e050 --- /dev/null +++ b/src/expression2/IExpression_DApplyExpr.cpp @@ -0,0 +1,45 @@ +/** @file IExpression_DApplyExpr.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IExpression_DApplyExpr.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IExpression_DApplyExpr.json5] +**/ + +#include "detail/IExpression_DApplyExpr.hpp" + +namespace xo { + namespace scm { + auto + IExpression_DApplyExpr::extype(const DApplyExpr & self) noexcept -> exprtype + { + return self.extype(); + } + + auto + IExpression_DApplyExpr::typeref(const DApplyExpr & self) noexcept -> TypeRef + { + return self.typeref(); + } + + auto + IExpression_DApplyExpr::valuetype(const DApplyExpr & self) noexcept -> TypeDescr + { + return self.valuetype(); + } + + auto + IExpression_DApplyExpr::assign_valuetype(DApplyExpr & self, TypeDescr td) noexcept -> void + { + self.assign_valuetype(td); + } + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IExpression_DApplyExpr.cpp */ \ No newline at end of file diff --git a/src/expression2/IPrintable_DApplyExpr.cpp b/src/expression2/IPrintable_DApplyExpr.cpp new file mode 100644 index 00000000..4f4a50d3 --- /dev/null +++ b/src/expression2/IPrintable_DApplyExpr.cpp @@ -0,0 +1,28 @@ +/** @file IPrintable_DApplyExpr.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DApplyExpr.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DApplyExpr.json5] +**/ + +#include "detail/IPrintable_DApplyExpr.hpp" + +namespace xo { + namespace scm { + auto + IPrintable_DApplyExpr::pretty(const DApplyExpr & self, const ppindentinfo & ppii) -> bool + { + return self.pretty(ppii); + } + + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IPrintable_DApplyExpr.cpp */ \ No newline at end of file diff --git a/src/expression2/expression2_register_facets.cpp b/src/expression2/expression2_register_facets.cpp index 1854f3eb..fc6ef3c1 100644 --- a/src/expression2/expression2_register_facets.cpp +++ b/src/expression2/expression2_register_facets.cpp @@ -17,6 +17,9 @@ #include #include +#include +#include + #include #include #include @@ -40,7 +43,8 @@ namespace xo { // Expression // +- Constant // +- Variable - // \- DefineExpr + // +- DefineExpr + // \- ApplyExpr FacetRegistry::register_impl(); FacetRegistry::register_impl(); @@ -51,10 +55,14 @@ namespace xo { FacetRegistry::register_impl(); FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + log && log(xtag("DUniqueString.tseq", typeseq::id())); log && log(xtag("DDefineExpr.tseq", typeseq::id())); log && log(xtag("DVariable.tseq", typeseq::id())); log && log(xtag("DConstant.tseq", typeseq::id())); + log && log(xtag("DApplyExpr.tseq", typeseq::id())); log && log(xtag("AExpression.tqseq", typeseq::id()));