xo-interpreter2: scaffold repl + alloc measurement frameowkr
This commit is contained in:
parent
eb929bb693
commit
eec85cc217
6 changed files with 89 additions and 0 deletions
|
|
@ -36,6 +36,7 @@ namespace xo {
|
|||
using AAllocator = xo::mm::AAllocator;
|
||||
using ArenaConfig = xo::mm::ArenaConfig;
|
||||
using DArena = xo::mm::DArena;
|
||||
using MemorySizeInfo = xo::mm::MemorySizeInfo;
|
||||
using size_type = std::size_t;
|
||||
|
||||
public:
|
||||
|
|
@ -61,6 +62,11 @@ namespace xo {
|
|||
/** top of parser stack **/
|
||||
obj<ASyntaxStateMachine> top_ssm() const;
|
||||
|
||||
/** number of distinct memory pools owned by PS **/
|
||||
std::size_t _n_store() const noexcept;
|
||||
/** memory consumption for i'th memory pool **/
|
||||
MemorySizeInfo _store_info(std::size_t i) const noexcept;
|
||||
|
||||
///@}
|
||||
|
||||
/** @defgroup scm-parserstatemachine-bookkeeping bookkeeping methods **/
|
||||
|
|
|
|||
|
|
@ -156,6 +156,7 @@ namespace xo {
|
|||
using token_type = Token;
|
||||
using ArenaConfig = xo::mm::ArenaConfig;
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using MemorySizeInfo = xo::mm::MemorySizeInfo;
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
using size_type = std::size_t;
|
||||
|
||||
|
|
@ -192,6 +193,11 @@ namespace xo {
|
|||
/** top of parser stack **/
|
||||
obj<ASyntaxStateMachine> top_ssm() const;
|
||||
|
||||
/** number of distinct memory pools owned by PS **/
|
||||
std::size_t _n_store() const noexcept;
|
||||
/** memory consumption for i'th memory pool **/
|
||||
MemorySizeInfo _store_info(std::size_t i) const noexcept;
|
||||
|
||||
///@}
|
||||
/** scm-schematikaparser-general-methods **/
|
||||
///@{
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ namespace xo {
|
|||
class SchematikaReader {
|
||||
public:
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using MemorySizeInfo = xo::mm::MemorySizeInfo;
|
||||
using span_type = xo::mm::span<const char>;
|
||||
using size_type = std::size_t;
|
||||
|
||||
|
|
@ -43,6 +44,9 @@ namespace xo {
|
|||
SchematikaReader(const ReaderConfig & config,
|
||||
obj<AAllocator> expr_alloc);
|
||||
|
||||
std::size_t _n_store() const noexcept;
|
||||
MemorySizeInfo _store_info(std::size_t i) const noexcept;
|
||||
|
||||
/** true iff parser is at top-level.
|
||||
* false iff parser is working on incomplete expression
|
||||
**/
|
||||
|
|
@ -53,6 +57,11 @@ namespace xo {
|
|||
**/
|
||||
void begin_interactive_session();
|
||||
|
||||
/** prepare batch session
|
||||
* (limits expression types at toplevel)
|
||||
**/
|
||||
void begin_batch_session();
|
||||
|
||||
/** consume input @p input_cstr **/
|
||||
const ReaderResult & read_expr(span_type input_span, bool eof);
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
#include <stdexcept>
|
||||
|
||||
namespace xo {
|
||||
using xo::mm::MemorySizeInfo;
|
||||
using xo::print::APrintable;
|
||||
using xo::facet::FacetRegistry;
|
||||
using xo::facet::with_facet;
|
||||
|
|
@ -53,6 +54,29 @@ namespace xo {
|
|||
return this->stack_->top();
|
||||
}
|
||||
|
||||
std::size_t
|
||||
ParserStateMachine::_n_store() const noexcept
|
||||
{
|
||||
return stringtable_._n_store() + 1;
|
||||
}
|
||||
|
||||
MemorySizeInfo
|
||||
ParserStateMachine::_store_info(std::size_t i) const noexcept
|
||||
{
|
||||
size_t n0 = stringtable_._n_store();
|
||||
|
||||
if (i < n0)
|
||||
return stringtable_._store_info(i);
|
||||
|
||||
if (i == n0)
|
||||
return parser_alloc_._store_info();
|
||||
|
||||
// not counting expr_alloc_. We don't consider
|
||||
// that to be owned by ParserStateMachine
|
||||
|
||||
return MemorySizeInfo::sentinel();
|
||||
}
|
||||
|
||||
void
|
||||
ParserStateMachine::establish_toplevel_ssm(obj<ASyntaxStateMachine> ssm)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
namespace xo {
|
||||
using xo::mm::AAllocator;
|
||||
using xo::mm::MemorySizeInfo;
|
||||
using xo::tostr;
|
||||
using xo::xtag;
|
||||
|
||||
|
|
@ -46,6 +47,18 @@ namespace xo {
|
|||
return psm_.top_ssm();
|
||||
}
|
||||
|
||||
std::size_t
|
||||
SchematikaParser::_n_store() const noexcept
|
||||
{
|
||||
return psm_._n_store();
|
||||
}
|
||||
|
||||
MemorySizeInfo
|
||||
SchematikaParser::_store_info(std::size_t i) const noexcept
|
||||
{
|
||||
return psm_._store_info(i);
|
||||
}
|
||||
|
||||
void
|
||||
SchematikaParser::begin_interactive_session()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
#include "SchematikaReader.hpp"
|
||||
|
||||
namespace xo {
|
||||
using xo::mm::MemorySizeInfo;
|
||||
|
||||
namespace scm {
|
||||
SchematikaReader::SchematikaReader(const ReaderConfig & config,
|
||||
obj<AAllocator> expr_alloc)
|
||||
|
|
@ -19,6 +21,29 @@ namespace xo {
|
|||
{
|
||||
}
|
||||
|
||||
std::size_t
|
||||
SchematikaReader::_n_store() const noexcept
|
||||
{
|
||||
return tokenizer_._n_store() + parser_._n_store();
|
||||
}
|
||||
|
||||
MemorySizeInfo
|
||||
SchematikaReader::_store_info(std::size_t i) const noexcept
|
||||
{
|
||||
size_t n_tk = tokenizer_._n_store();
|
||||
|
||||
if (i < n_tk) {
|
||||
return tokenizer_._store_info(i);
|
||||
}
|
||||
|
||||
size_t n_pr = parser_._n_store();
|
||||
|
||||
if (i < n_tk + n_pr)
|
||||
return parser_._store_info(i - n_tk);
|
||||
|
||||
return MemorySizeInfo::sentinel();
|
||||
}
|
||||
|
||||
bool
|
||||
SchematikaReader::is_at_toplevel() const noexcept
|
||||
{
|
||||
|
|
@ -31,6 +56,12 @@ namespace xo {
|
|||
parser_.begin_interactive_session();
|
||||
}
|
||||
|
||||
void
|
||||
SchematikaReader::begin_batch_session()
|
||||
{
|
||||
parser_.begin_batch_session();
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// Schematika::end_interactive_session()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue