xo-expression2 stack: + mvp DGlobalSymtab impl

This commit is contained in:
Roland Conybeare 2026-02-14 13:06:54 -05:00
commit 017a7a092c
4 changed files with 116 additions and 5 deletions

View file

@ -12,6 +12,8 @@ namespace xo {
namespace scm {
class Binding {
public:
using slot_type = int32_t;
static constexpr int32_t c_link_sentinel = -2;
static constexpr int32_t c_link_global = -1;
@ -22,7 +24,7 @@ namespace xo {
static Binding null() { return Binding(); }
/** global bindings are located by symbol name **/
static Binding global() { return Binding(c_link_global, 0); }
static Binding global(int32_t j_slot) { return Binding(c_link_global, j_slot); }
static Binding local(int32_t j_slot) { return Binding(0, j_slot); }
static Binding relative(int32_t i_link, Binding def);

View file

@ -6,6 +6,8 @@
#pragma once
#include "Binding.hpp"
#include "DVariable.hpp"
#include <xo/object2/DArray.hpp>
#include <xo/arena/DArenaHashMap.hpp>
namespace xo {
@ -23,7 +25,8 @@ namespace xo {
public:
using key_type = const DUniqueString *;
using value_type = Binding;
using repr_type = xo::map::DArenaHashMap<key_type, value_type>;
using repr_type = xo::map::DArenaHashMap<key_type, Binding::slot_type>;
using AAllocator = xo::mm::AAllocator;
using MemorySizeVisitor = xo::mm::MemorySizeVisitor;
public:
@ -31,6 +34,17 @@ namespace xo {
void visit_pools(const MemorySizeVisitor & visitor) const;
public:
/** lookup global symbol with name @p sym **/
DVariable * lookup_variable(const DUniqueString * sym) const noexcept;
/** establish binding for @p sym, with type described by @p typeref,
* replacing existing global (if present) with the same name.
* Use memory from @p mm to create variable-expr
**/
DVariable * establish_variable(obj<AAllocator> mm,
const DUniqueString * sym,
TypeRef typeref);
/** @defgroup xo-expression2-symboltable-facet symboltable facet**/
///@{
@ -49,6 +63,13 @@ namespace xo {
/** map symbols -> bindings **/
repr_type map_;
/** array of variables.
* When S is a unique-string for a global symbol, then:
* 1. map_[S] is unique global index i(S) for S.
* 2. vars_[i(S)] is variable-expr var(S) for S
* 3. var(S)->name == S
**/
DArray * vars_ = nullptr;
};
} /*namespace scm*/

View file

@ -73,7 +73,7 @@ namespace xo {
return slots_[ix.j_slot()].var_;
}
/** increase slot size (provided beleow capacity) to append
/** increase slot size (provided below capacity) to append
* binding for one local variable. Local variable will be allocated
* from @p mm, named @p name, with type described by @p typeref.
**/