+ xo-interpreter2 scaffold for constant expression [WIP]
This commit is contained in:
parent
ceb75e83c4
commit
3cbbe5ab63
13 changed files with 232 additions and 24 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
set(SELF_LIB xo_expression2)
|
||||
set(SELF_SRCS
|
||||
DConstant.cpp
|
||||
TypeRef.cpp
|
||||
#IExpression_Any.cpp
|
||||
expression2_register_facets.cpp
|
||||
|
|
@ -11,6 +12,7 @@ xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 $
|
|||
# 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_object2)
|
||||
xo_dependency(${SELF_LIB} xo_printable2)
|
||||
xo_dependency(${SELF_LIB} xo_flatstring)
|
||||
xo_dependency(${SELF_LIB} indentlog)
|
||||
|
|
|
|||
53
src/expression2/DConstant.cpp
Normal file
53
src/expression2/DConstant.cpp
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/** @file DConstant.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#include "DConstant.hpp"
|
||||
#include "TypeDescr.hpp"
|
||||
#include <xo/object2/DFloat.hpp>
|
||||
#include <xo/object2/DInteger.hpp>
|
||||
#include <xo/reflect/Reflect.hpp>
|
||||
#include <xo/reflectutil/typeseq.hpp>
|
||||
|
||||
namespace xo {
|
||||
using xo::scm::DFloat;
|
||||
using xo::scm::DInteger;
|
||||
using xo::reflect::Reflect;
|
||||
using xo::reflect::TypeDescr;
|
||||
using xo::reflect::typeseq;
|
||||
|
||||
namespace scm {
|
||||
DConstant::DConstant(obj<AGCObject> value) noexcept
|
||||
:
|
||||
//typeref_{TypeRef::resolved(td)},
|
||||
value_{value}
|
||||
{
|
||||
// todo: use ObjectConverter here
|
||||
|
||||
auto tseq = value_._typeseq();
|
||||
|
||||
TypeDescr td = this->_lookup_td(tseq);
|
||||
|
||||
if (td) {
|
||||
typeref_ = TypeRef::resolved(td);
|
||||
}
|
||||
}
|
||||
|
||||
TypeDescr
|
||||
DConstant::_lookup_td(typeseq tseq)
|
||||
{
|
||||
if (tseq == typeseq::id<DFloat>()) {
|
||||
/* double */
|
||||
return Reflect::require<DFloat::value_type>();
|
||||
} else if (tseq == typeseq::id<DInteger>()) {
|
||||
/* long */
|
||||
return Reflect::require<DInteger::value_type>();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DConstant.cpp */
|
||||
|
|
@ -11,6 +11,15 @@ namespace xo {
|
|||
: id_{id}, td_{td}
|
||||
{}
|
||||
|
||||
TypeRef
|
||||
TypeRef::resolved(TypeDescr td)
|
||||
{
|
||||
assert(td);
|
||||
|
||||
type_var null;
|
||||
return TypeRef(null, td);
|
||||
}
|
||||
|
||||
TypeRef
|
||||
TypeRef::dwim(prefix_type prefix, TypeDescr td)
|
||||
{
|
||||
|
|
@ -18,8 +27,7 @@ namespace xo {
|
|||
/* type already resolved
|
||||
* -> we don't need a type variable name
|
||||
*/
|
||||
type_var null;
|
||||
return TypeRef(null, td);
|
||||
return TypeRef::resolved(td);
|
||||
} else {
|
||||
/* type is not resolved yet.
|
||||
* -> give it a unique name,
|
||||
|
|
@ -49,7 +57,7 @@ namespace xo {
|
|||
}
|
||||
|
||||
bool
|
||||
TypeRef::is_concrete() const noexcept
|
||||
TypeRef::is_resolved() const noexcept
|
||||
{
|
||||
return (td_ != nullptr);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue