xo-expression2 xo-reader2: local symtab stack in PSM
This commit is contained in:
parent
a26b781101
commit
d953246acd
18 changed files with 319 additions and 12 deletions
|
|
@ -34,6 +34,30 @@ xo_add_genfacet(
|
|||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-expression2-facetimpl-symboltable-localsymtab
|
||||
FACET_PKG xo_expression2
|
||||
FACET SymbolTable
|
||||
REPR LocalSymtab
|
||||
INPUT idl/ISymbolTable_DLocalSymtab.json5
|
||||
OUTPUT_HPP_DIR include/xo/expression2
|
||||
OUTPUT_IMPL_SUBDIR symtab
|
||||
OUTPUT_CPP_DIR src/expression2
|
||||
)
|
||||
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-expression2-facetimpl-printable-localsymtab
|
||||
FACET_PKG xo_printable2
|
||||
FACET Printable
|
||||
REPR LocalSymtab
|
||||
INPUT idl/IPrintable_DLocalSymtab.json5
|
||||
OUTPUT_HPP_DIR include/xo/expression2
|
||||
OUTPUT_IMPL_SUBDIR symtab
|
||||
OUTPUT_CPP_DIR src/expression2
|
||||
)
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacet(
|
||||
TARGET xo-expression2-facet-expression
|
||||
|
|
|
|||
13
idl/IPrintable_DLocalSymtab.json5
Normal file
13
idl/IPrintable_DLocalSymtab.json5
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
mode: "implementation",
|
||||
includes: [ "<xo/printable2/Printable.hpp>",
|
||||
"<xo/printable2/detail/IPrintable_Xfer.hpp>" ],
|
||||
local_types: [ ],
|
||||
namespace1: "xo",
|
||||
namespace2: "scm",
|
||||
facet_idl: "idl/Printable.json5",
|
||||
brief: "provide APrintable interface for DLocalSymtab",
|
||||
using_doxygen: true,
|
||||
repr: "DLocalSymtab",
|
||||
doc: [ "implement APrintable for DLocalSymtab" ],
|
||||
}
|
||||
12
idl/ISymbolTable_DLocalSymtab.json5
Normal file
12
idl/ISymbolTable_DLocalSymtab.json5
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
mode: "implementation",
|
||||
includes: [ ],
|
||||
local_types: [ ],
|
||||
namespace1: "xo",
|
||||
namespace2: "scm",
|
||||
facet_idl: "idl/SymbolTable.json5",
|
||||
brief: "provide ASymbolTable interface for DLocalSymtab",
|
||||
using_doxygen: true,
|
||||
repr: "DLocalSymtab",
|
||||
doc: [ "implement ASymbolTable for DLocalSymtab" ],
|
||||
}
|
||||
|
|
@ -25,6 +25,7 @@ namespace xo {
|
|||
static Binding local(int32_t j_slot) { return Binding(0, j_slot); }
|
||||
|
||||
bool is_global() const { return i_link_ == s_link_global; }
|
||||
bool is_local() const { return (i_link_ == 0) && (j_slot_ >= 0); }
|
||||
|
||||
int32_t i_link() const noexcept { return i_link_; }
|
||||
int32_t j_slot() const noexcept { return j_slot_; }
|
||||
|
|
|
|||
|
|
@ -45,20 +45,23 @@ namespace xo {
|
|||
/** @defgroup scm-lambdaexpr-constructors **/
|
||||
///@{
|
||||
|
||||
/** empty instance with capacity for n slots.
|
||||
/** empty instance with parent @p p and capacity for @p n slots.
|
||||
* Caller must ensure that slots_[0..n) are actually addressable
|
||||
**/
|
||||
DLocalSymtab(size_type n);
|
||||
DLocalSymtab(DLocalSymtab * p, size_type n);
|
||||
|
||||
/** scaffold empty symtab instance,
|
||||
* with capacity for @p n slots, using memory from allocator @p mm
|
||||
**/
|
||||
static DLocalSymtab * _make_empty(obj<AAllocator> mm, size_type n);
|
||||
static DLocalSymtab * _make_empty(obj<AAllocator> mm,
|
||||
DLocalSymtab * p,
|
||||
size_type n);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-lambdaexpr-methods **/
|
||||
///@{
|
||||
|
||||
DLocalSymtab * parent() const noexcept { return parent_; }
|
||||
size_type capacity() const noexcept { return capacity_; }
|
||||
size_type size() const noexcept { return size_; }
|
||||
|
||||
|
|
@ -96,6 +99,8 @@ namespace xo {
|
|||
///@}
|
||||
|
||||
private:
|
||||
/** parent symbol table from scoping surrounding this one **/
|
||||
DLocalSymtab * parent_ = nullptr;
|
||||
/** actual range of slots_[] array. Can use inices in [0,..,n) **/
|
||||
size_type capacity_ = 0;
|
||||
/** number of slots in use **/
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IExpression_DIfElseExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IGCObject_DVariable.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DIfElseExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
62
include/xo/expression2/symtab/IPrintable_DLocalSymtab.hpp
Normal file
62
include/xo/expression2/symtab/IPrintable_DLocalSymtab.hpp
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/** @file IPrintable_DLocalSymtab.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DLocalSymtab.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DLocalSymtab.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Printable.hpp"
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
|
||||
#include "DLocalSymtab.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IPrintable_DLocalSymtab; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::print::APrintable,
|
||||
xo::scm::DLocalSymtab>
|
||||
{
|
||||
using ImplType = xo::print::IPrintable_Xfer
|
||||
<xo::scm::DLocalSymtab,
|
||||
xo::scm::IPrintable_DLocalSymtab>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IPrintable_DLocalSymtab
|
||||
**/
|
||||
class IPrintable_DLocalSymtab {
|
||||
public:
|
||||
/** @defgroup scm-printable-dlocalsymtab-type-traits **/
|
||||
///@{
|
||||
using ppindentinfo = xo::print::APrintable::ppindentinfo;
|
||||
using Copaque = xo::print::APrintable::Copaque;
|
||||
using Opaque = xo::print::APrintable::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-printable-dlocalsymtab-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** Pretty-printing support for this object.
|
||||
See [xo-indentlog/xo/indentlog/pretty.hpp] **/
|
||||
static bool pretty(const DLocalSymtab & self, const ppindentinfo & ppii);
|
||||
|
||||
// non-const methods
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
60
include/xo/expression2/symtab/ISymbolTable_DLocalSymtab.hpp
Normal file
60
include/xo/expression2/symtab/ISymbolTable_DLocalSymtab.hpp
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/** @file ISymbolTable_DLocalSymtab.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/ISymbolTable_DLocalSymtab.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/ISymbolTable_DLocalSymtab.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SymbolTable.hpp"
|
||||
#include "DLocalSymtab.hpp"
|
||||
|
||||
namespace xo { namespace scm { class ISymbolTable_DLocalSymtab; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::scm::ASymbolTable,
|
||||
xo::scm::DLocalSymtab>
|
||||
{
|
||||
using ImplType = xo::scm::ISymbolTable_Xfer
|
||||
<xo::scm::DLocalSymtab,
|
||||
xo::scm::ISymbolTable_DLocalSymtab>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class ISymbolTable_DLocalSymtab
|
||||
**/
|
||||
class ISymbolTable_DLocalSymtab {
|
||||
public:
|
||||
/** @defgroup scm-symboltable-dlocalsymtab-type-traits **/
|
||||
///@{
|
||||
using Copaque = xo::scm::ASymbolTable::Copaque;
|
||||
using Opaque = xo::scm::ASymbolTable::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-symboltable-dlocalsymtab-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** true iff this is toplevel (global) symbol table. **/
|
||||
static bool is_global_symtab(const DLocalSymtab & self) noexcept;
|
||||
/** report ingredients needed to address variable at runtime. **/
|
||||
static Binding lookup_binding(const DLocalSymtab & self, const DUniqueString * sym) noexcept;
|
||||
|
||||
// non-const methods
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -39,6 +39,9 @@ set(SELF_SRCS
|
|||
|
||||
ISymbolTable_Any.cpp
|
||||
|
||||
ISymbolTable_DLocalSymtab.cpp
|
||||
IPrintable_DLocalSymtab.cpp
|
||||
|
||||
StringTable.cpp
|
||||
|
||||
DUniqueString.cpp
|
||||
|
|
|
|||
|
|
@ -5,14 +5,21 @@
|
|||
|
||||
#include "DLocalSymtab.hpp"
|
||||
#include "DUniqueString.hpp"
|
||||
#include <xo/expression2/detail/IPrintable_DVariable.hpp>
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/indentlog/scope.hpp>
|
||||
|
||||
namespace xo {
|
||||
using xo::print::APrintable;
|
||||
using xo::facet::typeseq;
|
||||
using xo::print::ppstate;
|
||||
|
||||
namespace scm {
|
||||
|
||||
DLocalSymtab::DLocalSymtab(size_type n) : capacity_{n}, size_{0}
|
||||
DLocalSymtab::DLocalSymtab(DLocalSymtab * p,
|
||||
size_type n) : parent_{p},
|
||||
capacity_{n},
|
||||
size_{0}
|
||||
{
|
||||
for (size_type i = 0; i < n; ++i) {
|
||||
void * mem = &slots_[i];
|
||||
|
|
@ -21,12 +28,14 @@ namespace xo {
|
|||
}
|
||||
|
||||
DLocalSymtab *
|
||||
DLocalSymtab::_make_empty(obj<AAllocator> mm, size_type n)
|
||||
DLocalSymtab::_make_empty(obj<AAllocator> mm,
|
||||
DLocalSymtab * p,
|
||||
size_type n)
|
||||
{
|
||||
void * mem = mm.alloc(typeseq::id<DLocalSymtab>(),
|
||||
sizeof(DLocalSymtab) + (n * sizeof(Slot)));
|
||||
|
||||
return new (mem) DLocalSymtab(n);
|
||||
return new (mem) DLocalSymtab(p, n);
|
||||
}
|
||||
|
||||
Binding
|
||||
|
|
@ -68,6 +77,53 @@ namespace xo {
|
|||
return Binding();
|
||||
}
|
||||
|
||||
bool
|
||||
DLocalSymtab::pretty(const ppindentinfo & ppii) const
|
||||
{
|
||||
ppstate * pps = ppii.pps();
|
||||
|
||||
if (ppii.upto()) {
|
||||
/* perhaps print on one line */
|
||||
if (!pps->print_upto("<LocalSymtab"))
|
||||
return false;
|
||||
if (!pps->print_upto(xrefrtag("size", size_)))
|
||||
return false;
|
||||
|
||||
for (size_type i = 0; i < size_; ++i) {
|
||||
char buf[32];
|
||||
snprintf(buf, sizeof(buf), "[%u]", i);
|
||||
|
||||
assert(slots_[i].var_);
|
||||
|
||||
obj<APrintable,DVariable> arg_pr(const_cast<DVariable*>(slots_[i].var_));
|
||||
|
||||
if (!pps->print_upto(xrefrtag(buf, arg_pr)))
|
||||
return false;
|
||||
}
|
||||
|
||||
pps->write(">");
|
||||
return true;
|
||||
} else {
|
||||
/* with line breaks */
|
||||
|
||||
pps->write("<LocalSymtab");
|
||||
pps->newline_pretty_tag(ppii.ci1(), "size", size_);
|
||||
|
||||
for (size_type i = 0; i < size_; ++i) {
|
||||
char buf[32];
|
||||
snprintf(buf, sizeof(buf), "[%u]", i);
|
||||
|
||||
assert(slots_[i].var_);
|
||||
|
||||
obj<APrintable,DVariable> arg_pr(const_cast<DVariable *>(slots_[i].var_));
|
||||
|
||||
pps->newline_pretty_tag(ppii.ci1(), buf, arg_pr);
|
||||
}
|
||||
|
||||
pps->write(">");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IExpression_DIfElseExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IGCObject_DVariable.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DIfElseExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
|
|
|
|||
28
src/expression2/IPrintable_DLocalSymtab.cpp
Normal file
28
src/expression2/IPrintable_DLocalSymtab.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/** @file IPrintable_DLocalSymtab.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DLocalSymtab.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DLocalSymtab.json5]
|
||||
**/
|
||||
|
||||
#include "symtab/IPrintable_DLocalSymtab.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IPrintable_DLocalSymtab::pretty(const DLocalSymtab & self, const ppindentinfo & ppii) -> bool
|
||||
{
|
||||
return self.pretty(ppii);
|
||||
}
|
||||
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IPrintable_DLocalSymtab.cpp */
|
||||
34
src/expression2/ISymbolTable_DLocalSymtab.cpp
Normal file
34
src/expression2/ISymbolTable_DLocalSymtab.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/** @file ISymbolTable_DLocalSymtab.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/ISymbolTable_DLocalSymtab.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/ISymbolTable_DLocalSymtab.json5]
|
||||
**/
|
||||
|
||||
#include "symtab/ISymbolTable_DLocalSymtab.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
ISymbolTable_DLocalSymtab::is_global_symtab(const DLocalSymtab & self) noexcept -> bool
|
||||
{
|
||||
return self.is_global_symtab();
|
||||
}
|
||||
|
||||
auto
|
||||
ISymbolTable_DLocalSymtab::lookup_binding(const DLocalSymtab & self, const DUniqueString * sym) noexcept -> Binding
|
||||
{
|
||||
return self.lookup_binding(sym);
|
||||
}
|
||||
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end ISymbolTable_DLocalSymtab.cpp */
|
||||
|
|
@ -27,6 +27,9 @@
|
|||
#include <xo/expression2/detail/IExpression_DIfElseExpr.hpp>
|
||||
#include <xo/expression2/detail/IPrintable_DIfElseExpr.hpp>
|
||||
|
||||
#include <xo/expression2/symtab/ISymbolTable_DLocalSymtab.hpp>
|
||||
#include <xo/expression2/symtab/IPrintable_DLocalSymtab.hpp>
|
||||
|
||||
#include <xo/gc/detail/AGCObject.hpp>
|
||||
#include <xo/printable2/detail/APrintable.hpp>
|
||||
#include <xo/facet/FacetRegistry.hpp>
|
||||
|
|
@ -74,6 +77,9 @@ namespace xo {
|
|||
FacetRegistry::register_impl<AExpression, DIfElseExpr>();
|
||||
FacetRegistry::register_impl<APrintable, DIfElseExpr>();
|
||||
|
||||
FacetRegistry::register_impl<ASymbolTable, DLocalSymtab>();
|
||||
FacetRegistry::register_impl<APrintable, DLocalSymtab>();
|
||||
|
||||
log && log(xtag("DUniqueString.tseq", typeseq::id<DUniqueString>()));
|
||||
log && log(xtag("DDefineExpr.tseq", typeseq::id<DDefineExpr>()));
|
||||
log && log(xtag("DVariable.tseq", typeseq::id<DVariable>()));
|
||||
|
|
@ -82,7 +88,10 @@ namespace xo {
|
|||
log && log(xtag("DLambdaExpr.tseq", typeseq::id<DLambdaExpr>()));
|
||||
log && log(xtag("DIfElseExpr.tseq", typeseq::id<DIfElseExpr>()));
|
||||
|
||||
log && log(xtag("DLocalSymtab.tseq", typeseq::id<DLocalSymtab>()));
|
||||
|
||||
log && log(xtag("AExpression.tqseq", typeseq::id<AExpression>()));
|
||||
log && log(xtag("ASymbolTable.tseq", typeseq::id<ASymbolTable>()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue