xo-expression2 xo-gc: DSequenceExpr builds [WIP]
This commit is contained in:
parent
315c066734
commit
92e79852b9
60 changed files with 651 additions and 62 deletions
|
|
@ -238,6 +238,20 @@ xo_add_genfacetimpl(
|
|||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-expression2-facetimpl-expression-sequenceexpr
|
||||
FACET_PKG xo_expression2
|
||||
FACET Expression
|
||||
REPR SequenceExpr
|
||||
INPUT idl/IExpression_DSequenceExpr.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
xo-expression2/idl/IExpression_DSequenceExpr.json5
Normal file
12
xo-expression2/idl/IExpression_DSequenceExpr.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 DSequenceExpr state",
|
||||
using_doxygen: true,
|
||||
repr: "DSequenceExpr",
|
||||
doc: ["doc for something or other IExpression+DSequenceExpr" ],
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "Expression.hpp"
|
||||
#include "TypeRef.hpp"
|
||||
#include <xo/object2/DArray.hpp>
|
||||
|
||||
|
|
@ -21,6 +22,8 @@ namespace xo {
|
|||
**/
|
||||
class DSequenceExpr {
|
||||
public:
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using TypeDescr = xo::reflect::TypeDescr;
|
||||
using size_type = DArray::size_type;
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
|
||||
|
|
@ -37,8 +40,11 @@ namespace xo {
|
|||
size_type size() const noexcept;
|
||||
obj<AExpression> operator[](std::size_t i) const;
|
||||
|
||||
/** append @p expr to the end of this sequence **/
|
||||
void push_back(obj<AExpression> expr);
|
||||
/** append @p expr to the end of this sequence;
|
||||
* use memory from @p mm if need to expand storage
|
||||
**/
|
||||
void push_back(obj<AAllocator> mm,
|
||||
obj<AExpression> expr);
|
||||
|
||||
// get_free_variables();
|
||||
// visit_preorder();
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/Expression.json5]
|
||||
* 2. jinja2 template for facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/SymbolTable.json5]
|
||||
* 2. jinja2 template for facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/Expression.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/Expression.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IExpression_DApplyExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IExpression_DConstant.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IExpression_DDefineExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IExpression_DIfElseExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IExpression_DLambdaExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
/** @file IExpression_DSequenceExpr.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IExpression_DSequenceExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IExpression_DSequenceExpr.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Expression.hpp"
|
||||
#include "Expression.hpp"
|
||||
#include "DSequenceExpr.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IExpression_DSequenceExpr; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::scm::AExpression,
|
||||
xo::scm::DSequenceExpr>
|
||||
{
|
||||
using ImplType = xo::scm::IExpression_Xfer
|
||||
<xo::scm::DSequenceExpr,
|
||||
xo::scm::IExpression_DSequenceExpr>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IExpression_DSequenceExpr
|
||||
**/
|
||||
class IExpression_DSequenceExpr {
|
||||
public:
|
||||
/** @defgroup scm-expression-dsequenceexpr-type-traits **/
|
||||
///@{
|
||||
using TypeDescr = xo::scm::AExpression::TypeDescr;
|
||||
using Copaque = xo::scm::AExpression::Copaque;
|
||||
using Opaque = xo::scm::AExpression::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-expression-dsequenceexpr-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** expression type (constant | apply | ..) **/
|
||||
static exprtype extype(const DSequenceExpr & self) noexcept;
|
||||
/** placeholder for type giving possible values for this expression **/
|
||||
static TypeRef typeref(const DSequenceExpr & self) noexcept;
|
||||
/** type giving possible values for this expression. Maybe null before typecheck **/
|
||||
static TypeDescr valuetype(const DSequenceExpr & self) noexcept;
|
||||
|
||||
// non-const methods
|
||||
/** assing to valuetype member. Useful when scaffolding expressions **/
|
||||
static void assign_valuetype(DSequenceExpr & self, TypeDescr td) noexcept;
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IExpression_DVariable.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/Expression.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IGCObject_DUniqueString.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IGCObject_DVariable.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DApplyExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DConstant.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DDefineExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DIfElseExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DLambdaExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DUniqueString.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DVariable.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/Expression.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/SymbolTable.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DLocalSymtab.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/SymbolTable.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/ISymbolTable_DLocalSymtab.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/SymbolTable.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/SymbolTable.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ set(SELF_SRCS
|
|||
DLambdaExpr.cpp
|
||||
DApplyExpr.cpp
|
||||
DIfElseExpr.cpp
|
||||
DSequenceExpr.cpp
|
||||
|
||||
TypeRef.cpp
|
||||
|
||||
|
|
@ -34,6 +35,8 @@ set(SELF_SRCS
|
|||
IExpression_DIfElseExpr.cpp
|
||||
IPrintable_DIfElseExpr.cpp
|
||||
|
||||
IExpression_DSequenceExpr.cpp
|
||||
|
||||
DLocalSymtab.cpp
|
||||
DGlobalSymtab.cpp
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,19 @@
|
|||
**/
|
||||
|
||||
#include "DSequenceExpr.hpp"
|
||||
#include "detail/IExpression_DSequenceExpr.hpp"
|
||||
#include <xo/gc/GCObject.hpp>
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/facet/FacetRegistry.hpp>
|
||||
#include <xo/facet/obj.hpp>
|
||||
#include <xo/reflectutil/typeseq.hpp>
|
||||
|
||||
namespace xo {
|
||||
using xo::mm::AGCObject;
|
||||
using xo::facet::FacetRegistry;
|
||||
using xo::reflect::typeseq;
|
||||
|
||||
namespace scm {
|
||||
|
||||
obj<AExpression,DSequenceExpr>
|
||||
|
|
@ -35,8 +46,8 @@ namespace xo {
|
|||
return expr;
|
||||
}
|
||||
|
||||
size_type
|
||||
DSequenceExpr::size() const noexcept
|
||||
auto
|
||||
DSequenceExpr::size() const noexcept -> size_type
|
||||
{
|
||||
return expr_v_->size();
|
||||
}
|
||||
|
|
@ -44,7 +55,9 @@ namespace xo {
|
|||
obj<AExpression>
|
||||
DSequenceExpr::operator[](std::size_t i) const
|
||||
{
|
||||
return (*expr_v_)[i];
|
||||
obj<AGCObject> gco = (*expr_v_)[i];
|
||||
|
||||
return FacetRegistry::instance().variant<AExpression,AGCObject>(gco);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -64,7 +77,10 @@ namespace xo {
|
|||
this->expr_v_ = expr_2x_v;
|
||||
}
|
||||
|
||||
this->expr_v_->push_back(expr);
|
||||
obj<AGCObject> expr_gco
|
||||
= FacetRegistry::instance().variant<AGCObject,AExpression>(expr);
|
||||
|
||||
this->expr_v_->push_back(expr_gco);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -73,15 +89,16 @@ namespace xo {
|
|||
typeref_.resolve(td);
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
DSequenceExpr::pretty(const ppindentinfo & ppii) const
|
||||
{
|
||||
using xo::print::ppstate;
|
||||
|
||||
ppstate * pps = ppii.pps();
|
||||
|
||||
xxx;
|
||||
return ppii.pps()->pretty_struct
|
||||
(ppii,
|
||||
"DSequenceExpr");
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IExpression_DApplyExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IExpression_DConstant.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IExpression_DDefineExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IExpression_DIfElseExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IExpression_DLambdaExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
45
xo-expression2/src/expression2/IExpression_DSequenceExpr.cpp
Normal file
45
xo-expression2/src/expression2/IExpression_DSequenceExpr.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/** @file IExpression_DSequenceExpr.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IExpression_DSequenceExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IExpression_DSequenceExpr.json5]
|
||||
**/
|
||||
|
||||
#include "detail/IExpression_DSequenceExpr.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IExpression_DSequenceExpr::extype(const DSequenceExpr & self) noexcept -> exprtype
|
||||
{
|
||||
return self.extype();
|
||||
}
|
||||
|
||||
auto
|
||||
IExpression_DSequenceExpr::typeref(const DSequenceExpr & self) noexcept -> TypeRef
|
||||
{
|
||||
return self.typeref();
|
||||
}
|
||||
|
||||
auto
|
||||
IExpression_DSequenceExpr::valuetype(const DSequenceExpr & self) noexcept -> TypeDescr
|
||||
{
|
||||
return self.valuetype();
|
||||
}
|
||||
|
||||
auto
|
||||
IExpression_DSequenceExpr::assign_valuetype(DSequenceExpr & self, TypeDescr td) noexcept -> void
|
||||
{
|
||||
self.assign_valuetype(td);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IExpression_DSequenceExpr.cpp */
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IExpression_DVariable.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IGCObject_DUniqueString.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IGCObject_DVariable.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DApplyExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DConstant.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DDefineExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DIfElseExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DLambdaExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DLocalSymtab.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DUniqueString.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DVariable.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/ISymbolTable_DLocalSymtab.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -30,6 +30,10 @@ xo_add_genfacet(
|
|||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
xo_add_genfacet_all(xo-gc-genfacet-all)
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# must complete definition of expression lib before configuring examples
|
||||
add_subdirectory(src/gc)
|
||||
add_subdirectory(utest)
|
||||
|
|
|
|||
|
|
@ -6,11 +6,13 @@
|
|||
"<cstdint>",
|
||||
"<cstddef>",
|
||||
],
|
||||
// extra includes in GCObject.hpp, if any
|
||||
user_hpp_includes: [],
|
||||
namespace1: "xo",
|
||||
namespace2: "mm",
|
||||
pretext: [
|
||||
"namespace xo { namespace mm { struct ACollector; }}",
|
||||
],
|
||||
namespace1: "xo",
|
||||
namespace2: "mm",
|
||||
facet: "GCObject",
|
||||
detail_subdir: "detail",
|
||||
brief: "xxx",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/GCObject.json5]
|
||||
* 2. jinja2 template for facet .hpp file:
|
||||
|
|
@ -18,4 +18,5 @@
|
|||
#include "detail/IGCObject_Xfer.hpp"
|
||||
#include "detail/RGCObject.hpp"
|
||||
|
||||
|
||||
/* end GCObject.hpp */
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/GCObject.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/GCObject.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/GCObject.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/GCObject.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
@ -40,6 +40,9 @@ public:
|
|||
///@{
|
||||
RGCObject() {}
|
||||
RGCObject(Object::DataPtr data) : Object{std::move(data)} {}
|
||||
RGCObject(const AGCObject * iface, void * data)
|
||||
requires std::is_same_v<typename Object::DataType, xo::facet::DVariantPlaceholder>
|
||||
: Object(iface, data) {}
|
||||
|
||||
///@}
|
||||
/** @defgroup mm-gcobject-router-methods **/
|
||||
|
|
@ -54,7 +57,7 @@ public:
|
|||
return O::iface()->shallow_copy(O::data(), mm);
|
||||
}
|
||||
|
||||
// non-const methods
|
||||
// non-const methods (still const in router!)
|
||||
size_type forward_children(obj<ACollector> gc) noexcept {
|
||||
return O::iface()->forward_children(O::data(), gc);
|
||||
}
|
||||
|
|
|
|||
158
xo-object2/include/xo/object2/GCObjectConverter.hpp
Normal file
158
xo-object2/include/xo/object2/GCObjectConverter.hpp
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
/** @file GCObjectConverter.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Nov 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <xo/gc/GCObject.hpp>
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include <xo/reflect/Reflect.hpp>
|
||||
//#include "xo/reflect/TaggedPtr.hpp"
|
||||
#include <xo/reflect/TypeDrivenMap.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/* Convert between xo::reflect::TaggedPtr and xo::Object for
|
||||
* a particular wrapped c++ type
|
||||
*/
|
||||
struct Converter {
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using AGCObject = xo::mm::AGCObject;
|
||||
using TaggedPtr = xo::reflect::TaggedPtr;
|
||||
/** convert from some reflected T* @p src to
|
||||
* obj<AGCObject> dest
|
||||
* using memory from allocator @p mm
|
||||
**/
|
||||
using ConvertToObjectFn = obj<AGCObject> (*)(obj<AAllocator> mm,
|
||||
TaggedPtr src);
|
||||
/** convert from obj<AGCObject> @p src to some refected T* @p dest
|
||||
* using memory from allocator @p mm.
|
||||
*
|
||||
* NOTE: obj<AGCObject> is gc-aware -> will likely reside in
|
||||
* a collected memory region.
|
||||
**/
|
||||
using ConvertFromObjectFn = TaggedPtr (*)(obj<AAllocator> mm,
|
||||
obj<AGCObject> obj);
|
||||
|
||||
public:
|
||||
Converter() = default;
|
||||
explicit Converter(ConvertToObjectFn to,
|
||||
ConvertFromObjectFn from)
|
||||
: cvt_to_object_{to},
|
||||
cvt_from_object_{from}
|
||||
{}
|
||||
|
||||
/** convert tagged pointer @p tp to new object,
|
||||
* allocated via @p mm.
|
||||
*
|
||||
* Conversion will typically be for some specific type;
|
||||
* see @ref ObjectConverter
|
||||
**/
|
||||
ConvertToObjectFn cvt_to_object_ = nullptr;
|
||||
|
||||
/** convert object to tagged pointer @p,
|
||||
* allocated via @p mm.
|
||||
*
|
||||
* Conversion will typically be for some specific type;
|
||||
* see @ref ObjectConverter
|
||||
**/
|
||||
ConvertFromObjectFn cvt_from_object_ = nullptr;
|
||||
};
|
||||
|
||||
/** @class ObjectConverter
|
||||
* @brief Conversion to/from Object
|
||||
*
|
||||
* For some instance of type T:
|
||||
*
|
||||
* @code
|
||||
* ObjectConverter & converters = ...;
|
||||
* T x = ...;
|
||||
* TaggedPtr tp = Reflect::make_tp(&x);
|
||||
* TypeId tid = tp.td()->id();
|
||||
*
|
||||
* const Converter * cvt = converters.cvt_.lookup(tid);
|
||||
*
|
||||
* if (cvt) {
|
||||
* // cvt is a converter for T instances
|
||||
* gp<Object> obj = (*(cvt->cvt_to_object_))(mm,
|
||||
* @endcode
|
||||
**/
|
||||
class ObjectConverter {
|
||||
public:
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using AGCObject = xo::mm::AGCObject;
|
||||
using Reflect = xo::reflect::Reflect;
|
||||
using TaggedPtr = xo::reflect::TaggedPtr;
|
||||
using TypeId = xo::reflect::TypeId;
|
||||
|
||||
/** sets up standard conversions **/
|
||||
ObjectConverter();
|
||||
|
||||
/** singleton instance **/
|
||||
static const ObjectConverter & instance();
|
||||
|
||||
/** establish conversion: use @p fn to convert values of type @tparam T. **/
|
||||
template <typename T>
|
||||
void establish_conversion(Converter::ConvertToObjectFn to,
|
||||
Converter::ConvertFromObjectFn from);
|
||||
|
||||
/** convert tagged poitner @p tp to object. allocates memory only from @p mm.
|
||||
* return nullptr if no converter available and @p throw_flag not set.
|
||||
* throw exception if no converter available and @p throw_flag set.
|
||||
**/
|
||||
obj<AGCObject> tp_to_gco(obj<AAllocator> mm,
|
||||
TaggedPtr tp,
|
||||
bool throw_flag) const;
|
||||
|
||||
/** convert @p x to object.
|
||||
* return converted object; if allocated, using only memory from @p mm.
|
||||
* return nullptr if no converter available, and @p throw_flag not set.
|
||||
* throw exception if no converter available, and @p throw_flag set.
|
||||
**/
|
||||
template <typename T>
|
||||
obj<AGCObject> to_gco(obj<AAllocator> mm, const T & x, bool throw_flag);
|
||||
|
||||
/** convert object @p obj to tagged pointer, with typeid @p target_id.
|
||||
* Allocates memory only from @p mm.
|
||||
* return null TaggedPtr if no converter available and @p throw_flag not set.
|
||||
* Throw exception if no converter available and @p throw_flag set.
|
||||
**/
|
||||
TaggedPtr tp_from_gco(obj<AAllocator> mm,
|
||||
obj<AGCObject> obj,
|
||||
TypeId target_type_id,
|
||||
bool throw_flag) const;
|
||||
|
||||
private:
|
||||
/** expandable type-driven conversion table.
|
||||
**/
|
||||
xo::reflect::TypeDrivenMap<Converter> cvt_;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void
|
||||
ObjectConverter::establish_conversion(Converter::ConvertToObjectFn to,
|
||||
Converter::ConvertFromObjectFn from)
|
||||
{
|
||||
using xo::reflect::TypeDescrW;
|
||||
using xo::reflect::Reflect;
|
||||
|
||||
TypeDescrW td = Reflect::require<T>();
|
||||
Converter * cvt = cvt_.require(td);
|
||||
|
||||
*cvt = Converter(to, from);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto
|
||||
ObjectConverter::to_gco(obj<AAllocator> mm, const T & x, bool throw_flag)
|
||||
-> obj<AGCObject>
|
||||
{
|
||||
TaggedPtr x_tp = Reflect::make_tp(&x);
|
||||
|
||||
return tp_to_gco(mm, x_tp, throw_flag);
|
||||
}
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end GCObjectConverter.hpp */
|
||||
258
xo-object2/src/object2/GCObjectConverter.cpp
Normal file
258
xo-object2/src/object2/GCObjectConverter.cpp
Normal file
|
|
@ -0,0 +1,258 @@
|
|||
/** @file GCObjectConverter.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Nov 2025
|
||||
**/
|
||||
|
||||
#include "GCObjectConverter.hpp"
|
||||
|
||||
#include "DInteger.hpp"
|
||||
#include "number/IGCObject_DInteger.hpp"
|
||||
|
||||
#include "DFloat.hpp"
|
||||
#include "number/IGCObject_DFloat.hpp"
|
||||
|
||||
#include "DBoolean.hpp"
|
||||
#include "boolean/IGCObject_DBoolean.hpp"
|
||||
|
||||
#include "DString.hpp"
|
||||
#include "string/IGCObject_DString.hpp"
|
||||
|
||||
#include <xo/facet/obj.hpp>
|
||||
#include <xo/reflect/TaggedPtr.hpp>
|
||||
//#include "xo/alloc/Blob.hpp"
|
||||
|
||||
namespace xo {
|
||||
using xo::mm::AGCObject;
|
||||
using xo::reflect::Reflect;
|
||||
using xo::reflect::TaggedPtr;
|
||||
using xo::reflect::TypeId;
|
||||
using xo::facet::obj;
|
||||
using xo::facet::typeseq;
|
||||
using xo::mm::AAllocator;
|
||||
|
||||
namespace scm {
|
||||
namespace {
|
||||
// DInteger <-> T
|
||||
|
||||
template <typename T>
|
||||
obj<AGCObject>
|
||||
int_to_gco(obj<AAllocator> mm, TaggedPtr src)
|
||||
{
|
||||
T * native = src.recover_native<T>();
|
||||
|
||||
assert(native);
|
||||
|
||||
return DInteger::box<AGCObject>(mm, *native);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
TaggedPtr
|
||||
gco_to_int(obj<AAllocator> mm,
|
||||
obj<AGCObject> obj)
|
||||
{
|
||||
|
||||
/* mm cannot be GC allocator!
|
||||
* That's Object-only
|
||||
*/
|
||||
|
||||
auto int_obj = xo::facet::obj<AGCObject,DInteger>::from(obj); //Integer::from(obj);
|
||||
|
||||
if (!int_obj) {
|
||||
throw std::runtime_error
|
||||
(tostr("Object obj found where Integer expected",
|
||||
xtag("obj", obj)));
|
||||
}
|
||||
|
||||
void * mem = mm.alloc(typeseq::id<T>(), sizeof(T));
|
||||
|
||||
T * p = reinterpret_cast<T *>(mem);
|
||||
|
||||
*p = int_obj.data()->value();
|
||||
|
||||
/* Note:
|
||||
* retval invalidated when
|
||||
* *mm cleared/recycled/collected
|
||||
*/
|
||||
|
||||
return Reflect::make_tp(p);
|
||||
}
|
||||
|
||||
// DFloat <-> T
|
||||
|
||||
template <typename T>
|
||||
xo::facet::obj<xo::mm::AGCObject>
|
||||
float_to_gco(xo::facet::obj<AAllocator> mm,
|
||||
TaggedPtr src)
|
||||
{
|
||||
T * native = src.recover_native<T>();
|
||||
|
||||
assert(native);
|
||||
|
||||
return DFloat::box<AGCObject>(mm, *native);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
TaggedPtr
|
||||
gco_to_float(obj<AAllocator> mm, obj<AGCObject> obj)
|
||||
{
|
||||
auto float_obj = xo::facet::obj<AGCObject,DFloat>::from(obj);
|
||||
|
||||
if (!float_obj) {
|
||||
throw std::runtime_error
|
||||
(tostr("Object obj found where Float expected",
|
||||
xtag("obj", obj)));
|
||||
}
|
||||
|
||||
void * mem = mm.alloc(typeseq::id<T>(), sizeof(T));
|
||||
|
||||
T * p = reinterpret_cast<T *>(mem);
|
||||
|
||||
*p = float_obj.data()->value();
|
||||
|
||||
/* Note:
|
||||
* retval invalidated when *mm cleared/recycled/collected
|
||||
*/
|
||||
|
||||
return Reflect::make_tp(p);
|
||||
}
|
||||
|
||||
// DBoolean <-> T
|
||||
|
||||
obj<AGCObject>
|
||||
bool_to_gco(obj<AAllocator> mm, TaggedPtr src)
|
||||
{
|
||||
bool * native = src.recover_native<bool>();
|
||||
|
||||
assert(native);
|
||||
|
||||
return DBoolean::box<AGCObject>(mm, *native);
|
||||
}
|
||||
|
||||
TaggedPtr
|
||||
gco_to_bool(obj<AAllocator> /*mm*/,
|
||||
obj<AGCObject> obj)
|
||||
{
|
||||
static bool s_true = true;
|
||||
static bool s_false = false;
|
||||
|
||||
auto bool_obj = xo::facet::obj<AGCObject,DBoolean>::from(obj);
|
||||
|
||||
if (!bool_obj) {
|
||||
throw std::runtime_error
|
||||
(tostr("Object obj found where Boolean expected",
|
||||
xtag("obj", obj)));
|
||||
}
|
||||
|
||||
return Reflect::make_tp(bool_obj.data()->value() ? &s_true : &s_false);
|
||||
}
|
||||
|
||||
// DString <-> T
|
||||
// w/
|
||||
// T = std::string
|
||||
|
||||
obj<AGCObject>
|
||||
string_to_gco(obj<AAllocator> mm, TaggedPtr src)
|
||||
{
|
||||
// try std::string..
|
||||
|
||||
std::string * native = src.recover_native<std::string>();
|
||||
|
||||
assert(native);
|
||||
|
||||
DString * dstr = DString::from_str(mm, *native);
|
||||
|
||||
return xo::facet::obj<AGCObject,DString>(dstr);
|
||||
}
|
||||
|
||||
TaggedPtr
|
||||
gco_to_string(obj<AAllocator> mm, obj<AGCObject> obj)
|
||||
{
|
||||
auto string_obj = xo::facet::obj<AGCObject,DString>::from(obj);
|
||||
|
||||
if (!string_obj) {
|
||||
throw std::runtime_error
|
||||
(tostr("Object obj founcd where String expected",
|
||||
xtag("obj", obj)));
|
||||
}
|
||||
|
||||
// still don't have impl for this
|
||||
// Need regular std::allocator interface
|
||||
//
|
||||
|
||||
(void)mm;
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
ObjectConverter::ObjectConverter()
|
||||
{
|
||||
this->establish_conversion<std::int32_t>(&int_to_gco<std::int32_t>,
|
||||
&gco_to_int<std::int32_t>);
|
||||
this->establish_conversion<std::int64_t>(&int_to_gco<std::int64_t>,
|
||||
&gco_to_int<std::int64_t>);
|
||||
|
||||
this->establish_conversion<double>(&float_to_gco<double>,
|
||||
&gco_to_float<double>);
|
||||
|
||||
this->establish_conversion<bool>(&bool_to_gco,
|
||||
&gco_to_bool);
|
||||
|
||||
this->establish_conversion<std::string>(&string_to_gco,
|
||||
&gco_to_string);
|
||||
}
|
||||
|
||||
const ObjectConverter &
|
||||
ObjectConverter::instance() {
|
||||
static ObjectConverter s_instance;
|
||||
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
obj<AGCObject>
|
||||
ObjectConverter::tp_to_gco(obj<AAllocator> mm,
|
||||
TaggedPtr x_tp,
|
||||
bool throw_flag) const
|
||||
{
|
||||
using xo::reflect::Reflect;
|
||||
using xo::reflect::TaggedPtr;
|
||||
|
||||
const Converter * cvt = cvt_.lookup(x_tp.td());
|
||||
|
||||
if (cvt) {
|
||||
return (cvt->cvt_to_object_)(mm, x_tp);
|
||||
} else {
|
||||
if (throw_flag) {
|
||||
throw std::runtime_error
|
||||
(tostr("no to-object-converter available for instance of type",
|
||||
xtag("id", x_tp.td()->id()),
|
||||
xtag("name", x_tp.td()->short_name())));
|
||||
}
|
||||
|
||||
return obj<AGCObject>();
|
||||
}
|
||||
}
|
||||
|
||||
TaggedPtr
|
||||
ObjectConverter::tp_from_gco(obj<AAllocator> mm,
|
||||
obj<AGCObject> obj,
|
||||
TypeId target_id,
|
||||
bool throw_flag) const
|
||||
{
|
||||
const Converter * cvt = cvt_.lookup(target_id);
|
||||
|
||||
if (cvt) {
|
||||
return (cvt->cvt_from_object_)(mm, obj);
|
||||
} else {
|
||||
if (throw_flag) {
|
||||
throw std::runtime_error
|
||||
(tostr("no from-object-converter available for instance of type",
|
||||
xtag("id", target_id)));
|
||||
}
|
||||
|
||||
return TaggedPtr::universal_null();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* end GCObjectConverter.cpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue