xo-expression2 xo-procedure2: work on calling primitive for x*y
This commit is contained in:
parent
6c73d08e32
commit
9eda9f7894
11 changed files with 365 additions and 24 deletions
|
|
@ -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
|
||||
|
|
|
|||
12
idl/IExpression_DApplyExpr.json5
Normal file
12
idl/IExpression_DApplyExpr.json5
Normal file
|
|
@ -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" ],
|
||||
}
|
||||
13
idl/IPrintable_DApplyExpr.json5
Normal file
13
idl/IPrintable_DApplyExpr.json5
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
mode: "implementation",
|
||||
includes: [ "<xo/printable2/Printable.hpp>",
|
||||
"<xo/printable2/detail/IPrintable_Xfer.hpp>" ],
|
||||
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" ],
|
||||
}
|
||||
|
|
@ -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<AExpression> fn_expr,
|
||||
size_type n_args);
|
||||
|
||||
/** create apply for function with 2 arguments **/
|
||||
static obj<AExpression,DApplyExpr> make2(obj<AAllocator> mm,
|
||||
TypeRef typeref,
|
||||
obj<AExpression> fn_expr,
|
||||
obj<AExpression> arg1,
|
||||
obj<AExpression> arg2);
|
||||
|
||||
/** create apply for function with 2 arguments **/
|
||||
static DApplyExpr * _make2(obj<AAllocator> mm,
|
||||
TypeRef typeref,
|
||||
obj<AExpression> fn_expr,
|
||||
obj<AExpression> arg1,
|
||||
obj<AExpression> 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<AAllocator> mm,
|
||||
TypeRef typeref,
|
||||
obj<AExpression> fn_expr,
|
||||
size_type n_args);
|
||||
void assign_arg(size_type i_arg, obj<AExpression> expr);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-applyexpr-access-methods **/
|
||||
///@{
|
||||
|
||||
obj<AExpression> 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<AExpression> 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<AExpression> 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<AExpression> args_[];
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
66
include/xo/expression2/detail/IExpression_DApplyExpr.hpp
Normal file
66
include/xo/expression2/detail/IExpression_DApplyExpr.hpp
Normal file
|
|
@ -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<xo::scm::AExpression,
|
||||
xo::scm::DApplyExpr>
|
||||
{
|
||||
using ImplType = xo::scm::IExpression_Xfer
|
||||
<xo::scm::DApplyExpr,
|
||||
xo::scm::IExpression_DApplyExpr>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
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 */
|
||||
62
include/xo/expression2/detail/IPrintable_DApplyExpr.hpp
Normal file
62
include/xo/expression2/detail/IPrintable_DApplyExpr.hpp
Normal file
|
|
@ -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 <xo/printable2/Printable.hpp>
|
||||
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
|
||||
#include "DApplyExpr.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IPrintable_DApplyExpr; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::print::APrintable,
|
||||
xo::scm::DApplyExpr>
|
||||
{
|
||||
using ImplType = xo::print::IPrintable_Xfer
|
||||
<xo::scm::DApplyExpr,
|
||||
xo::scm::IPrintable_DApplyExpr>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
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 */
|
||||
|
|
@ -22,6 +22,9 @@ set(SELF_SRCS
|
|||
IExpression_DDefineExpr.cpp
|
||||
IPrintable_DDefineExpr.cpp
|
||||
|
||||
IExpression_DApplyExpr.cpp
|
||||
IPrintable_DApplyExpr.cpp
|
||||
|
||||
DLocalSymtab.cpp
|
||||
DGlobalSymtab.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<AExpression> fn_expr,
|
||||
size_type n_args) : typeref_{typeref},
|
||||
fn_{fn_expr},
|
||||
n_args_{n_args}
|
||||
{}
|
||||
|
||||
DApplyExpr *
|
||||
DApplyExpr::scaffold(obj<AAllocator> mm,
|
||||
TypeRef typeref,
|
||||
obj<AExpression> fn_expr,
|
||||
size_type n_args)
|
||||
{
|
||||
void * mem = mm.alloc(typeseq::id<DApplyExpr>(),
|
||||
sizeof(DApplyExpr) + (n_args * sizeof(obj<AExpression>)));
|
||||
|
||||
DApplyExpr * result = new (mem) DApplyExpr(typeref,
|
||||
fn_expr,
|
||||
n_args);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
DApplyExpr::assign_arg(size_type i_arg,
|
||||
obj<AExpression> 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<AExpression>
|
||||
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<AGCObject> arg_i = args_->at(i);
|
||||
|
||||
auto expr_i = FacetRegistry::instance().variant<AExpression>(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<APrintable> arg_i
|
||||
= FacetRegistry::instance().variant<APrintable>(this->arg(i_arg));
|
||||
= FacetRegistry::instance().variant<APrintable>(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<APrintable> arg_i
|
||||
= FacetRegistry::instance().variant<APrintable>(fn_);
|
||||
= FacetRegistry::instance().variant<APrintable>(args_[i_arg]);
|
||||
|
||||
pps->newline_indent(ppii.ci1());
|
||||
pps->pretty(refrtag(concat("arg", 1+i_arg), arg_i));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
45
src/expression2/IExpression_DApplyExpr.cpp
Normal file
45
src/expression2/IExpression_DApplyExpr.cpp
Normal file
|
|
@ -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 */
|
||||
28
src/expression2/IPrintable_DApplyExpr.cpp
Normal file
28
src/expression2/IPrintable_DApplyExpr.cpp
Normal file
|
|
@ -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 */
|
||||
|
|
@ -17,6 +17,9 @@
|
|||
#include <xo/expression2/detail/IExpression_DConstant.hpp>
|
||||
#include <xo/expression2/detail/IPrintable_DConstant.hpp>
|
||||
|
||||
#include <xo/expression2/detail/IExpression_DApplyExpr.hpp>
|
||||
#include <xo/expression2/detail/IPrintable_DApplyExpr.hpp>
|
||||
|
||||
#include <xo/gc/detail/AGCObject.hpp>
|
||||
#include <xo/printable2/detail/APrintable.hpp>
|
||||
#include <xo/facet/FacetRegistry.hpp>
|
||||
|
|
@ -40,7 +43,8 @@ namespace xo {
|
|||
// Expression
|
||||
// +- Constant
|
||||
// +- Variable
|
||||
// \- DefineExpr
|
||||
// +- DefineExpr
|
||||
// \- ApplyExpr
|
||||
|
||||
FacetRegistry::register_impl<AExpression, DConstant>();
|
||||
FacetRegistry::register_impl<APrintable, DConstant>();
|
||||
|
|
@ -51,10 +55,14 @@ namespace xo {
|
|||
FacetRegistry::register_impl<AExpression, DDefineExpr>();
|
||||
FacetRegistry::register_impl<APrintable, DDefineExpr>();
|
||||
|
||||
FacetRegistry::register_impl<AExpression, DApplyExpr>();
|
||||
FacetRegistry::register_impl<APrintable, DApplyExpr>();
|
||||
|
||||
log && log(xtag("DUniqueString.tseq", typeseq::id<DUniqueString>()));
|
||||
log && log(xtag("DDefineExpr.tseq", typeseq::id<DDefineExpr>()));
|
||||
log && log(xtag("DVariable.tseq", typeseq::id<DVariable>()));
|
||||
log && log(xtag("DConstant.tseq", typeseq::id<DConstant>()));
|
||||
log && log(xtag("DApplyExpr.tseq", typeseq::id<DApplyExpr>()));
|
||||
|
||||
log && log(xtag("AExpression.tqseq", typeseq::id<AExpression>()));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue