xo-expression2: + Expression facet

This commit is contained in:
Roland Conybeare 2026-01-12 21:50:17 -05:00
commit ceb75e83c4
14 changed files with 634 additions and 4 deletions

View file

@ -0,0 +1,16 @@
# expression2/CMakeLists.txt
set(SELF_LIB xo_expression2)
set(SELF_SRCS
TypeRef.cpp
#IExpression_Any.cpp
expression2_register_facets.cpp
)
xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS})
# note: deps here must also appear in cmake/xo_expression2Config.cmake.in
xo_dependency(${SELF_LIB} xo_gc)
xo_dependency(${SELF_LIB} reflect)
xo_dependency(${SELF_LIB} xo_printable2)
xo_dependency(${SELF_LIB} xo_flatstring)
xo_dependency(${SELF_LIB} indentlog)

View file

@ -0,0 +1,38 @@
/** @file IExpression_Any.cpp
*
**/
#include "detail/IExpression_Any.hpp"
#include <iostream>
namespace xo {
namespace scm {
using xo::facet::DVariantPlaceholder;
using xo::facet::typeseq;
using xo::facet::valid_facet_implementation;
void
IExpression_Any::_fatal()
{
/* control here on uninitialized IAllocator_Any.
* Initialized instance will have specific implementation type
*/
std::cerr << "fatal"
<< ": attempt to call uninitialized"
<< " IExpression_Any method"
<< std::endl;
std::terminate();
}
typeseq
IExpression_Any::s_typeseq = typeseq::id<DVariantPlaceholder>();
bool
IExpression_Any::_valid
= valid_facet_implementation<AExpression, IExpression_Any>();
} /*namespace scm*/
} /*namespace xo*/
/* end IExpression_Any.cpp */

View file

@ -0,0 +1,60 @@
/** @file TypeRef.cpp
*
* @author Roland Conybeare, Jan 2026
**/
#include "TypeRef.hpp"
namespace xo {
namespace scm {
TypeRef::TypeRef(const type_var & id, TypeDescr td)
: id_{id}, td_{td}
{}
TypeRef
TypeRef::dwim(prefix_type prefix, TypeDescr td)
{
if (td) {
/* type already resolved
* -> we don't need a type variable name
*/
type_var null;
return TypeRef(null, td);
} else {
/* type is not resolved yet.
* -> give it a unique name,
* to seed unification
*/
return TypeRef(generate_unique(prefix), td);
}
}
auto
TypeRef::generate_unique(prefix_type prefix) -> type_var
{
static uint32_t s_counter = 0;
s_counter = (1 + s_counter) % 1000000000;
char buf[type_var::fixed_capacity];
int n = snprintf(buf, sizeof(buf), "%s:%u", prefix.c_str(), s_counter);
(void)n;;
assert(n < static_cast<int>(type_var::fixed_capacity));
// not necessary, but to remove all doubt.
buf [sizeof(buf) - 1] = '\0';
return type_var(buf);
}
bool
TypeRef::is_concrete() const noexcept
{
return (td_ != nullptr);
}
} /*namespace scm*/
} /*namespace xo*/
/* end TypeRef.cpp */

View file

@ -0,0 +1,11 @@
/** @file expression2_register_facets.cpp
*
* @author Roland Conybeare, Jan 2026
**/
namespace xo {
namespace scm {
}
} /*namesapce xo*/
/* end expression2_register_facets.cpp */