From 0965367d7581534f5d84cc93a66d3a38a5d646fe Mon Sep 17 00:00:00 2001 From: olpc user Date: Mon, 30 Dec 2019 11:24:17 -0800 Subject: fixed compilation errors; next is runtime --- starts/meaning-vm/level-1/funcs.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'starts/meaning-vm/level-1') diff --git a/starts/meaning-vm/level-1/funcs.cpp b/starts/meaning-vm/level-1/funcs.cpp index 1e6bd9d..2ba2d0f 100644 --- a/starts/meaning-vm/level-1/funcs.cpp +++ b/starts/meaning-vm/level-1/funcs.cpp @@ -11,6 +11,26 @@ namespace level1 { using namespace concepts; +// for generalizing unique data references. not used yet, could replace conceptsByName, +// but note this doesn't use a type link, and conceptsByName does. +template +ref conceptByData(T const& data, concept* con = nullptr, concept* allocator = nullptr) +{ + static std::map conceptsByData; // std::map works for typeid data + auto res = conceptsByData.find(data); + if (res != conceptsByData.end()) { + if (con != nullptr) { throw std::logic_error("unique data concept already specified"); } + return res->second; + } else { + if (con == nullptr) { + if (allocator == nullptr) { allocator = level0::concepts::allocations(); } + con = level0::alloc(allocator); + } + conceptsByData.emplace(data, con); + return con; + } +} + // ensure name link and backing structure are created prior to first use static auto & namestruct() { -- cgit v1.2.3