From a23307aabb560c00955f0a7b8df81775c3cb202f Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sat, 17 Jan 2026 01:05:59 -0500 Subject: [PATCH] xo-expression2: + DVariable --- include/xo/expression2/DVariable.hpp | 56 ++++++++++++++++++++++++++++ src/expression2/CMakeLists.txt | 1 + src/expression2/DVariable.cpp | 19 ++++++++++ 3 files changed, 76 insertions(+) create mode 100644 include/xo/expression2/DVariable.hpp create mode 100644 src/expression2/DVariable.cpp diff --git a/include/xo/expression2/DVariable.hpp b/include/xo/expression2/DVariable.hpp new file mode 100644 index 00000000..036d88ce --- /dev/null +++ b/include/xo/expression2/DVariable.hpp @@ -0,0 +1,56 @@ +/** @file DVariable.hpp + * + * @author Roland Conybeare, Jan 2026 + **/ + +#pragma once + +#include "DUniqueString.hpp" +#include "Binding.hpp" +#include "TypeRef.hpp" +#include "exprtype.hpp" +#include + +namespace xo { + namespace scm { + + /** @class DVariable* + * @brief syntax for a variable reference + **/ + class DVariable { + public: + using TypeDescr = xo::reflect::TypeDescr; + + public: + DVariable(const DUniqueString & name, const TypeRef & typeref, Binding path) + : name_{name}, typeref_{typeref}, path_{path} {} + + const DUniqueString & name() const { return name_; } + Binding path() const { return path_; } + + /** @defgroup scm-variable-expression-facet**/ + ///@{ + + exprtype extype() const noexcept { return exprtype::variable; } + TypeRef typeref() const noexcept { return typeref_; } + TypeDescr valuetype() const noexcept { return typeref_.td(); }; + void assign_valuetype(TypeDescr td) noexcept; + + ///@} + + private: + /** symbol name **/ + const DUniqueString & name_; + /** variable value always has type consistent + * with this description + **/ + TypeRef typeref_; + /** at runtime: navigate environemnt via this path to get + * runtime memory location for this variable + **/ + Binding path_; + }; + } /*namespace scm*/ +} /*namespace xo*/ + +/* end DVariable.hpp */ diff --git a/src/expression2/CMakeLists.txt b/src/expression2/CMakeLists.txt index bf54ab6a..6b897535 100644 --- a/src/expression2/CMakeLists.txt +++ b/src/expression2/CMakeLists.txt @@ -4,6 +4,7 @@ set(SELF_LIB xo_expression2) set(SELF_SRCS init_expression2.cpp DConstant.cpp + DVariable.cpp TypeRef.cpp IExpression_Any.cpp IExpression_DConstant.cpp diff --git a/src/expression2/DVariable.cpp b/src/expression2/DVariable.cpp new file mode 100644 index 00000000..f589da7b --- /dev/null +++ b/src/expression2/DVariable.cpp @@ -0,0 +1,19 @@ +/** @file DVariable.cpp + * + * @author Roland Conybeare, Jan 2026 + **/ + +#include "DVariable.hpp" +#include "exprtype.hpp" + +namespace xo { + namespace scm { + void + DVariable::assign_valuetype(TypeDescr td) noexcept + { + typeref_.resolve(td); + } + } /*namespace scm*/ +} /*namespace xo*/ + +/* end DVariable.cpp */