summaryrefslogtreecommitdiff
path: root/starts/meaning-vm/helpers.cpp
blob: e4a76899d86d41fb66840f252845823101137d09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "helpers.hpp"

#include <unordered_map>

// these concept names are for bootstrapping convenience,
// to make hardcoding structures easier.
// hence there is just one single list of them

concept namesByConcept;
std::unordered_map<value<std::string>,concept,std::hash<std::string>> conceptsByName;

ref::ref(std::string s)
{
	try {
		ptr = &conceptsByName.at(value<std::string>(s));
	} catch (std::out_of_range) {
		auto insertion = conceptsByName.emplace(value<std::string>(s), concept());
		ref con = &insertion.first->second;
		ref nam = const_cast<concept *>((concept const *)&insertion.first->first);
		namesByConcept.link(con, nam);
		ptr = con;
	}
}

ref::operator std::string()
{
	return value<std::string>::of(namesByConcept.get(*this));
}