summaryrefslogtreecommitdiff
path: root/starts
diff options
context:
space:
mode:
authorolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-22 06:28:03 -0800
committerolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-22 06:28:03 -0800
commit018ced49ce429b123cbf63534d75f16ca91a96c2 (patch)
treea6c34ea9310bd3399392555b2d685e2fd4c8743f /starts
parent55f586437b52bda32793a376f8ea5df9fb1b89e2 (diff)
downloadstandingwithresilience-018ced49ce429b123cbf63534d75f16ca91a96c2.tar.gz
standingwithresilience-018ced49ce429b123cbf63534d75f16ca91a96c2.zip
decl references in one expression
Diffstat (limited to 'starts')
-rw-r--r--starts/meaning-vm/concept.hpp5
-rw-r--r--starts/meaning-vm/helpers.hpp22
-rw-r--r--starts/meaning-vm/main.cpp5
3 files changed, 26 insertions, 6 deletions
diff --git a/starts/meaning-vm/concept.hpp b/starts/meaning-vm/concept.hpp
index a2dcc2c..a80b157 100644
--- a/starts/meaning-vm/concept.hpp
+++ b/starts/meaning-vm/concept.hpp
@@ -12,11 +12,14 @@ struct ref
{
ref(concept *p) : ptr(p) { }
concept* operator->() { return ptr; }
+
+ // for use by containers
bool operator<(ref const & other) const { return ptr < other.ptr; }
- // helper names
+ // for helpers
ref(std::string const &);
ref(char const * str) : ref(std::string(str)) { }
+ ref() : ref("nothing") { }
value<std::string> & name() const;
operator const char *() const;
diff --git a/starts/meaning-vm/helpers.hpp b/starts/meaning-vm/helpers.hpp
index d69519c..f1b9e36 100644
--- a/starts/meaning-vm/helpers.hpp
+++ b/starts/meaning-vm/helpers.hpp
@@ -2,5 +2,23 @@
#include "concept.hpp"
-#define r(concept) \
- ref concept = #concept
+#include <sstream>
+
+template <typename... T>
+void __helper_init_ref_names(std::string names, T &... refrefs)
+{
+ std::stringstream ss(names);
+ ref* refptrs[] = {&refrefs...};
+ for (std::size_t i = 0; i < sizeof...(refrefs); ++ i) {
+ std::string name;
+ ss >> name;
+ if (name[name.size() - 1] == ',') {
+ name = name.substr(0, name.size() - 1);
+ }
+ refptrs[i]->ptr = ref(name).ptr;
+ }
+}
+
+#define decl(...) \
+ ref __VA_ARGS__; \
+ __helper_init_ref_names(#__VA_ARGS__, __VA_ARGS__)
diff --git a/starts/meaning-vm/main.cpp b/starts/meaning-vm/main.cpp
index a82a155..1392957 100644
--- a/starts/meaning-vm/main.cpp
+++ b/starts/meaning-vm/main.cpp
@@ -7,9 +7,8 @@ using namespace std;
int main()
{
- r(fruit);
- r(banana);
- r(is);
+ decl(fruit, banana, is);
+
banana->link(is, fruit);
cout << banana << "-" << is << "-" << fruit << endl;
}