xo-expression2 xo-procedure2: work on calling primitive for x*y
This commit is contained in:
parent
43a6235439
commit
bb8a140647
30 changed files with 603 additions and 221 deletions
|
|
@ -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
xo-expression2/src/expression2/IExpression_DApplyExpr.cpp
Normal file
45
xo-expression2/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
xo-expression2/src/expression2/IPrintable_DApplyExpr.cpp
Normal file
28
xo-expression2/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