xo-reader2 stack: expand symbol table to store typedefs

+ typedef utest
+ misc qol policy choices
This commit is contained in:
Roland Conybeare 2026-03-11 07:49:14 -05:00
commit 5a141e09ac
29 changed files with 841 additions and 150 deletions

View file

@ -7,6 +7,7 @@
#include "Binding.hpp"
#include "DVariable.hpp"
#include "DTypename.hpp"
#include <xo/object2/DArray.hpp>
#include <xo/alloc2/dp.hpp>
#include <xo/arena/DArenaHashMap.hpp>
@ -38,16 +39,18 @@ namespace xo {
/** @defgroup scm-globalsymtab-ctors constructors **/
///@{
DGlobalSymtab(dp<repr_type> map, DArray * vars);
DGlobalSymtab(dp<repr_type> var_map, DArray * vars,
dp<repr_type> type_map, DArray * types);
/** create instance.
* Use memory from @p fixed_mm for @ref map_.
* Use memory from @p mm for DGlobalSymtab instance.
* Hashmap configured per @p cfg.
* Hashmap for variables per @p var_cfg; for types per @p type_cfg.
**/
static dp<DGlobalSymtab> make(obj<AAllocator> mm,
obj<AAllocator> fixed_mm,
const ArenaHashMapConfig & cfg);
const ArenaHashMapConfig & var_cfg,
const ArenaHashMapConfig & type_cfg);
/** non-trivial destructor for @ref map_ **/
~DGlobalSymtab() = default;
@ -56,8 +59,8 @@ namespace xo {
/** @defgroup scm-globalsymtab-access-methods access methods **/
///@{
size_type size() const noexcept { return map_->size(); }
size_type capacity() const noexcept { return map_->capacity(); }
size_type n_vars() const noexcept { return var_map_->size(); }
size_type var_capacity() const noexcept { return var_map_->capacity(); }
/** visit symtab-owned memory pools; call visitor(info) for each **/
void visit_pools(const MemorySizeVisitor & visitor) const;
@ -65,6 +68,9 @@ namespace xo {
/** lookup global symbol with name @p sym **/
DVariable * lookup_variable(const DUniqueString * sym) const noexcept;
/** lookup global typename with name @p sym **/
DTypename * lookup_typename(const DUniqueString * sym) const noexcept;
///@}
/** @defgroup scm-globalsymtab-general-methods general methods **/
///@{
@ -76,6 +82,13 @@ namespace xo {
void upsert_variable(obj<AAllocator> mm,
DVariable * var);
/** update this symtab to associate typename @p type with @c type->name().
* If there was a previous type with the same name, replace it with
* @p type.
**/
void upsert_typename(obj<AAllocator> mm,
DTypename * type);
///@}
/** @defgroup scm-globalsymtab-symboltable-facet symboltable facet **/
///@{
@ -104,20 +117,31 @@ namespace xo {
///@}
private:
/** map symbols -> bindings.
* Minor point: storing offsets instead of Variables allows us to omit
* iterating over map elements during GC. Possible savings if map_ slots
* sparsely populated.
/** map variable symbol -> index into @ref vars_.
* Minor point: storing offsets instead of Variables allows us to:
* omit hash-map iteration during GC.
* Savings when map_ slots sparsely populated.
**/
dp<repr_type> map_;
dp<repr_type> var_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.
* 1. var_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;
/** map type name -> index values into @ref types_ **/
dp<repr_type> type_map_;
/** array of types.
* When T is a unique-string for a globally-defined type, then:
* 1. type_map_[T] is unique global index i(T) for T.
* 2. types_[i(T)] is type type(T) for T
* 3. type(T)->name == T
**/
DArray * types_ = nullptr;
};
} /*namespace scm*/