diff --git a/include/xo/reader2/ParserStateMachine.hpp b/include/xo/reader2/ParserStateMachine.hpp index 4f14f72a..a7726c35 100644 --- a/include/xo/reader2/ParserStateMachine.hpp +++ b/include/xo/reader2/ParserStateMachine.hpp @@ -90,6 +90,7 @@ namespace xo { obj expr_alloc() const noexcept { return expr_alloc_; } DGlobalSymtab * global_symtab() const noexcept { return global_symtab_.data(); } DLocalSymtab * local_symtab() const noexcept { return local_symtab_; } + DGlobalEnv * global_env() const noexcept { return global_env_.data(); } const ParserResult & result() const noexcept { return result_; } /** polymoprhihc multiply primitive. Use to implement infix op* **/ diff --git a/include/xo/reader2/SchematikaParser.hpp b/include/xo/reader2/SchematikaParser.hpp index ce7b3335..dd6ae341 100644 --- a/include/xo/reader2/SchematikaParser.hpp +++ b/include/xo/reader2/SchematikaParser.hpp @@ -184,6 +184,7 @@ namespace xo { ///@{ DGlobalSymtab * global_symtab() const noexcept; + DGlobalEnv * global_env() const noexcept; bool debug_flag() const { return debug_flag_; } diff --git a/include/xo/reader2/SchematikaReader.hpp b/include/xo/reader2/SchematikaReader.hpp index 5d20226e..0761b6e3 100644 --- a/include/xo/reader2/SchematikaReader.hpp +++ b/include/xo/reader2/SchematikaReader.hpp @@ -57,6 +57,9 @@ namespace xo { /** top-level symbol table **/ DGlobalSymtab * global_symtab() const noexcept; + /** top-level global environment (e.g. contains built-in primitives) **/ + DGlobalEnv * global_env() const noexcept; + /** visit reader-owned memory pools; call visitor(info) for each. * Specifically exclude expr_alloc, since we don't consider * that reader-owned diff --git a/src/reader2/ParserStateMachine.cpp b/src/reader2/ParserStateMachine.cpp index 0634a564..5e6b4164 100644 --- a/src/reader2/ParserStateMachine.cpp +++ b/src/reader2/ParserStateMachine.cpp @@ -41,19 +41,17 @@ namespace xo { DGlobalSymtab * global_symtab, InstallFlags pm_install_flags) { + scope log(XO_DEBUG(true)); + DGlobalEnv * env = DGlobalEnv::_make(mm, global_symtab); - InstallSink sink = ([env, mm, &stringtable] + InstallSink sink = ([env, mm, &stringtable, &log] (std::string_view name, TypeDescr fn_td, obj pm, InstallFlags flags) { - scope log(XO_DEBUG(false)); - - log && log(xtag("name", name)); - (void)flags; obj pm_gco = pm.to_facet(); @@ -61,6 +59,8 @@ namespace xo { const DUniqueString * sym = stringtable.intern(name); + log && log("upsert", xtag("sym", std::string_view(*sym))); + env->_upsert_value(mm, sym, fn_td, diff --git a/src/reader2/SchematikaParser.cpp b/src/reader2/SchematikaParser.cpp index acfbeaa1..7d27e41c 100644 --- a/src/reader2/SchematikaParser.cpp +++ b/src/reader2/SchematikaParser.cpp @@ -42,6 +42,12 @@ namespace xo { return psm_.global_symtab(); } + DGlobalEnv * + SchematikaParser::global_env() const noexcept + { + return psm_.global_env(); + } + bool SchematikaParser::is_at_toplevel() const { diff --git a/src/reader2/SchematikaReader.cpp b/src/reader2/SchematikaReader.cpp index 98ef2292..de815f97 100644 --- a/src/reader2/SchematikaReader.cpp +++ b/src/reader2/SchematikaReader.cpp @@ -32,6 +32,12 @@ namespace xo { return parser_.global_symtab(); } + DGlobalEnv * + SchematikaReader::global_env() const noexcept + { + return parser_.global_env(); + } + void SchematikaReader::visit_pools(const MemorySizeVisitor & visitor) const {