xo-reader2 stack: top-level lambda w/ apply parses
This commit is contained in:
parent
da1f099b4f
commit
60b8fda134
26 changed files with 858 additions and 20 deletions
|
|
@ -146,6 +146,44 @@ xo_add_genfacetimpl(
|
|||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-expression2-facetimpl-expression-varref
|
||||
FACET_PKG xo_expression2
|
||||
FACET Expression
|
||||
REPR VarRef
|
||||
INPUT idl/IExpression_DVarRef.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-varref
|
||||
FACET_PKG xo_gc
|
||||
FACET GCObject
|
||||
REPR VarRef
|
||||
INPUT idl/IGCObject_DVarRef.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-varref
|
||||
FACET_PKG xo_printable2
|
||||
FACET Printable
|
||||
REPR VarRef
|
||||
INPUT idl/IPrintable_DVarRef.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-expression-defineexpr
|
||||
|
|
@ -184,6 +222,18 @@ xo_add_genfacetimpl(
|
|||
OUTPUT_CPP_DIR src/expression2
|
||||
)
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-expression2-facetimpl-gcobject-applyexpr
|
||||
FACET_PKG xo_gc
|
||||
FACET GCObject
|
||||
REPR ApplyExpr
|
||||
INPUT idl/IGCObject_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
|
||||
|
|
|
|||
|
|
@ -67,4 +67,5 @@
|
|||
attributes: [],
|
||||
}
|
||||
],
|
||||
router_facet_explicit_content: [ ],
|
||||
}
|
||||
|
|
|
|||
12
idl/IExpression_DVarRef.json5
Normal file
12
idl/IExpression_DVarRef.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 DVarRef state",
|
||||
using_doxygen: true,
|
||||
repr: "DVarRef",
|
||||
doc: ["doc for IExpression+DVarRef" ],
|
||||
}
|
||||
15
idl/IGCObject_DApplyExpr.json5
Normal file
15
idl/IGCObject_DApplyExpr.json5
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
mode: "implementation",
|
||||
includes: [
|
||||
"<xo/gc/GCObject.hpp>",
|
||||
"<xo/alloc2/Allocator.hpp>"
|
||||
],
|
||||
local_types: [ ],
|
||||
namespace1: "xo",
|
||||
namespace2: "scm",
|
||||
facet_idl: "idl/GCObject.json5",
|
||||
brief: "provide AGCObject interface for DApplyExpr",
|
||||
using_doxygen: true,
|
||||
repr: "DApplyExpr",
|
||||
doc: [ "implement AGCObject for DApplyExpr" ],
|
||||
}
|
||||
15
idl/IGCObject_DVarRef.json5
Normal file
15
idl/IGCObject_DVarRef.json5
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
mode: "implementation",
|
||||
includes: [
|
||||
"<xo/gc/GCObject.hpp>",
|
||||
"<xo/alloc2/Allocator.hpp>"
|
||||
],
|
||||
local_types: [ ],
|
||||
namespace1: "xo",
|
||||
namespace2: "scm",
|
||||
facet_idl: "idl/GCObject.json5",
|
||||
brief: "provide AGCObject interface for DVarRef",
|
||||
using_doxygen: true,
|
||||
repr: "DVarRef",
|
||||
doc: [ "implement AGCObject for DVarRef" ],
|
||||
}
|
||||
13
idl/IPrintable_DVarRef.json5
Normal file
13
idl/IPrintable_DVarRef.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 DVarRef",
|
||||
using_doxygen: true,
|
||||
repr: "DVarRef",
|
||||
doc: [ "implement APrintable for DVarRef" ],
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include "DApplyExpr.hpp"
|
||||
#include "detail/IExpression_DApplyExpr.hpp"
|
||||
//#include "detail/IGCObject_DApplyExpr.hpp"
|
||||
#include "detail/IGCObject_DApplyExpr.hpp"
|
||||
#include "detail/IPrintable_DApplyExpr.hpp"
|
||||
|
||||
/* end ApplyExpr.hpp */
|
||||
|
|
|
|||
|
|
@ -5,14 +5,15 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
class Binding {
|
||||
public:
|
||||
static constexpr int32_t s_link_sentinel = -2;
|
||||
static constexpr int32_t s_link_global = -1;
|
||||
static constexpr int32_t c_link_sentinel = -2;
|
||||
static constexpr int32_t c_link_global = -1;
|
||||
|
||||
public:
|
||||
Binding() : i_link_{-2}, j_slot_{-1} {}
|
||||
|
|
@ -21,18 +22,22 @@ namespace xo {
|
|||
|
||||
static Binding null() { return Binding(); }
|
||||
/** global bindings are located by symbol name **/
|
||||
static Binding global() { return Binding(s_link_global, 0); }
|
||||
static Binding global() { return Binding(c_link_global, 0); }
|
||||
static Binding local(int32_t j_slot) { return Binding(0, j_slot); }
|
||||
static Binding relative(int32_t i_link, Binding def);
|
||||
|
||||
bool is_null() const {
|
||||
return (i_link_ == s_link_sentinel) && (j_slot_ == -1);
|
||||
return (i_link_ == c_link_sentinel) && (j_slot_ == -1);
|
||||
}
|
||||
bool is_global() const { return i_link_ == s_link_global; }
|
||||
bool is_global() const { return i_link_ == c_link_global; }
|
||||
bool is_local() const { return (i_link_ == 0) && (j_slot_ >= 0); }
|
||||
|
||||
int32_t i_link() const noexcept { return i_link_; }
|
||||
int32_t j_slot() const noexcept { return j_slot_; }
|
||||
|
||||
/** print human-readable repr to stream @p os **/
|
||||
void print(std::ostream & os) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* >= 0: number of parent links to traverse
|
||||
|
|
@ -40,13 +45,18 @@ namespace xo {
|
|||
* -1: resolve globally
|
||||
* -2: sentinel (binding info not computed)
|
||||
**/
|
||||
int32_t i_link_ = s_link_sentinel;
|
||||
int32_t i_link_ = c_link_sentinel;
|
||||
/** if @ref i_link_ >= 0, frame offset
|
||||
* (in 'variables' not bytes).
|
||||
* ignored if @ref i_link_ is global
|
||||
**/
|
||||
int32_t j_slot_ = -1;
|
||||
};
|
||||
|
||||
inline std::ostream & operator<< (std::ostream & os, Binding x) {
|
||||
x.print(os);
|
||||
return os;
|
||||
}
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ namespace xo {
|
|||
**/
|
||||
class DApplyExpr {
|
||||
public:
|
||||
using ACollector = xo::mm::ACollector;
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using TypeDescr = xo::reflect::TypeDescr;
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
|
|
@ -81,7 +82,9 @@ namespace xo {
|
|||
/** @defgroup scm-applyexpr-gcobject-facet **/
|
||||
///@{
|
||||
|
||||
// shallow_copy() etc.
|
||||
std::size_t shallow_size() const noexcept;
|
||||
DApplyExpr * shallow_copy(obj<AAllocator> mm) const noexcept;
|
||||
std::size_t forward_children(obj<ACollector> gc) noexcept;
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-applyexpr-printable-facet **/
|
||||
|
|
|
|||
|
|
@ -31,14 +31,14 @@ namespace xo {
|
|||
|
||||
struct Slot {
|
||||
Slot() = default;
|
||||
explicit Slot(const DVariable * var) : var_{var} {}
|
||||
explicit Slot(DVariable * var) : var_{var} {}
|
||||
|
||||
/** variable representing a formal argument.
|
||||
* binding will be correct only within the same layer
|
||||
* as top-level lambda body
|
||||
* (i.e. up to the doorstep of each and every nested lambda)
|
||||
**/
|
||||
const DVariable * var_ = nullptr;
|
||||
DVariable * var_ = nullptr;
|
||||
};
|
||||
|
||||
public:
|
||||
|
|
@ -65,7 +65,7 @@ namespace xo {
|
|||
size_type capacity() const noexcept { return capacity_; }
|
||||
size_type size() const noexcept { return size_; }
|
||||
|
||||
const DVariable * lookup_var(Binding ix) const noexcept {
|
||||
DVariable * lookup_var(Binding ix) noexcept {
|
||||
assert(ix.i_link() == 0);
|
||||
assert(ix.j_slot() < static_cast<int32_t>(size_));
|
||||
|
||||
|
|
|
|||
84
include/xo/expression2/DVarRef.hpp
Normal file
84
include/xo/expression2/DVarRef.hpp
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/** @file DVarRef.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Variable.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
/** @class DVarRef
|
||||
* @brief syntax for a variable reference
|
||||
*
|
||||
* Reference to a known variable possibly
|
||||
* defined in another scope.
|
||||
* For non-local non-global variables,
|
||||
**/
|
||||
class DVarRef {
|
||||
public:
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
using ACollector = xo::mm::ACollector;
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using TypeDescr = xo::reflect::TypeDescr;
|
||||
|
||||
public:
|
||||
DVarRef(DVariable * vardef,
|
||||
Binding path);
|
||||
|
||||
/** create instance
|
||||
* @p mm memory allocator
|
||||
* @p vardef variable definition (name, typeref, binding)
|
||||
* @p link number of lexical scope boundaries we must cross
|
||||
* to reach scope containing @p vardef.
|
||||
* Only relevant for non-global vardef
|
||||
**/
|
||||
static DVarRef * make(obj<AAllocator> mm,
|
||||
DVariable * vardef,
|
||||
int32_t link);
|
||||
|
||||
const DUniqueString * name() const;
|
||||
Binding path() const { return path_; }
|
||||
|
||||
/** @defgroup scm-variable-expression-facet **/
|
||||
///@{
|
||||
|
||||
exprtype extype() const noexcept { return exprtype::varref; }
|
||||
TypeRef typeref() const noexcept;
|
||||
TypeDescr valuetype() const noexcept;
|
||||
void assign_valuetype(TypeDescr td) noexcept;
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-variable-gcobject-facet **/
|
||||
///@{
|
||||
|
||||
size_t shallow_size() const noexcept;
|
||||
DVarRef * shallow_copy(obj<AAllocator> mm) const noexcept;
|
||||
size_t forward_children(obj<ACollector> gc) noexcept;
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-variable-printable-facet **/
|
||||
///@{
|
||||
|
||||
bool pretty(const ppindentinfo & ppii) const;
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
/** variable definition. Created in the sccope where variable introduced.
|
||||
* Has an associated @ref Binding, but that binding is only correct
|
||||
* around any nested scopes.
|
||||
**/
|
||||
DVariable * vardef_ = nullptr;
|
||||
|
||||
/** at runtime: navigate environemnt via this path to get
|
||||
* runtime memory location for this variable
|
||||
**/
|
||||
Binding path_;
|
||||
};
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DVarRef.hpp */
|
||||
13
include/xo/expression2/VarRef.hpp
Normal file
13
include/xo/expression2/VarRef.hpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/** @file VarRef.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DVarRef.hpp"
|
||||
#include "detail/IExpression_DVarRef.hpp"
|
||||
#include "detail/IGCObject_DVarRef.hpp"
|
||||
#include "detail/IPrintable_DVarRef.hpp"
|
||||
|
||||
/* end VarRef.hpp */
|
||||
66
include/xo/expression2/detail/IExpression_DVarRef.hpp
Normal file
66
include/xo/expression2/detail/IExpression_DVarRef.hpp
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/** @file IExpression_DVarRef.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IExpression_DVarRef.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IExpression_DVarRef.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Expression.hpp"
|
||||
#include "Expression.hpp"
|
||||
#include "DVarRef.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IExpression_DVarRef; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::scm::AExpression,
|
||||
xo::scm::DVarRef>
|
||||
{
|
||||
using ImplType = xo::scm::IExpression_Xfer
|
||||
<xo::scm::DVarRef,
|
||||
xo::scm::IExpression_DVarRef>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IExpression_DVarRef
|
||||
**/
|
||||
class IExpression_DVarRef {
|
||||
public:
|
||||
/** @defgroup scm-expression-dvarref-type-traits **/
|
||||
///@{
|
||||
using TypeDescr = xo::scm::AExpression::TypeDescr;
|
||||
using Copaque = xo::scm::AExpression::Copaque;
|
||||
using Opaque = xo::scm::AExpression::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-expression-dvarref-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** expression type (constant | apply | ..) **/
|
||||
static exprtype extype(const DVarRef & self) noexcept;
|
||||
/** placeholder for type giving possible values for this expression **/
|
||||
static TypeRef typeref(const DVarRef & self) noexcept;
|
||||
/** type giving possible values for this expression. Maybe null before typecheck **/
|
||||
static TypeDescr valuetype(const DVarRef & self) noexcept;
|
||||
|
||||
// non-const methods
|
||||
/** assing to valuetype member. Useful when scaffolding expressions **/
|
||||
static void assign_valuetype(DVarRef & self, TypeDescr td) noexcept;
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
67
include/xo/expression2/detail/IGCObject_DApplyExpr.hpp
Normal file
67
include/xo/expression2/detail/IGCObject_DApplyExpr.hpp
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/** @file IGCObject_DApplyExpr.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IGCObject_DApplyExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IGCObject_DApplyExpr.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GCObject.hpp"
|
||||
#include <xo/gc/GCObject.hpp>
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include "DApplyExpr.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IGCObject_DApplyExpr; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::mm::AGCObject,
|
||||
xo::scm::DApplyExpr>
|
||||
{
|
||||
using ImplType = xo::mm::IGCObject_Xfer
|
||||
<xo::scm::DApplyExpr,
|
||||
xo::scm::IGCObject_DApplyExpr>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IGCObject_DApplyExpr
|
||||
**/
|
||||
class IGCObject_DApplyExpr {
|
||||
public:
|
||||
/** @defgroup scm-gcobject-dapplyexpr-type-traits **/
|
||||
///@{
|
||||
using size_type = xo::mm::AGCObject::size_type;
|
||||
using AAllocator = xo::mm::AGCObject::AAllocator;
|
||||
using ACollector = xo::mm::AGCObject::ACollector;
|
||||
using Copaque = xo::mm::AGCObject::Copaque;
|
||||
using Opaque = xo::mm::AGCObject::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-gcobject-dapplyexpr-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** memory consumption for this instance **/
|
||||
static size_type shallow_size(const DApplyExpr & self) noexcept;
|
||||
/** copy instance using allocator **/
|
||||
static Opaque shallow_copy(const DApplyExpr & self, obj<AAllocator> mm) noexcept;
|
||||
|
||||
// non-const methods
|
||||
/** during GC: forward immdiate children **/
|
||||
static size_type forward_children(DApplyExpr & self, obj<ACollector> gc) noexcept;
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
67
include/xo/expression2/detail/IGCObject_DVarRef.hpp
Normal file
67
include/xo/expression2/detail/IGCObject_DVarRef.hpp
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/** @file IGCObject_DVarRef.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IGCObject_DVarRef.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IGCObject_DVarRef.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GCObject.hpp"
|
||||
#include <xo/gc/GCObject.hpp>
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include "DVarRef.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IGCObject_DVarRef; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::mm::AGCObject,
|
||||
xo::scm::DVarRef>
|
||||
{
|
||||
using ImplType = xo::mm::IGCObject_Xfer
|
||||
<xo::scm::DVarRef,
|
||||
xo::scm::IGCObject_DVarRef>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IGCObject_DVarRef
|
||||
**/
|
||||
class IGCObject_DVarRef {
|
||||
public:
|
||||
/** @defgroup scm-gcobject-dvarref-type-traits **/
|
||||
///@{
|
||||
using size_type = xo::mm::AGCObject::size_type;
|
||||
using AAllocator = xo::mm::AGCObject::AAllocator;
|
||||
using ACollector = xo::mm::AGCObject::ACollector;
|
||||
using Copaque = xo::mm::AGCObject::Copaque;
|
||||
using Opaque = xo::mm::AGCObject::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-gcobject-dvarref-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** memory consumption for this instance **/
|
||||
static size_type shallow_size(const DVarRef & self) noexcept;
|
||||
/** copy instance using allocator **/
|
||||
static Opaque shallow_copy(const DVarRef & self, obj<AAllocator> mm) noexcept;
|
||||
|
||||
// non-const methods
|
||||
/** during GC: forward immdiate children **/
|
||||
static size_type forward_children(DVarRef & self, obj<ACollector> gc) noexcept;
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
62
include/xo/expression2/detail/IPrintable_DVarRef.hpp
Normal file
62
include/xo/expression2/detail/IPrintable_DVarRef.hpp
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/** @file IPrintable_DVarRef.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DVarRef.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DVarRef.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Printable.hpp"
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
|
||||
#include "DVarRef.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IPrintable_DVarRef; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::print::APrintable,
|
||||
xo::scm::DVarRef>
|
||||
{
|
||||
using ImplType = xo::print::IPrintable_Xfer
|
||||
<xo::scm::DVarRef,
|
||||
xo::scm::IPrintable_DVarRef>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IPrintable_DVarRef
|
||||
**/
|
||||
class IPrintable_DVarRef {
|
||||
public:
|
||||
/** @defgroup scm-printable-dvarref-type-traits **/
|
||||
///@{
|
||||
using ppindentinfo = xo::print::APrintable::ppindentinfo;
|
||||
using Copaque = xo::print::APrintable::Copaque;
|
||||
using Opaque = xo::print::APrintable::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-printable-dvarref-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** Pretty-printing support for this object.
|
||||
See [xo-indentlog/xo/indentlog/pretty.hpp] **/
|
||||
static bool pretty(const DVarRef & self, const ppindentinfo & ppii);
|
||||
|
||||
// non-const methods
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -36,8 +36,10 @@ namespace xo {
|
|||
/** function definition **/
|
||||
lambda,
|
||||
|
||||
/** variable reference **/
|
||||
/** variable definition **/
|
||||
variable,
|
||||
/** variabele reference (possibly non-local) **/
|
||||
varref,
|
||||
/** if-then-else **/
|
||||
ifexpr,
|
||||
/** sequence **/
|
||||
|
|
@ -65,14 +67,16 @@ namespace xo {
|
|||
case exprtype::assign: return "assign";
|
||||
#endif
|
||||
case exprtype::apply: return "apply";
|
||||
#ifdef NOT_YET
|
||||
case exprtype::lambda: return "lambda";
|
||||
case exprtype::variable: return "variable";
|
||||
case exprtype::varref: return "varref";
|
||||
case exprtype::ifexpr: return "if_expr";
|
||||
case exprtype::sequence: return "sequence";
|
||||
#ifdef NOT_YET
|
||||
case exprtype::convert: return "convert";
|
||||
#endif
|
||||
default: break;
|
||||
case exprtype::N: break;
|
||||
//default: break;
|
||||
}
|
||||
|
||||
return "???exprtype???";
|
||||
|
|
|
|||
41
src/expression2/Binding.cpp
Normal file
41
src/expression2/Binding.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/** @file Binding.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#include "Binding.hpp"
|
||||
#include <cassert>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
Binding
|
||||
Binding::relative(int32_t i_link, Binding def)
|
||||
{
|
||||
if (def.i_link_ == Binding::c_link_global) {
|
||||
// for globally defined vars, i_link always -1
|
||||
return def;
|
||||
} else if (def.i_link_ >= 0) {
|
||||
return Binding(i_link + def.i_link_, def.j_slot_);
|
||||
} else {
|
||||
assert(false);
|
||||
return Binding();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Binding::print(std::ostream & os) const
|
||||
{
|
||||
if (i_link_ == c_link_global) {
|
||||
os << "{path:global}";
|
||||
} else if (i_link_ == c_link_sentinel) {
|
||||
os << "{path}";
|
||||
} else {
|
||||
os << "{path:" << i_link_ << ":" << j_slot_ << "}";
|
||||
}
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end Binding.cpp */
|
||||
|
|
@ -3,9 +3,12 @@
|
|||
set(SELF_LIB xo_expression2)
|
||||
set(SELF_SRCS
|
||||
init_expression2.cpp
|
||||
expression2_register_facets.cpp
|
||||
expression2_register_types.cpp
|
||||
|
||||
DConstant.cpp
|
||||
DVariable.cpp
|
||||
DVarRef.cpp
|
||||
DDefineExpr.cpp
|
||||
DLambdaExpr.cpp
|
||||
DApplyExpr.cpp
|
||||
|
|
@ -13,6 +16,7 @@ set(SELF_SRCS
|
|||
DSequenceExpr.cpp
|
||||
|
||||
TypeRef.cpp
|
||||
Binding.cpp
|
||||
|
||||
IExpression_Any.cpp
|
||||
|
||||
|
|
@ -24,10 +28,15 @@ set(SELF_SRCS
|
|||
IGCObject_DVariable.cpp
|
||||
IPrintable_DVariable.cpp
|
||||
|
||||
IExpression_DVarRef.cpp
|
||||
IGCObject_DVarRef.cpp
|
||||
IPrintable_DVarRef.cpp
|
||||
|
||||
IExpression_DDefineExpr.cpp
|
||||
IPrintable_DDefineExpr.cpp
|
||||
|
||||
IExpression_DApplyExpr.cpp
|
||||
IGCObject_DApplyExpr.cpp
|
||||
IPrintable_DApplyExpr.cpp
|
||||
|
||||
IExpression_DLambdaExpr.cpp
|
||||
|
|
@ -55,8 +64,6 @@ set(SELF_SRCS
|
|||
IGCObject_DUniqueString.cpp
|
||||
IPrintable_DUniqueString.cpp
|
||||
|
||||
expression2_register_facets.cpp
|
||||
expression2_register_types.cpp
|
||||
)
|
||||
|
||||
xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS})
|
||||
|
|
|
|||
|
|
@ -102,6 +102,48 @@ namespace xo {
|
|||
typeref_.resolve(td);
|
||||
}
|
||||
|
||||
// ----- gcobject facet -----
|
||||
|
||||
std::size_t
|
||||
DApplyExpr::shallow_size() const noexcept {
|
||||
return sizeof(DApplyExpr) + (n_args_ * sizeof(obj<AExpression>));
|
||||
}
|
||||
|
||||
DApplyExpr *
|
||||
DApplyExpr::shallow_copy(obj<AAllocator> mm) const noexcept {
|
||||
DApplyExpr * copy = (DApplyExpr *)mm.alloc_copy((std::byte *)this);
|
||||
|
||||
if (copy) {
|
||||
copy->typeref_ = typeref_;
|
||||
copy->fn_ = fn_;
|
||||
copy->n_args_ = n_args_;
|
||||
|
||||
constexpr auto c_obj_z = sizeof(obj<AExpression>);
|
||||
|
||||
::memcpy((void*)&(copy->args_[0]), (void*)&(args_[0]), n_args_ * c_obj_z);
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
std::size_t
|
||||
DApplyExpr::forward_children(obj<ACollector> gc) noexcept
|
||||
{
|
||||
for (size_type i = 0; i < n_args_; ++i) {
|
||||
obj<AExpression> & arg = args_[i];
|
||||
|
||||
// runtime poly here
|
||||
obj<AGCObject> arg_gco = arg.to_facet<AGCObject>();
|
||||
|
||||
// need the data address within *this
|
||||
gc.forward_inplace(arg_gco.iface(), (void **)(&arg.data_));
|
||||
}
|
||||
|
||||
return shallow_size();
|
||||
}
|
||||
|
||||
// ----- printable facet -----
|
||||
|
||||
bool
|
||||
DApplyExpr::pretty(const ppindentinfo & ppii) const {
|
||||
using xo::print::ppstate;
|
||||
|
|
|
|||
105
src/expression2/DVarRef.cpp
Normal file
105
src/expression2/DVarRef.cpp
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
/** @file DVarRef.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#include "DVarRef.hpp"
|
||||
|
||||
namespace xo {
|
||||
using xo::mm::AGCObject;
|
||||
using xo::reflect::TypeDescr;
|
||||
|
||||
namespace scm {
|
||||
|
||||
DVarRef::DVarRef(DVariable * vardef,
|
||||
Binding path)
|
||||
: vardef_{vardef},
|
||||
path_{path}
|
||||
{}
|
||||
|
||||
DVarRef *
|
||||
DVarRef::make(obj<AAllocator> mm,
|
||||
DVariable * vardef,
|
||||
int32_t link)
|
||||
{
|
||||
assert(vardef);
|
||||
|
||||
void * mem = mm.alloc_for<DVarRef>();
|
||||
|
||||
return new (mem) DVarRef(vardef,
|
||||
Binding::relative(link,
|
||||
vardef->path()));
|
||||
}
|
||||
|
||||
const DUniqueString *
|
||||
DVarRef::name() const {
|
||||
return vardef_->name();
|
||||
}
|
||||
|
||||
TypeRef
|
||||
DVarRef::typeref() const noexcept {
|
||||
assert(vardef_);
|
||||
|
||||
return vardef_->typeref();
|
||||
}
|
||||
|
||||
TypeDescr
|
||||
DVarRef::valuetype() const noexcept
|
||||
{
|
||||
return this->typeref().td();
|
||||
}
|
||||
|
||||
void
|
||||
DVarRef::assign_valuetype(TypeDescr td) noexcept
|
||||
{
|
||||
assert(vardef_);
|
||||
vardef_->assign_valuetype(td);
|
||||
}
|
||||
|
||||
// gcobject facet
|
||||
|
||||
std::size_t
|
||||
DVarRef::shallow_size() const noexcept
|
||||
{
|
||||
return sizeof(DVarRef);
|
||||
}
|
||||
|
||||
DVarRef *
|
||||
DVarRef::shallow_copy(obj<AAllocator> mm) const noexcept
|
||||
{
|
||||
DVarRef * copy = (DVarRef *)mm.alloc_copy((std::byte *)this);
|
||||
|
||||
if (copy)
|
||||
*copy = *this;
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
std::size_t
|
||||
DVarRef::forward_children(obj<ACollector> gc) noexcept
|
||||
{
|
||||
// TODO: this can be helper in RCollector interface
|
||||
auto iface = xo::facet::impl_for<AGCObject,DVariable>();
|
||||
gc.forward_inplace(&iface, (void **)vardef_);
|
||||
|
||||
// TODO: concept to indicate that no gc pointers in Binding
|
||||
|
||||
return shallow_size();
|
||||
}
|
||||
|
||||
// printable facet
|
||||
|
||||
bool
|
||||
DVarRef::pretty(const ppindentinfo & ppii) const
|
||||
{
|
||||
return ppii.pps()->pretty_struct
|
||||
(ppii,
|
||||
"DVarRef",
|
||||
refrtag("name", std::string_view(*(this->name()))),
|
||||
refrtag("path", this->path_));
|
||||
}
|
||||
|
||||
}
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DVarRef.cpp */
|
||||
45
src/expression2/IExpression_DVarRef.cpp
Normal file
45
src/expression2/IExpression_DVarRef.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/** @file IExpression_DVarRef.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IExpression_DVarRef.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IExpression_DVarRef.json5]
|
||||
**/
|
||||
|
||||
#include "detail/IExpression_DVarRef.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IExpression_DVarRef::extype(const DVarRef & self) noexcept -> exprtype
|
||||
{
|
||||
return self.extype();
|
||||
}
|
||||
|
||||
auto
|
||||
IExpression_DVarRef::typeref(const DVarRef & self) noexcept -> TypeRef
|
||||
{
|
||||
return self.typeref();
|
||||
}
|
||||
|
||||
auto
|
||||
IExpression_DVarRef::valuetype(const DVarRef & self) noexcept -> TypeDescr
|
||||
{
|
||||
return self.valuetype();
|
||||
}
|
||||
|
||||
auto
|
||||
IExpression_DVarRef::assign_valuetype(DVarRef & self, TypeDescr td) noexcept -> void
|
||||
{
|
||||
self.assign_valuetype(td);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IExpression_DVarRef.cpp */
|
||||
39
src/expression2/IGCObject_DApplyExpr.cpp
Normal file
39
src/expression2/IGCObject_DApplyExpr.cpp
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/** @file IGCObject_DApplyExpr.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IGCObject_DApplyExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IGCObject_DApplyExpr.json5]
|
||||
**/
|
||||
|
||||
#include "detail/IGCObject_DApplyExpr.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IGCObject_DApplyExpr::shallow_size(const DApplyExpr & self) noexcept -> size_type
|
||||
{
|
||||
return self.shallow_size();
|
||||
}
|
||||
|
||||
auto
|
||||
IGCObject_DApplyExpr::shallow_copy(const DApplyExpr & self, obj<AAllocator> mm) noexcept -> Opaque
|
||||
{
|
||||
return self.shallow_copy(mm);
|
||||
}
|
||||
|
||||
auto
|
||||
IGCObject_DApplyExpr::forward_children(DApplyExpr & self, obj<ACollector> gc) noexcept -> size_type
|
||||
{
|
||||
return self.forward_children(gc);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IGCObject_DApplyExpr.cpp */
|
||||
39
src/expression2/IGCObject_DVarRef.cpp
Normal file
39
src/expression2/IGCObject_DVarRef.cpp
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/** @file IGCObject_DVarRef.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IGCObject_DVarRef.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IGCObject_DVarRef.json5]
|
||||
**/
|
||||
|
||||
#include "detail/IGCObject_DVarRef.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IGCObject_DVarRef::shallow_size(const DVarRef & self) noexcept -> size_type
|
||||
{
|
||||
return self.shallow_size();
|
||||
}
|
||||
|
||||
auto
|
||||
IGCObject_DVarRef::shallow_copy(const DVarRef & self, obj<AAllocator> mm) noexcept -> Opaque
|
||||
{
|
||||
return self.shallow_copy(mm);
|
||||
}
|
||||
|
||||
auto
|
||||
IGCObject_DVarRef::forward_children(DVarRef & self, obj<ACollector> gc) noexcept -> size_type
|
||||
{
|
||||
return self.forward_children(gc);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IGCObject_DVarRef.cpp */
|
||||
28
src/expression2/IPrintable_DVarRef.cpp
Normal file
28
src/expression2/IPrintable_DVarRef.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/** @file IPrintable_DVarRef.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DVarRef.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DVarRef.json5]
|
||||
**/
|
||||
|
||||
#include "detail/IPrintable_DVarRef.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IPrintable_DVarRef::pretty(const DVarRef & self, const ppindentinfo & ppii) -> bool
|
||||
{
|
||||
return self.pretty(ppii);
|
||||
}
|
||||
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IPrintable_DVarRef.cpp */
|
||||
|
|
@ -16,13 +16,13 @@
|
|||
#include <xo/expression2/detail/IGCObject_DVariable.hpp>
|
||||
#include <xo/expression2/detail/IPrintable_DVariable.hpp>
|
||||
|
||||
#include <xo/expression2/VarRef.hpp>
|
||||
|
||||
#include <xo/expression2/detail/IExpression_DConstant.hpp>
|
||||
#include <xo/expression2/detail/IGCObject_DConstant.hpp>
|
||||
#include <xo/expression2/detail/IPrintable_DConstant.hpp>
|
||||
|
||||
#include <xo/expression2/detail/IExpression_DApplyExpr.hpp>
|
||||
//#include <xo/expression2/detail/IGCObject_DApplyExpr.hpp>
|
||||
#include <xo/expression2/detail/IPrintable_DApplyExpr.hpp>
|
||||
#include <xo/expression2/ApplyExpr.hpp>
|
||||
|
||||
#include <xo/expression2/detail/IExpression_DLambdaExpr.hpp>
|
||||
//#include <xo/expression2/detail/IGCObject_DLambdaExpr.hpp>
|
||||
|
|
@ -63,6 +63,7 @@ namespace xo {
|
|||
// Expression
|
||||
// +- Constant
|
||||
// +- Variable
|
||||
// +- VarRef
|
||||
// +- DefineExpr
|
||||
// +- ApplyExpr
|
||||
// +- LambdaExpr
|
||||
|
|
@ -77,13 +78,20 @@ namespace xo {
|
|||
FacetRegistry::register_impl<AGCObject, DVariable>();
|
||||
FacetRegistry::register_impl<APrintable, DVariable>();
|
||||
|
||||
FacetRegistry::register_impl<AExpression, DVarRef>();
|
||||
FacetRegistry::register_impl<AGCObject, DVarRef>();
|
||||
FacetRegistry::register_impl<APrintable, DVarRef>();
|
||||
|
||||
FacetRegistry::register_impl<AExpression, DDefineExpr>();
|
||||
//FacetRegistry::register_impl<AGCObject, DDefineExpr>();
|
||||
FacetRegistry::register_impl<APrintable, DDefineExpr>();
|
||||
|
||||
FacetRegistry::register_impl<AExpression, DApplyExpr>();
|
||||
FacetRegistry::register_impl<AGCObject, DApplyExpr>();
|
||||
FacetRegistry::register_impl<APrintable, DApplyExpr>();
|
||||
|
||||
FacetRegistry::register_impl<AExpression, DLambdaExpr>();
|
||||
//FacetRegistry::register_impl<AGCObject, DLambdaExpr>();
|
||||
FacetRegistry::register_impl<APrintable, DLambdaExpr>();
|
||||
|
||||
FacetRegistry::register_impl<AExpression, DIfElseExpr>();
|
||||
|
|
@ -95,11 +103,13 @@ namespace xo {
|
|||
FacetRegistry::register_impl<APrintable, DSequenceExpr>();
|
||||
|
||||
FacetRegistry::register_impl<ASymbolTable, DLocalSymtab>();
|
||||
//FacetRegistry::register_impl<AGCObject, DLocalSymtab>();
|
||||
FacetRegistry::register_impl<APrintable, DLocalSymtab>();
|
||||
|
||||
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("DVarRef.tseq", typeseq::id<DVarRef>()));
|
||||
log && log(xtag("DConstant.tseq", typeseq::id<DConstant>()));
|
||||
log && log(xtag("DApplyExpr.tseq", typeseq::id<DApplyExpr>()));
|
||||
log && log(xtag("DLambdaExpr.tseq", typeseq::id<DLambdaExpr>()));
|
||||
|
|
@ -108,7 +118,7 @@ namespace xo {
|
|||
|
||||
log && log(xtag("DLocalSymtab.tseq", typeseq::id<DLocalSymtab>()));
|
||||
|
||||
log && log(xtag("AExpression.tqseq", typeseq::id<AExpression>()));
|
||||
log && log(xtag("AExpression.tseq", typeseq::id<AExpression>()));
|
||||
log && log(xtag("ASymbolTable.tseq", typeseq::id<ASymbolTable>()));
|
||||
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue