+ 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
|
|
@ -3,7 +3,10 @@
|
|||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#include <xo/reflect/TypeDescr.hpp>
|
||||
#include "TypeRef.hpp"
|
||||
#include "exprtype.hpp"
|
||||
#include <xo/reflect/TaggedPtr.hpp>
|
||||
#include <xo/gc/GCObject.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
|
@ -12,24 +15,36 @@ namespace xo {
|
|||
**/
|
||||
struct DConstant {
|
||||
public:
|
||||
using TaggedPtr = xo::reflect::TaggedPtr;
|
||||
using TypeDescr = xo::reflect::TypeDescr;
|
||||
using AGCObject = xo::mm::AGCObject;
|
||||
using typeseq = xo::reflect::typeseq;
|
||||
|
||||
public:
|
||||
DConstant(TypeDescr td, void * value);
|
||||
explicit DConstant(obj<AGCObject> value) noexcept;
|
||||
|
||||
TypeDescr value_td() const { return value_td; }
|
||||
bool is_resolved() const noexcept { return typeref_.is_resolved(); }
|
||||
|
||||
TypeRef typeref() const noexcept;
|
||||
TypeDescr valuetype() const noexcept;
|
||||
void assign_valuetype(TypeDescr td) noexcept;
|
||||
exprtype extype() const noexcept { return exprtype::constant; }
|
||||
TypeDescr value_td() const noexcept { return typeref_.td(); }
|
||||
TaggedPtr value_tp() const noexcept { return TaggedPtr(typeref_.td(), value_.data()); }
|
||||
|
||||
TypeRef typeref() const noexcept { return typeref_; }
|
||||
TypeDescr valuetype() const noexcept { return typeref_.td(); }
|
||||
obj<AGCObject> value() const noexcept { return value_; }
|
||||
|
||||
void assign_valuetype(TypeDescr td) noexcept { typeref_.resolve(td); }
|
||||
|
||||
private:
|
||||
/** type for value of this expression **/
|
||||
TypeRef type_ref_;
|
||||
/** type description for destination *value_ **/
|
||||
TypeDescr valuetype_;
|
||||
static TypeDescr _lookup_td(typeseq tseq);
|
||||
|
||||
private:
|
||||
/** type for value of this expression
|
||||
* or unification breadcrumb before unification
|
||||
**/
|
||||
TypeRef typeref_;
|
||||
/** literal value **/
|
||||
void * value_;
|
||||
obj<AGCObject> value_;
|
||||
};
|
||||
} /*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/Expression.json5]
|
||||
* 2. jinja2 template for facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -26,6 +26,11 @@ namespace xo {
|
|||
TypeRef() = default;
|
||||
TypeRef(const type_var & id, TypeDescr td);
|
||||
|
||||
/** trivial typeref, where already resolved.
|
||||
* Require: @p td non-null
|
||||
**/
|
||||
static TypeRef resolved(TypeDescr td);
|
||||
|
||||
/** if @p td is non-null
|
||||
* -> type is already resolved
|
||||
*
|
||||
|
|
@ -43,7 +48,10 @@ namespace xo {
|
|||
TypeDescr td() const noexcept { return td_; }
|
||||
|
||||
/** true iff type at this location has been resolved **/
|
||||
bool is_concrete() const noexcept;
|
||||
bool is_resolved() const noexcept;
|
||||
|
||||
/** resolve TypeRef by supplying final type-description **/
|
||||
void resolve(TypeDescr td) noexcept { td_ = td; }
|
||||
|
||||
private:
|
||||
/** unique (probably generated) name for type at this location **/
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
@ -15,6 +15,8 @@
|
|||
|
||||
// includes (via {facet_includes})
|
||||
#include "TypeRef.hpp"
|
||||
#include "exprtype.hpp"
|
||||
#include <xo/reflect/TypeDescr.hpp>
|
||||
#include <xo/facet/obj.hpp>
|
||||
#include <xo/facet/facet_implementation.hpp>
|
||||
#include <xo/facet/typeseq.hpp>
|
||||
|
|
@ -35,6 +37,8 @@ public:
|
|||
// types
|
||||
/** integer identifying a type **/
|
||||
using typeseq = xo::facet::typeseq;
|
||||
/** struct describing a type **/
|
||||
using TypeDescr = xo::reflect::TypeDescr;
|
||||
///@}
|
||||
|
||||
/** @defgroup scm-expression-methods **/
|
||||
|
|
@ -42,6 +46,8 @@ public:
|
|||
// const methods
|
||||
/** RTTI: unique id# for actual runtime data representation **/
|
||||
virtual typeseq _typeseq() const noexcept = 0;
|
||||
/** expression type (constant | apply | ..) **/
|
||||
virtual exprtype extype(Copaque data) const noexcept = 0;
|
||||
/** placeholder for type giving possible values for this expression **/
|
||||
virtual TypeRef typeref(Copaque data) const noexcept = 0;
|
||||
/** type giving possible values for this expression. Maybe null before typecheck **/
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
@ -44,6 +44,7 @@ namespace scm {
|
|||
|
||||
/** integer identifying a type **/
|
||||
using typeseq = xo::facet::typeseq;
|
||||
using TypeDescr = AExpression::TypeDescr;
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-expression-any-methods **/
|
||||
|
|
@ -55,6 +56,7 @@ namespace scm {
|
|||
|
||||
// const methods
|
||||
typeseq _typeseq() const noexcept override { return s_typeseq; }
|
||||
[[noreturn]] exprtype extype(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] TypeRef typeref(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] TypeDescr valuetype(Copaque) const noexcept override { _fatal(); }
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
@ -14,6 +14,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "TypeRef.hpp"
|
||||
#include "exprtype.hpp"
|
||||
#include <xo/reflect/TypeDescr.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
|
@ -28,6 +30,7 @@ namespace scm {
|
|||
using Impl = IExpression_DRepr;
|
||||
/** integer identifying a type **/
|
||||
using typeseq = AExpression::typeseq;
|
||||
using TypeDescr = AExpression::TypeDescr;
|
||||
///@}
|
||||
|
||||
/** @defgroup scm-expression-xfer-methods **/
|
||||
|
|
@ -40,6 +43,9 @@ namespace scm {
|
|||
|
||||
// const methods
|
||||
typeseq _typeseq() const noexcept override { return s_typeseq; }
|
||||
exprtype extype(Copaque data) const noexcept override {
|
||||
return I::extype(_dcast(data));
|
||||
}
|
||||
TypeRef typeref(Copaque data) const noexcept override {
|
||||
return I::typeref(_dcast(data));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
@ -31,6 +31,7 @@ public:
|
|||
using ObjectType = Object;
|
||||
using DataPtr = Object::DataPtr;
|
||||
using typeseq = xo::reflect::typeseq;
|
||||
using TypeDescr = AExpression::TypeDescr;
|
||||
///@}
|
||||
|
||||
/** @defgroup scm-expression-router-ctors **/
|
||||
|
|
@ -44,10 +45,13 @@ public:
|
|||
|
||||
// const methods
|
||||
typeseq _typeseq() const noexcept { return O::iface()->_typeseq(); }
|
||||
TypeRef typeref() const noexcept override {
|
||||
exprtype extype() const noexcept {
|
||||
return O::iface()->extype(O::data());
|
||||
}
|
||||
TypeRef typeref() const noexcept {
|
||||
return O::iface()->typeref(O::data());
|
||||
}
|
||||
TypeDescr valuetype() const noexcept override {
|
||||
TypeDescr valuetype() const noexcept {
|
||||
return O::iface()->valuetype(O::data());
|
||||
}
|
||||
|
||||
|
|
|
|||
84
include/xo/expression2/exprtype.hpp
Normal file
84
include/xo/expression2/exprtype.hpp
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/** @file exprtype.hpp
|
||||
*
|
||||
* Author: Roland Conybeare
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ostream>
|
||||
//#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @enum exprtype
|
||||
* @brief enum to identify subclasses of xo::scm::Expression.
|
||||
*
|
||||
**/
|
||||
enum class exprtype {
|
||||
/** sentinel value **/
|
||||
invalid = -1,
|
||||
|
||||
/** literal constant. must satisfy both standard_layout_type + trivial **/
|
||||
constant,
|
||||
#ifdef NOT_YET
|
||||
/** a literal constant that refers to a linkable named function **/
|
||||
primitive,
|
||||
/** variable/function definition **/
|
||||
define,
|
||||
/** variable assignment **/
|
||||
assign,
|
||||
/** function call **/
|
||||
apply,
|
||||
/** function definition **/
|
||||
lambda,
|
||||
/** variable reference **/
|
||||
variable,
|
||||
/** if-then-else **/
|
||||
ifexpr,
|
||||
/** sequence **/
|
||||
sequence,
|
||||
/** type conversion **/
|
||||
convert,
|
||||
#endif
|
||||
|
||||
/** not an expression. comes last, counts entries **/
|
||||
N
|
||||
};
|
||||
|
||||
inline const char *
|
||||
expr2str(exprtype x)
|
||||
{
|
||||
switch(x) {
|
||||
case exprtype::invalid: return "?exprtype";
|
||||
case exprtype::constant: return "constant";
|
||||
#ifdef NOT_YET
|
||||
case exprtype::primitive: return "primitive";
|
||||
case exprtype::define: return "define";
|
||||
case exprtype::assign: return "assign";
|
||||
case exprtype::apply: return "apply";
|
||||
case exprtype::lambda: return "lambda";
|
||||
case exprtype::variable: return "variable";
|
||||
case exprtype::ifexpr: return "if_expr";
|
||||
case exprtype::sequence: return "sequence";
|
||||
case exprtype::convert: return "convert";
|
||||
#endif
|
||||
default: break;
|
||||
}
|
||||
|
||||
return "???exprtype???";
|
||||
}
|
||||
|
||||
/** @brief number of built-in expression types, repr convenient for array sizing **/
|
||||
static constexpr std::size_t n_exprtype = static_cast<std::size_t>(exprtype::N);
|
||||
|
||||
inline std::ostream &
|
||||
operator<<(std::ostream & os,
|
||||
exprtype x)
|
||||
{
|
||||
os << expr2str(x);
|
||||
return os;
|
||||
}
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end exprtype.hpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue