xo-expression2: + LambdaExpr ++ LocalSymtab
This commit is contained in:
parent
a69023096d
commit
666482a945
15 changed files with 621 additions and 9 deletions
|
|
@ -6,6 +6,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "Binding.hpp"
|
||||
#include "DVariable.hpp"
|
||||
#include "DUniqueString.hpp"
|
||||
//#include "exprtype.hpp"
|
||||
//#include <xo/reflect/TaggedPtr.hpp>
|
||||
|
|
@ -23,15 +24,61 @@ namespace xo {
|
|||
// using AGCObject = xo::mm::AGCObject;
|
||||
// using typeseq = xo::reflect::typeseq;
|
||||
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
/* note: uint16_t would be fine too */
|
||||
using size_type = std::uint32_t;
|
||||
|
||||
struct Slot {
|
||||
// obj<Expression,DVariable> var_;
|
||||
Binding binding_;
|
||||
Slot() = default;
|
||||
explicit Slot(const DVariable * var) : var_{var} {}
|
||||
|
||||
/** variable representing a formal argument.
|
||||
* binding will be correct only within the same layer
|
||||
* as top-level lambda body
|
||||
* (i.e. up to the doorstep of each and every nested lambda)
|
||||
**/
|
||||
const DVariable * var_ = nullptr;
|
||||
};
|
||||
|
||||
public:
|
||||
// explicit DLocalSymtab(obj<AGCObject> value) noexcept;
|
||||
/** @defgroup scm-lambdaexpr-constructors **/
|
||||
///@{
|
||||
|
||||
/** @defgroup xo-expression2-symboltable-facet symboltable facet**/
|
||||
/** empty instance with capacity for n slots.
|
||||
* Caller must ensure that slots_[0..n) are actually addressable
|
||||
**/
|
||||
DLocalSymtab(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);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-lambdaexpr-methods **/
|
||||
///@{
|
||||
|
||||
size_type capacity() const noexcept { return capacity_; }
|
||||
size_type size() const noexcept { return size_; }
|
||||
|
||||
const DVariable * lookup_var(Binding ix) const noexcept {
|
||||
assert(ix.i_link() == 0);
|
||||
assert(ix.j_slot() < static_cast<int32_t>(size_));
|
||||
|
||||
return slots_[ix.j_slot()].var_;
|
||||
}
|
||||
|
||||
/** increase slot size (provided beleow 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.
|
||||
**/
|
||||
Binding append_var(obj<AAllocator> mm,
|
||||
const DUniqueString * name,
|
||||
TypeRef typeref);
|
||||
|
||||
///@}
|
||||
/** @defgroup xo-localsymtab-symboltable-facet symboltable facet**/
|
||||
///@{
|
||||
|
||||
/** true for global symbol table **/
|
||||
|
|
@ -41,9 +88,20 @@ namespace xo {
|
|||
Binding lookup_binding(const DUniqueString * sym) const noexcept;
|
||||
|
||||
///@}
|
||||
/** @defgroup xo-localsymtab-printable-facet printable facet **/
|
||||
///@{
|
||||
|
||||
bool pretty(const ppindentinfo & ppii) const;
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
|
||||
/** actual range of slots_[] array. Can use inices in [0,..,n) **/
|
||||
size_type capacity_ = 0;
|
||||
/** number of slots in use **/
|
||||
size_type size_ = 0;
|
||||
/** memory for names and bindings **/
|
||||
Slot slots_[];
|
||||
};
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue