xo-interpreter2 stack: plumbing for aux_mm and use opportunistically
This commit is contained in:
parent
6209c812d3
commit
31c6697467
12 changed files with 243 additions and 183 deletions
|
|
@ -14,7 +14,7 @@
|
|||
#include <xo/reader2/SchematikaReader.hpp>
|
||||
#include <xo/expression2/Expression.hpp>
|
||||
#include <xo/gc/GCObject.hpp>
|
||||
#include <xo/facet/box.hpp>
|
||||
#include <xo/alloc2/abox.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
|
@ -74,7 +74,12 @@ namespace xo {
|
|||
using span_type = xo::mm::span<const char>;
|
||||
|
||||
public:
|
||||
VirtualSchematikaMachine(const VsmConfig & config);
|
||||
/** @p config. configuration
|
||||
* @p aux_mm. Allocator for miscellaneous dataN
|
||||
* owned by this VSM.
|
||||
**/
|
||||
VirtualSchematikaMachine(const VsmConfig & config,
|
||||
obj<AAllocator> aux_mm);
|
||||
|
||||
/** allocator for schematika data **/
|
||||
obj<AAllocator> allocator() const noexcept;
|
||||
|
|
@ -213,10 +218,17 @@ namespace xo {
|
|||
/** configuration **/
|
||||
VsmConfig config_;
|
||||
|
||||
#ifdef NOT_YET
|
||||
/** allocator (likely DArena) for globals.
|
||||
* For example DArenaHashMap in global symtab,
|
||||
**/
|
||||
obj<AAllocator> aux_mm_;
|
||||
#endif
|
||||
|
||||
/** allocator (likely DX1Collector or similar) for
|
||||
* expressions and values
|
||||
**/
|
||||
box<AAllocator> mm_;
|
||||
abox<AAllocator> mm_;
|
||||
|
||||
/** Sidecar allocator for error reporting.
|
||||
* Separate to mitigate interference with @ref mm_
|
||||
|
|
@ -224,12 +236,12 @@ namespace xo {
|
|||
* an out-of-memory error).
|
||||
* Likely DArena or similar
|
||||
**/
|
||||
box<AAllocator> error_mm_;
|
||||
abox<AAllocator> error_mm_;
|
||||
|
||||
/** runtime context for this vsm.
|
||||
* For example, provides allocator to primitives
|
||||
**/
|
||||
box<ARuntimeContext> rcx_;
|
||||
abox<ARuntimeContext> rcx_;
|
||||
|
||||
// consider separate allocator (which _may_ turn out to be the same)
|
||||
// for VM stack. Only works for code that doesn't rely on fancy
|
||||
|
|
|
|||
|
|
@ -19,15 +19,28 @@ namespace xo {
|
|||
|
||||
VsmConfig() = default;
|
||||
|
||||
VsmConfig with_debug_flag(bool x) const {
|
||||
VsmConfig retval = *this;
|
||||
retval.debug_flag_ = x;
|
||||
return retval;
|
||||
}
|
||||
|
||||
/** true for interactive parser session; false for batch session **/
|
||||
bool interactive_flag_ = true;
|
||||
|
||||
/** true to enable logging **/
|
||||
bool debug_flag_ = false;
|
||||
|
||||
/** reader configuration **/
|
||||
ReaderConfig rdr_config_;
|
||||
/** Configuration for allocator/collector.
|
||||
* TODO: may want to make CollectorConfig polymorphic
|
||||
**/
|
||||
X1CollectorConfig x1_config_ = X1CollectorConfig().with_size(4*1024*1024);
|
||||
X1CollectorConfig x1_config_ = X1CollectorConfig().with_name("gc").with_size(4*1024*1024);
|
||||
/** Configuration for handful of non-moveable high-level objects
|
||||
* e.g. DArenaHashMap in global symtab
|
||||
**/
|
||||
ArenaConfig fixed_config_ = ArenaConfig().with_name("fixed").with_size(4*1024);
|
||||
/** Configuration for error allocator
|
||||
* TODO: may want to make ArenaConfig polymorphic
|
||||
**/
|
||||
|
|
|
|||
|
|
@ -54,16 +54,16 @@ namespace xo {
|
|||
// NOTE: using heap here for {DX1Collector, DArena, DVsmRcx} instances
|
||||
// (though DX1Collector allocations will be from explictly mmap'd memory)
|
||||
//
|
||||
VirtualSchematikaMachine::VirtualSchematikaMachine(const VsmConfig & config)
|
||||
VirtualSchematikaMachine::VirtualSchematikaMachine(const VsmConfig & config,
|
||||
obj<AAllocator> aux_mm)
|
||||
: config_{config},
|
||||
mm_(box<AAllocator,DX1Collector>(new DX1Collector(config.x1_config_))),
|
||||
rcx_(box<ARuntimeContext,DVsmRcx>(new DVsmRcx(this))),
|
||||
reader_{config.rdr_config_, mm_.to_op()}
|
||||
mm_(abox<AAllocator,DX1Collector>::make(aux_mm, config.x1_config_)),
|
||||
rcx_(abox<ARuntimeContext,DVsmRcx>::make(aux_mm, this)),
|
||||
reader_{config.rdr_config_, mm_.to_op(), aux_mm}
|
||||
{
|
||||
{
|
||||
DArena * arena = new DArena();
|
||||
DArena * arena = new DArena(config_.error_config_);
|
||||
assert(arena);
|
||||
*arena = DArena::map(config_.error_config_);
|
||||
|
||||
error_mm_.adopt(obj<AAllocator,DArena>(arena));
|
||||
}
|
||||
|
|
@ -165,7 +165,7 @@ namespace xo {
|
|||
bool
|
||||
VirtualSchematikaMachine::execute_one()
|
||||
{
|
||||
scope log(XO_DEBUG(true));
|
||||
scope log(XO_DEBUG(config_.debug_flag_));
|
||||
log && log(xtag("pc", pc_),
|
||||
xtag("cont", cont_));
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include <xo/object2/Integer.hpp>
|
||||
#include <xo/object2/Boolean.hpp>
|
||||
#include <xo/object2/RuntimeError.hpp>
|
||||
#include <xo/alloc2/Arena.hpp>
|
||||
|
||||
#ifdef NOT_YET
|
||||
#include <xo/reader2/SchematikaParser.hpp>
|
||||
|
|
@ -37,61 +38,80 @@ namespace xo {
|
|||
using xo::scm::DRuntimeError;
|
||||
using xo::mm::AGCObject;
|
||||
using xo::mm::MemorySizeInfo;
|
||||
using xo::mm::AAllocator;
|
||||
using xo::mm::DArena;
|
||||
using xo::mm::ArenaConfig;
|
||||
using xo::facet::FacetRegistry;
|
||||
using span_type = xo::scm::VirtualSchematikaMachine::span_type;
|
||||
using Catch::Matchers::WithinAbs;
|
||||
|
||||
#ifdef NOT_YET
|
||||
using xo::scm::SchematikaParser;
|
||||
using xo::scm::ASyntaxStateMachine;
|
||||
using xo::scm::syntaxstatetype;
|
||||
// using xo::scm::DDefineSsm;
|
||||
using xo::scm::DExpectExprSsm;
|
||||
// using xo::scm::defexprstatetype;
|
||||
//using xo::scm::ParserResult;
|
||||
//using xo::scm::parser_result_type;
|
||||
using xo::scm::Token;
|
||||
using xo::scm::DString;
|
||||
using xo::mm::ArenaConfig;
|
||||
using xo::mm::AAllocator;
|
||||
using xo::mm::DArena;
|
||||
using xo::facet::with_facet;
|
||||
#endif
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
static InitEvidence s_init = (InitSubsys<S_interpreter2_tag>::require());
|
||||
|
||||
namespace ut {
|
||||
TEST_CASE("VirtualSchematikaMachine-ctor", "[interpreter2][VSM]")
|
||||
struct ArenaShim {
|
||||
explicit ArenaShim(const std::string & name, std::size_t size = 16*1024)
|
||||
: arena_(ArenaConfig().with_name(name).with_size(size))
|
||||
{
|
||||
const auto & testname = Catch::getResultCapture().getCurrentTestName();
|
||||
}
|
||||
|
||||
scope log(XO_DEBUG(true), xtag("test", testname));
|
||||
obj<AAllocator,DArena> to_op() { return obj<AAllocator,DArena>(&arena_); }
|
||||
|
||||
VsmConfig cfg;
|
||||
VirtualSchematikaMachine vsm(cfg);
|
||||
DArena arena_;
|
||||
};
|
||||
|
||||
auto visitor = [&log](const MemorySizeInfo & info) {
|
||||
log && log(xtag("resource", info.resource_name_),
|
||||
struct VsmFixture {
|
||||
explicit VsmFixture(const std::string & testname,
|
||||
bool debug_flag,
|
||||
const VsmConfig & cfg = VsmConfig())
|
||||
: aux_mm_{testname},
|
||||
vsm_{cfg.with_debug_flag(debug_flag), aux_mm_.to_op()}
|
||||
{}
|
||||
|
||||
bool log_memory_layout(scope * p_log) {
|
||||
auto visitor = [p_log](const MemorySizeInfo & info) {
|
||||
*p_log && (*p_log)(xtag("resource", info.resource_name_),
|
||||
xtag("used", info.used_),
|
||||
xtag("alloc", info.allocated_),
|
||||
xtag("commit", info.committed_),
|
||||
xtag("resv", info.reserved_));
|
||||
};
|
||||
|
||||
aux_mm_.arena_.visit_pools(visitor);
|
||||
FacetRegistry::instance().visit_pools(visitor);
|
||||
vsm.visit_pools(visitor);
|
||||
vsm_.visit_pools(visitor);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ArenaShim aux_mm_;
|
||||
VirtualSchematikaMachine vsm_;
|
||||
};
|
||||
|
||||
TEST_CASE("VirtualSchematikaMachine-ctor", "[interpreter2][VSM]")
|
||||
{
|
||||
const auto & testname = Catch::getResultCapture().getCurrentTestName();
|
||||
|
||||
bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
|
||||
|
||||
VsmFixture vsm_fixture(testname, c_debug_flag);
|
||||
|
||||
log && vsm_fixture.log_memory_layout(&log);
|
||||
}
|
||||
|
||||
TEST_CASE("VirtualSchematikaMachine-const1", "[interpreter2][VSM]")
|
||||
{
|
||||
const auto & testname = Catch::getResultCapture().getCurrentTestName();
|
||||
|
||||
scope log(XO_DEBUG(true), xtag("test", testname));
|
||||
constexpr bool c_debug_flag = false;
|
||||
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
|
||||
|
||||
VsmConfig cfg;
|
||||
VirtualSchematikaMachine vsm(cfg);
|
||||
VsmFixture vsm_fixture(testname, c_debug_flag);
|
||||
|
||||
auto & vsm = vsm_fixture.vsm_;
|
||||
|
||||
bool eof_flag = false;
|
||||
|
||||
|
|
@ -109,26 +129,19 @@ namespace xo {
|
|||
REQUIRE(res.remaining_.size() == 1);
|
||||
REQUIRE(*res.remaining_.lo() == '\n');
|
||||
|
||||
auto visitor = [&log](const MemorySizeInfo & info) {
|
||||
log && log(xtag("resource", info.resource_name_),
|
||||
xtag("used", info.used_),
|
||||
xtag("alloc", info.allocated_),
|
||||
xtag("commit", info.committed_),
|
||||
xtag("resv", info.reserved_));
|
||||
};
|
||||
|
||||
FacetRegistry::instance().visit_pools(visitor);
|
||||
vsm.visit_pools(visitor);
|
||||
log && vsm_fixture.log_memory_layout(&log);
|
||||
}
|
||||
|
||||
TEST_CASE("VirtualSchematikaMachine-const2", "[interpreter2][VSM]")
|
||||
{
|
||||
const auto & testname = Catch::getResultCapture().getCurrentTestName();
|
||||
|
||||
scope log(XO_DEBUG(true), xtag("test", testname));
|
||||
constexpr bool c_debug_flag = false;
|
||||
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
|
||||
|
||||
VsmConfig cfg;
|
||||
VirtualSchematikaMachine vsm(cfg);
|
||||
VsmFixture vsm_fixture(testname, c_debug_flag);
|
||||
|
||||
auto & vsm = vsm_fixture.vsm_;
|
||||
|
||||
bool eof_flag = false;
|
||||
|
||||
|
|
@ -148,26 +161,18 @@ namespace xo {
|
|||
REQUIRE(res.remaining_.size() == 1);
|
||||
REQUIRE(*res.remaining_.lo() == '\n');
|
||||
|
||||
auto visitor = [&log](const MemorySizeInfo & info) {
|
||||
log && log(xtag("resource", info.resource_name_),
|
||||
xtag("used", info.used_),
|
||||
xtag("alloc", info.allocated_),
|
||||
xtag("commit", info.committed_),
|
||||
xtag("resv", info.reserved_));
|
||||
};
|
||||
|
||||
FacetRegistry::instance().visit_pools(visitor);
|
||||
vsm.visit_pools(visitor);
|
||||
log && vsm_fixture.log_memory_layout(&log);
|
||||
}
|
||||
|
||||
TEST_CASE("VirtualSchematikaMachine-arith1", "[interpreter2][VSM]")
|
||||
{
|
||||
const auto & testname = Catch::getResultCapture().getCurrentTestName();
|
||||
|
||||
scope log(XO_DEBUG(true), xtag("test", testname));
|
||||
constexpr bool c_debug_flag = false;
|
||||
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
|
||||
|
||||
VsmConfig cfg;
|
||||
VirtualSchematikaMachine vsm(cfg);
|
||||
VsmFixture vsm_fixture(testname, c_debug_flag);
|
||||
auto & vsm = vsm_fixture.vsm_;
|
||||
|
||||
bool eof_flag = false;
|
||||
|
||||
|
|
@ -187,16 +192,7 @@ namespace xo {
|
|||
REQUIRE(res.remaining_.size() == 1);
|
||||
REQUIRE(*res.remaining_.lo() == '\n');
|
||||
|
||||
auto visitor = [&log](const MemorySizeInfo & info) {
|
||||
log && log(xtag("resource", info.resource_name_),
|
||||
xtag("used", info.used_),
|
||||
xtag("alloc", info.allocated_),
|
||||
xtag("commit", info.committed_),
|
||||
xtag("resv", info.reserved_));
|
||||
};
|
||||
|
||||
FacetRegistry::instance().visit_pools(visitor);
|
||||
vsm.visit_pools(visitor);
|
||||
log && vsm_fixture.log_memory_layout(&log);
|
||||
}
|
||||
|
||||
TEST_CASE("VirtualSchematikaMachine-cmp1", "[interpreter2][VSM]")
|
||||
|
|
@ -206,13 +202,15 @@ namespace xo {
|
|||
constexpr bool c_debug_flag = false;
|
||||
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
|
||||
|
||||
VsmConfig cfg;
|
||||
VirtualSchematikaMachine vsm(cfg);
|
||||
VsmFixture vsm_fixture(testname, c_debug_flag);
|
||||
auto & vsm = vsm_fixture.vsm_;
|
||||
|
||||
bool eof_flag = false;
|
||||
|
||||
vsm.begin_interactive_session();
|
||||
VsmResultExt res = vsm.read_eval_print(span_type::from_cstr("123 == 123;"), eof_flag);
|
||||
VsmResultExt res
|
||||
= vsm.read_eval_print(span_type::from_cstr("123 == 123;"),
|
||||
eof_flag);
|
||||
|
||||
REQUIRE(res.is_value());
|
||||
REQUIRE(res.value());
|
||||
|
|
@ -227,32 +225,25 @@ namespace xo {
|
|||
REQUIRE(res.remaining_.size() == 1);
|
||||
REQUIRE(*res.remaining_.lo() == '\n');
|
||||
|
||||
auto visitor = [&log](const MemorySizeInfo & info) {
|
||||
log && log(xtag("resource", info.resource_name_),
|
||||
xtag("used", info.used_),
|
||||
xtag("alloc", info.allocated_),
|
||||
xtag("commit", info.committed_),
|
||||
xtag("resv", info.reserved_));
|
||||
};
|
||||
|
||||
FacetRegistry::instance().visit_pools(visitor);
|
||||
vsm.visit_pools(visitor);
|
||||
log && vsm_fixture.log_memory_layout(&log);
|
||||
}
|
||||
|
||||
TEST_CASE("VirtualSchematikaMachine-if", "[interpreter2][VSM]")
|
||||
{
|
||||
const auto & testname = Catch::getResultCapture().getCurrentTestName();
|
||||
|
||||
constexpr bool c_debug_flag = true;
|
||||
constexpr bool c_debug_flag = false;
|
||||
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
|
||||
|
||||
VsmConfig cfg;
|
||||
VirtualSchematikaMachine vsm(cfg);
|
||||
VsmFixture vsm_fixture(testname, c_debug_flag);
|
||||
auto & vsm = vsm_fixture.vsm_;
|
||||
|
||||
bool eof_flag = false;
|
||||
|
||||
vsm.begin_interactive_session();
|
||||
VsmResultExt res = vsm.read_eval_print(span_type::from_cstr("if 123 == 123 then \"equal\" else \"notequal\";"), eof_flag);
|
||||
VsmResultExt res
|
||||
= vsm.read_eval_print(span_type::from_cstr("if 123 == 123 then \"equal\" else \"notequal\";"),
|
||||
eof_flag);
|
||||
|
||||
REQUIRE(res.is_value());
|
||||
REQUIRE(res.value());
|
||||
|
|
@ -267,16 +258,7 @@ namespace xo {
|
|||
REQUIRE(res.remaining_.size() == 1);
|
||||
REQUIRE(*res.remaining_.lo() == '\n');
|
||||
|
||||
auto visitor = [&log](const MemorySizeInfo & info) {
|
||||
log && log(xtag("resource", info.resource_name_),
|
||||
xtag("used", info.used_),
|
||||
xtag("alloc", info.allocated_),
|
||||
xtag("commit", info.committed_),
|
||||
xtag("resv", info.reserved_));
|
||||
};
|
||||
|
||||
FacetRegistry::instance().visit_pools(visitor);
|
||||
vsm.visit_pools(visitor);
|
||||
log && vsm_fixture.log_memory_layout(&log);
|
||||
}
|
||||
|
||||
TEST_CASE("VirtualSchematikaMachine-lambda1", "[interpreter2][VSM]")
|
||||
|
|
@ -286,13 +268,15 @@ namespace xo {
|
|||
constexpr bool c_debug_flag = false;
|
||||
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
|
||||
|
||||
VsmConfig cfg;
|
||||
VirtualSchematikaMachine vsm(cfg);
|
||||
VsmFixture vsm_fixture(testname, c_debug_flag);
|
||||
auto & vsm = vsm_fixture.vsm_;
|
||||
|
||||
bool eof_flag = false;
|
||||
|
||||
vsm.begin_interactive_session();
|
||||
VsmResultExt res = vsm.read_eval_print(span_type::from_cstr("lambda (x : i64) -> i64 { x * x; }"), eof_flag);
|
||||
VsmResultExt res
|
||||
= vsm.read_eval_print(span_type::from_cstr("lambda (x : i64) -> i64 { x * x; }"),
|
||||
eof_flag);
|
||||
|
||||
REQUIRE(res.is_value());
|
||||
REQUIRE(res.value());
|
||||
|
|
@ -307,26 +291,18 @@ namespace xo {
|
|||
REQUIRE(res.remaining_.size() == 1);
|
||||
REQUIRE(*res.remaining_.lo() == '\n');
|
||||
|
||||
auto visitor = [&log](const MemorySizeInfo & info) {
|
||||
log && log(xtag("resource", info.resource_name_),
|
||||
xtag("used", info.used_),
|
||||
xtag("alloc", info.allocated_),
|
||||
xtag("commit", info.committed_),
|
||||
xtag("resv", info.reserved_));
|
||||
};
|
||||
|
||||
FacetRegistry::instance().visit_pools(visitor);
|
||||
vsm.visit_pools(visitor);
|
||||
log && vsm_fixture.log_memory_layout(&log);
|
||||
}
|
||||
|
||||
TEST_CASE("VirtualSchematikaMachine-apply2", "[interpreter2][VSM]")
|
||||
{
|
||||
const auto & testname = Catch::getResultCapture().getCurrentTestName();
|
||||
|
||||
scope log(XO_DEBUG(false), xtag("test", testname));
|
||||
bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
|
||||
|
||||
VsmConfig cfg;
|
||||
VirtualSchematikaMachine vsm(cfg);
|
||||
VsmFixture vsm_fixture(testname, c_debug_flag);
|
||||
auto & vsm = vsm_fixture.vsm_;
|
||||
|
||||
bool eof_flag = false;
|
||||
|
||||
|
|
@ -354,16 +330,7 @@ namespace xo {
|
|||
REQUIRE(res.remaining_.size() == 1);
|
||||
REQUIRE(*res.remaining_.lo() == '\n');
|
||||
|
||||
auto visitor = [&log](const MemorySizeInfo & info) {
|
||||
log && log(xtag("resource", info.resource_name_),
|
||||
xtag("used", info.used_),
|
||||
xtag("alloc", info.allocated_),
|
||||
xtag("commit", info.committed_),
|
||||
xtag("resv", info.reserved_));
|
||||
};
|
||||
|
||||
FacetRegistry::instance().visit_pools(visitor);
|
||||
vsm.visit_pools(visitor);
|
||||
log && vsm_fixture.log_memory_layout(&log);
|
||||
}
|
||||
|
||||
} /*namespace ut*/
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@
|
|||
|
||||
#include <xo/reader2/init_reader2.hpp>
|
||||
#include <xo/reader2/SchematikaReader.hpp>
|
||||
#include <xo/gc/DX1Collector.hpp>
|
||||
#include <xo/gc/X1Collector.hpp>
|
||||
#include <xo/gc/detail/IAllocator_DX1Collector.hpp>
|
||||
#include <xo/alloc2/Arena.hpp>
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/facet/FacetRegistry.hpp>
|
||||
|
|
@ -137,6 +138,7 @@ namespace {
|
|||
struct AppConfig {
|
||||
using ReaderConfig = xo::scm::ReaderConfig;
|
||||
using X1CollectorConfig = xo::mm::X1CollectorConfig;
|
||||
using ArenaConfig = xo::mm::ArenaConfig;
|
||||
|
||||
AppConfig() {
|
||||
rdr_config_.reader_debug_flag_ = true;
|
||||
|
|
@ -147,17 +149,24 @@ struct AppConfig {
|
|||
std::size_t max_history_size_ = 1000;
|
||||
std::string repl_history_fname_ = "repl_history.txt";;
|
||||
ReaderConfig rdr_config_;
|
||||
X1CollectorConfig x1_config_ = (X1CollectorConfig().with_size(4*1024*1024));
|
||||
X1CollectorConfig x1_config_ = (X1CollectorConfig().with_name("gc").with_size(4*1024*1024));
|
||||
ArenaConfig fixed_config_ = (ArenaConfig().with_name("fixed").with_size(4*1024));
|
||||
};
|
||||
|
||||
struct AppContext {
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using DX1Collector = xo::mm::DX1Collector;
|
||||
using X1CollectorConfig = xo::mm::X1CollectorConfig;
|
||||
using DArena = xo::mm::DArena;
|
||||
using ArenaConfig = xo::mm::ArenaConfig;
|
||||
using Replxx = replxx::Replxx;
|
||||
|
||||
AppContext(const AppConfig & cfg = AppConfig()) : config_{cfg},
|
||||
x1_{X1CollectorConfig().with_size(4*1024*1024)},
|
||||
rdr_{config_.rdr_config_, x1_.ref()}
|
||||
x1_{cfg.x1_config_},
|
||||
fixed_{cfg.fixed_config_},
|
||||
rdr_{config_.rdr_config_,
|
||||
x1_.ref(),
|
||||
obj<AAllocator,DArena>(&fixed_)}
|
||||
{
|
||||
rx_.set_max_history_size(config_.max_history_size_);
|
||||
rx_.history_load(config_.repl_history_fname_);
|
||||
|
|
@ -167,7 +176,10 @@ struct AppContext {
|
|||
|
||||
AppConfig config_;
|
||||
Replxx rx_;
|
||||
/** collector/allocator for schematika expressions **/
|
||||
DX1Collector x1_;
|
||||
/** e.g. for DArenaHashMap within global symtab **/
|
||||
DArena fixed_;
|
||||
SchematikaReader rdr_;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -41,9 +41,21 @@ namespace xo {
|
|||
using size_type = std::size_t;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @p config arena configuration for parser state
|
||||
* @p max_stringtable_capacity
|
||||
* hard max size for unique stringtable
|
||||
* @p expr_alloc allocator for schematika expressions.
|
||||
* Probably shared with execution.
|
||||
* @p aux_alloc auxiliary allocator for non-copyable memory
|
||||
* (e.g. DArenaHashMap for global symtable).
|
||||
* If not using X1Collector, this can be the
|
||||
* same as @p expr_alloc.
|
||||
**/
|
||||
ParserStateMachine(const ArenaConfig & config,
|
||||
size_type max_stringtable_capacity,
|
||||
obj<AAllocator> expr_alloc);
|
||||
obj<AAllocator> expr_alloc,
|
||||
obj<AAllocator> aux_alloc);
|
||||
|
||||
/** @defgroup scm-parserstatemachine-accessors accessor methods **/
|
||||
///@{
|
||||
|
|
@ -280,6 +292,19 @@ namespace xo {
|
|||
**/
|
||||
obj<AAllocator> expr_alloc_;
|
||||
|
||||
/** Allocator for data with lifetime bounded by this ParserStateMachine
|
||||
*
|
||||
* Cannot be DX1Collector; for example DArenaHashMap will
|
||||
* for global symtab will be allocated from here,
|
||||
* and does not support gc.
|
||||
*
|
||||
* If @ref expr_alloc_ is an ordinary arena (e.g. DArenaAlloc)
|
||||
* can have aux_alloc_ = expr_alloc_.
|
||||
* When expr_alloc_ is a garbage collector (e.g. DX1Collector)
|
||||
* this needs to be distinct.
|
||||
**/
|
||||
obj<AAllocator> aux_alloc_;
|
||||
|
||||
/** symbol table with local bindings.
|
||||
* non-null during parsing of lambda expressions.
|
||||
* Always allocated from @p expr_alloc_.
|
||||
|
|
|
|||
|
|
@ -167,11 +167,15 @@ namespace xo {
|
|||
* @p config arena configuration for parser stack
|
||||
* @p expr_alloc allocator for schematika expressions.
|
||||
* Probably shared with execution.
|
||||
* @p aux_alloc aux allocator for non-copyable memory
|
||||
* with lifetime bounded by this
|
||||
* SchematikeParser itself
|
||||
* @p debug_flag true to enable debug logging
|
||||
**/
|
||||
SchematikaParser(const ArenaConfig & config,
|
||||
size_t max_stringtable_capacity,
|
||||
obj<AAllocator> expr_alloc,
|
||||
obj<AAllocator> aux_alloc,
|
||||
bool debug_flag);
|
||||
|
||||
/** scm-schematikaparser-access-methods **/
|
||||
|
|
|
|||
|
|
@ -41,8 +41,15 @@ namespace xo {
|
|||
using size_type = std::size_t;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @p expr_alloc. allocator for Schematika expressions
|
||||
* @p aux_alloc. allocator for miscellaneous objects
|
||||
* (e.g. DArenaHashMap for global symtab)
|
||||
* that have lifetime bounded by Schematika reader itself.
|
||||
**/
|
||||
SchematikaReader(const ReaderConfig & config,
|
||||
obj<AAllocator> expr_alloc);
|
||||
obj<AAllocator> expr_alloc,
|
||||
obj<AAllocator> fixed_alloc);
|
||||
|
||||
/** visit reader-owned memory pools; call visitor(info) for each.
|
||||
* Specifically exclude expr_alloc, since we don't consider
|
||||
|
|
|
|||
|
|
@ -24,13 +24,14 @@ namespace xo {
|
|||
namespace scm {
|
||||
ParserStateMachine::ParserStateMachine(const ArenaConfig & config,
|
||||
size_type max_stringtable_capacity,
|
||||
obj<AAllocator> expr_alloc)
|
||||
obj<AAllocator> expr_alloc,
|
||||
obj<AAllocator> aux_alloc)
|
||||
: stringtable_{max_stringtable_capacity},
|
||||
parser_alloc_{DArena::map(config)},
|
||||
expr_alloc_{expr_alloc},
|
||||
aux_alloc_{aux_alloc},
|
||||
debug_flag_{config.debug_flag_}
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
@ -60,8 +61,8 @@ namespace xo {
|
|||
stringtable_.visit_pools(visitor);
|
||||
parser_alloc_.visit_pools(visitor);
|
||||
|
||||
// not counting expr_alloc_. We don't consider
|
||||
// that to be owned by ParserStateMachine
|
||||
// not counting {expr_alloc_, fixed_alloc_}. We don't consider
|
||||
// either to be owned by ParserStateMachine
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -23,8 +23,9 @@ namespace xo {
|
|||
SchematikaParser::SchematikaParser(const ArenaConfig & config,
|
||||
size_t max_stringtable_capacity,
|
||||
obj<AAllocator> expr_alloc,
|
||||
obj<AAllocator> fixed_alloc,
|
||||
bool debug_flag)
|
||||
: psm_{config, max_stringtable_capacity, expr_alloc},
|
||||
: psm_{config, max_stringtable_capacity, expr_alloc, fixed_alloc},
|
||||
debug_flag_{debug_flag}
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,12 +10,14 @@ namespace xo {
|
|||
|
||||
namespace scm {
|
||||
SchematikaReader::SchematikaReader(const ReaderConfig & config,
|
||||
obj<AAllocator> expr_alloc)
|
||||
obj<AAllocator> expr_alloc,
|
||||
obj<AAllocator> fixed_alloc)
|
||||
: tokenizer_{config.tk_buffer_config_,
|
||||
config.tk_debug_flag_},
|
||||
parser_{config.parser_arena_config_,
|
||||
config.max_stringtable_cap_,
|
||||
expr_alloc,
|
||||
fixed_alloc,
|
||||
config.parser_debug_flag_},
|
||||
debug_flag_{config.reader_debug_flag_}
|
||||
{
|
||||
|
|
|
|||
|
|
@ -88,8 +88,9 @@ namespace xo {
|
|||
|
||||
DArena expr_arena = DArena::map(config);
|
||||
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
||||
auto aux_alloc = expr_alloc;
|
||||
|
||||
SchematikaParser parser(config, 4096, expr_alloc, false /*debug_flag*/);
|
||||
SchematikaParser parser(config, 4096, expr_alloc, aux_alloc, false /*debug_flag*/);
|
||||
|
||||
REQUIRE(parser.debug_flag() == false);
|
||||
REQUIRE(parser.is_at_toplevel() == true);
|
||||
|
|
@ -103,8 +104,9 @@ namespace xo {
|
|||
|
||||
DArena expr_arena = DArena::map(config);
|
||||
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
||||
auto aux_alloc = expr_alloc;
|
||||
|
||||
SchematikaParser parser(config, 4096, expr_alloc, false /*debug_flag*/);
|
||||
SchematikaParser parser(config, 4096, expr_alloc, aux_alloc, false /*debug_flag*/);
|
||||
|
||||
parser.begin_interactive_session();
|
||||
|
||||
|
|
@ -121,8 +123,9 @@ namespace xo {
|
|||
|
||||
DArena expr_arena = DArena::map(config);
|
||||
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
||||
auto aux_alloc = expr_alloc;
|
||||
|
||||
SchematikaParser parser(config, 4096, expr_alloc, false /*debug_flag*/);
|
||||
SchematikaParser parser(config, 4096, expr_alloc, aux_alloc, false /*debug_flag*/);
|
||||
|
||||
parser.begin_batch_session();
|
||||
|
||||
|
|
@ -133,17 +136,20 @@ namespace xo {
|
|||
|
||||
TEST_CASE("SchematikaParser-batch-def", "[reader2][SchematikaParser]")
|
||||
{
|
||||
const auto & testname = Catch::getResultCapture().getCurrentTestName();
|
||||
|
||||
constexpr bool c_debug_flag = false;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
|
||||
|
||||
ArenaConfig config;
|
||||
config.name_ = "test-arena";
|
||||
config.name_ = testname;
|
||||
config.size_ = 16 * 1024;
|
||||
|
||||
DArena expr_arena = DArena::map(config);
|
||||
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
||||
auto aux_alloc = expr_alloc;
|
||||
|
||||
SchematikaParser parser(config, 4096, expr_alloc, false /*debug_flag*/);
|
||||
SchematikaParser parser(config, 4096, expr_alloc, aux_alloc, false /*debug_flag*/);
|
||||
|
||||
parser.begin_batch_session();
|
||||
|
||||
|
|
@ -185,8 +191,9 @@ namespace xo {
|
|||
|
||||
DArena expr_arena = DArena::map(config);
|
||||
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
||||
auto aux_alloc = expr_alloc;
|
||||
|
||||
SchematikaParser parser(config, 4096, expr_alloc, false /*debug_flag*/);
|
||||
SchematikaParser parser(config, 4096, expr_alloc, aux_alloc, false /*debug_flag*/);
|
||||
|
||||
parser.begin_interactive_session();
|
||||
|
||||
|
|
@ -250,8 +257,9 @@ namespace xo {
|
|||
|
||||
DArena expr_arena = DArena::map(config);
|
||||
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
||||
auto aux_alloc = expr_alloc;
|
||||
|
||||
SchematikaParser parser(config, 4096, expr_alloc, false /*debug_flag*/);
|
||||
SchematikaParser parser(config, 4096, expr_alloc, aux_alloc, false /*debug_flag*/);
|
||||
|
||||
parser.begin_interactive_session();
|
||||
|
||||
|
|
@ -315,8 +323,9 @@ namespace xo {
|
|||
|
||||
DArena expr_arena = DArena::map(config);
|
||||
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
||||
auto aux_alloc = expr_alloc;
|
||||
|
||||
SchematikaParser parser(config, 4096, expr_alloc, false /*debug_flag*/);
|
||||
SchematikaParser parser(config, 4096, expr_alloc, aux_alloc, false /*debug_flag*/);
|
||||
|
||||
parser.begin_interactive_session();
|
||||
|
||||
|
|
@ -380,8 +389,9 @@ namespace xo {
|
|||
|
||||
DArena expr_arena = DArena::map(config);
|
||||
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
||||
auto aux_alloc = expr_alloc;
|
||||
|
||||
SchematikaParser parser(config, 4096, expr_alloc, false /*debug_flag*/);
|
||||
SchematikaParser parser(config, 4096, expr_alloc, aux_alloc, false /*debug_flag*/);
|
||||
|
||||
parser.begin_interactive_session();
|
||||
|
||||
|
|
@ -435,16 +445,17 @@ namespace xo {
|
|||
const auto & testname = Catch::getResultCapture().getCurrentTestName();
|
||||
|
||||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
|
||||
scope log(XO_DEBUG(c_debug_flag),
|
||||
xtag("test", testname));
|
||||
|
||||
ArenaConfig config;
|
||||
config.name_ = "test-arena";
|
||||
config.size_ = 16 * 1024;
|
||||
ArenaConfig config
|
||||
= (ArenaConfig().with_name(testname).with_size(16 * 1024));
|
||||
|
||||
DArena expr_arena = DArena::map(config);
|
||||
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
||||
auto expr_alloc = obj<AAllocator,DArena>(&expr_arena);
|
||||
auto aux_alloc = expr_alloc;
|
||||
|
||||
SchematikaParser parser(config, 4096, expr_alloc, false /*debug_flag*/);
|
||||
SchematikaParser parser(config, 4096, expr_alloc, aux_alloc, false /*debug_flag*/);
|
||||
|
||||
parser.begin_interactive_session();
|
||||
|
||||
|
|
@ -507,8 +518,9 @@ namespace xo {
|
|||
|
||||
DArena expr_arena = DArena::map(config);
|
||||
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
||||
auto aux_alloc = expr_alloc;
|
||||
|
||||
SchematikaParser parser(config, 4096, expr_alloc, false /*debug_flag*/);
|
||||
SchematikaParser parser(config, 4096, expr_alloc, aux_alloc, false /*debug_flag*/);
|
||||
|
||||
parser.begin_interactive_session();
|
||||
|
||||
|
|
@ -549,13 +561,14 @@ namespace xo {
|
|||
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
|
||||
|
||||
ArenaConfig config;
|
||||
config.name_ = "test-arena";
|
||||
config.name_ = testname;
|
||||
config.size_ = 16 * 1024;
|
||||
|
||||
DArena expr_arena = DArena::map(config);
|
||||
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
||||
auto aux_alloc = expr_alloc;
|
||||
|
||||
SchematikaParser parser(config, 4096, expr_alloc, false /*debug_flag*/);
|
||||
SchematikaParser parser(config, 4096, expr_alloc, aux_alloc, false /*debug_flag*/);
|
||||
|
||||
parser.begin_interactive_session();
|
||||
|
||||
|
|
@ -592,8 +605,9 @@ namespace xo {
|
|||
|
||||
DArena expr_arena = DArena::map(config);
|
||||
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
||||
auto aux_alloc = expr_alloc;
|
||||
|
||||
SchematikaParser parser(config, 4096, expr_alloc, false /*debug_flag*/);
|
||||
SchematikaParser parser(config, 4096, expr_alloc, aux_alloc, false /*debug_flag*/);
|
||||
|
||||
parser.begin_interactive_session();
|
||||
|
||||
|
|
@ -632,13 +646,14 @@ namespace xo {
|
|||
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
|
||||
|
||||
ArenaConfig config;
|
||||
config.name_ = "test-arena";
|
||||
config.name_ = testname;
|
||||
config.size_ = 16 * 1024;
|
||||
|
||||
DArena expr_arena = DArena::map(config);
|
||||
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
||||
auto aux_alloc = expr_alloc;
|
||||
|
||||
SchematikaParser parser(config, 4096, expr_alloc, false /*debug_flag*/);
|
||||
SchematikaParser parser(config, 4096, expr_alloc, aux_alloc, false /*debug_flag*/);
|
||||
|
||||
parser.begin_interactive_session();
|
||||
|
||||
|
|
@ -689,8 +704,9 @@ namespace xo {
|
|||
|
||||
DArena expr_arena = DArena::map(config);
|
||||
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
||||
auto aux_alloc = expr_alloc;
|
||||
|
||||
SchematikaParser parser(config, 4096, expr_alloc, false /*debug_flag*/);
|
||||
SchematikaParser parser(config, 4096, expr_alloc, aux_alloc, false /*debug_flag*/);
|
||||
|
||||
parser.begin_interactive_session();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue