From d6b29241fdabb648ccd446d2abb7391eabe5d396 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sat, 17 Jan 2026 01:10:33 -0500 Subject: [PATCH] xo-expression2: + Binding etc --- include/xo/expression2/Binding.hpp | 46 ++++++++++++++++++++++++ include/xo/expression2/DUniqueString.hpp | 2 +- include/xo/expression2/TypeRef.hpp | 3 +- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 include/xo/expression2/Binding.hpp diff --git a/include/xo/expression2/Binding.hpp b/include/xo/expression2/Binding.hpp new file mode 100644 index 00000000..455c1538 --- /dev/null +++ b/include/xo/expression2/Binding.hpp @@ -0,0 +1,46 @@ +/** @file Binding.hpp + * + * @author Roland Conybeare, Jan 2026 + **/ + +#pragma once + +#include + +namespace xo { + namespace scm { + class Binding { + public: + static constexpr int32_t s_link_sentinel = -2; + static constexpr int32_t s_link_global = -1; + + public: + Binding(int32_t i_link, int32_t j_slot) + : i_link_{i_link}, j_slot_{j_slot} {} + + /** global bindings are located by symbol name **/ + static Binding global() { return Binding(s_link_global, 0); } + static Binding local(int32_t j_slot) { return Binding(0, j_slot); } + + bool is_global() const { return i_link_ == s_link_global; } + + int32_t i_link() const noexcept { return i_link_; } + int32_t j_slot() const noexcept { return j_slot_; } + + private: + /** + * >= 0: number of parent links to traverse + * to a fixed-size frame + * -1: resolve globally + **/ + int32_t i_link_ = s_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; + }; + } /*namespace scm*/ +} /*namespace xo*/ + +/* Binding.hpp */ diff --git a/include/xo/expression2/DUniqueString.hpp b/include/xo/expression2/DUniqueString.hpp index 08fcde86..30655b45 100644 --- a/include/xo/expression2/DUniqueString.hpp +++ b/include/xo/expression2/DUniqueString.hpp @@ -40,7 +40,7 @@ namespace xo { * * Legend * header 8 byte allocation header - * u 1 byte DUniqueString placholder (c++ insists) + * u 1 byte DUniqueString placeholder (c++ insists) * padding 7 bytes allocator-imposed padding to 8-byte alignment * cap 4 bytes DString.capacity * size 4 bytes DString.size diff --git a/include/xo/expression2/TypeRef.hpp b/include/xo/expression2/TypeRef.hpp index cd789d23..01401d28 100644 --- a/include/xo/expression2/TypeRef.hpp +++ b/include/xo/expression2/TypeRef.hpp @@ -11,7 +11,8 @@ namespace xo { namespace scm { /** @class TypeRef - * @brief name and (when established) resolution for type associate with an expression + * @brief name and (when established) resolution for type + * associated with an expression * * Type inference / unification operates on * @ref xo::scm::TypeBlueprint instances. See also!