summaryrefslogtreecommitdiff
path: root/starts/meaning-vm/helpers.cpp
diff options
context:
space:
mode:
authorolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-22 17:55:18 -0800
committerolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-22 17:55:18 -0800
commitc2ed17faa6aa9f8420128d2713c5b557ab333466 (patch)
treea6d4755f797896f641891565e9d2965c97513b7c /starts/meaning-vm/helpers.cpp
parentc699a8913c5c1e53e0b701109dabe2b8fc70b644 (diff)
downloadstandingwithresilience-c2ed17faa6aa9f8420128d2713c5b557ab333466.tar.gz
standingwithresilience-c2ed17faa6aa9f8420128d2713c5b557ab333466.zip
use refs for temporaries, which means pulling them out of containers
Diffstat (limited to 'starts/meaning-vm/helpers.cpp')
-rw-r--r--starts/meaning-vm/helpers.cpp31
1 files changed, 15 insertions, 16 deletions
diff --git a/starts/meaning-vm/helpers.cpp b/starts/meaning-vm/helpers.cpp
index 1d6d498..8c8618d 100644
--- a/starts/meaning-vm/helpers.cpp
+++ b/starts/meaning-vm/helpers.cpp
@@ -9,7 +9,7 @@ ref operator-(ref a, ref b)
return ref(a.name() + "-" + b.name());
}
-concept ref::operator=(ref other)
+ref ref::operator=(ref other)
{
// if this is not anonymous, and other is, then we are naming it
/*declrefs(anonymous);
@@ -17,28 +17,28 @@ concept ref::operator=(ref other)
return;
}*/
// if this is link-type, make new concept [not checked, might want to assume]
- concept ret;
- ret.link(*this, other);
+ ref ret = alloc();
+ ret->link(*this, other);
return ret;
}
-ref ref::operator[](concept links) {
- ptr->links.insert(links.links.begin(), links.links.end());
+ref ref::operator[](ref links) {
+ ptr->links.insert(links->links.begin(), links->links.end());
+ dealloc(links);
return *this;
}
-concept operator,(concept a, concept b)
+ref operator,(ref a, ref b)
{
- concept ret;
- ret.links.insert(a.links.begin(), a.links.end());
- ret.links.insert(b.links.begin(), b.links.end());
- return ret;
+ a->links.insert(b->links.begin(), b->links.end());
+ dealloc(b);
+ return a;
}
// concept names are for bootstrapping convenience,
// to make hardcoding structures easier.
// hence there is just one single list of them
-std::unordered_map<vref<std::string>,ref,std::hash<std::string>,std::equal_to<std::string>> conceptsByName;
+std::unordered_map<std::string,concept*,std::hash<std::string>,std::equal_to<std::string>> conceptsByName;
struct name_t : public ref
{
@@ -49,19 +49,18 @@ name_t::name_t()
{
auto nam = valloc(std::string("name"));
ptr->link(::name, nam);
- conceptsByName.emplace(nam, *this);
+ conceptsByName.emplace(nam, ptr);
}
ref::ref(std::string const & s)
{
- value<std::string> str(s);
- auto res = conceptsByName.find(&str);
+ auto res = conceptsByName.find(s);
if (res != conceptsByName.end()) {
- ptr = res->second.ptr;
+ ptr = res->second;
} else {
ref con = alloc();
auto nam = valloc<std::string>(s);
- conceptsByName.emplace(nam, con);
+ conceptsByName.emplace(nam, con.ptr);
con->link(::name, nam);
ptr = con.ptr;
}