diff options
Diffstat (limited to 'starts/meaning-vm/level-1')
-rw-r--r-- | starts/meaning-vm/level-1/baseref.hpp | 4 | ||||
-rw-r--r-- | starts/meaning-vm/level-1/common.hpp | 1 | ||||
-rw-r--r-- | starts/meaning-vm/level-1/funcs.cpp | 37 | ||||
-rw-r--r-- | starts/meaning-vm/level-1/funcs.hpp | 5 |
4 files changed, 26 insertions, 21 deletions
diff --git a/starts/meaning-vm/level-1/baseref.hpp b/starts/meaning-vm/level-1/baseref.hpp index 8c358cc..e8bdcb9 100644 --- a/starts/meaning-vm/level-1/baseref.hpp +++ b/starts/meaning-vm/level-1/baseref.hpp @@ -21,8 +21,8 @@ struct baseref : public level0::baseref<ref> bool isa(ref group) const { return level1::isa(self, group); } bool isan(ref group) const { return isa(group); } - std::string const & name() const { return getname(self)->data; } - operator std::string const &() const { return getname(self)->data; } + std::string const & name() const { return getname(self); } + operator std::string const &() const { return getname(self); } operator char const *() const { return getname(self)->data.c_str(); } ref operator-(ref other) { return hyphenate(self.ptr(), other.ptr()); } diff --git a/starts/meaning-vm/level-1/common.hpp b/starts/meaning-vm/level-1/common.hpp index 2c9297b..73de3b4 100644 --- a/starts/meaning-vm/level-1/common.hpp +++ b/starts/meaning-vm/level-1/common.hpp @@ -6,7 +6,6 @@ namespace intellect { namespace level1 { using level0::concept; -using level0::value; template <typename T> struct baseref; struct ref; diff --git a/starts/meaning-vm/level-1/funcs.cpp b/starts/meaning-vm/level-1/funcs.cpp index 3d0d88d..07f0eba 100644 --- a/starts/meaning-vm/level-1/funcs.cpp +++ b/starts/meaning-vm/level-1/funcs.cpp @@ -21,9 +21,9 @@ static auto & namestruct() name_t() : nameref(level0::alloc()) { - auto namestr = valloc<std::string>("name"); + level0::ref namestr = alloc((std::string)("name")); nameref.set(nameref, namestr); - conceptsByName.emplace(namestr->data, nameref); + conceptsByName.emplace(namestr.val<std::string>(), nameref); } } namestruct; return namestruct; @@ -37,14 +37,14 @@ concept* getnamed(std::string const & name) return res->second; } else { level1::ref con = level0::alloc(); - level0::value<std::string>* namestr = level0::valloc(name); - ns.conceptsByName.emplace(namestr->data, con); + level0::ref namestr = level0::alloc(name); + ns.conceptsByName.emplace(namestr.val<std::string>(), con); con.set(ns.nameref, namestr); return con.ptr(); } } -value<std::string>* getname(concept* r) +std::string& getname(concept* r) { try { return r->vget<std::string>(namestruct().nameref); @@ -63,24 +63,31 @@ bool isa(concept* member, concept* group) return false; } -template <typename T> -value<T>* valloc(T const & val) +concept* alloc(std::any val) { - auto ret = level0::valloc<T>(val); + + ref ret = level0::alloc(val); std::stringstream ss; - // << val is making recursion - ss << typeid(T).name() << "(" << val << ")"; - ret->link(concepts::name, level0::valloc(ss.str())); + ss << val.type().name() << "("; + if (false); +#define t(T) \ + else if (val.type() == typeid(T)) { \ + ss << ret.val<T>(); \ + } + t(uint8_t) t(int8_t) t(uint16_t) t(int16_t) + t(uint32_t) t(int32_t) t(uint64_t) t(int64_t) + t(bool) t(float) t(double) t(std::string) t(char const *) +#undef t + else { ss << "?"; } + ss << ")"; + ret.link(concepts::name, level0::alloc(ss.str())); return ret; } concept* hyphenate(concept* a, concept* b) { - return getnamed(getname(a)->data + "-" + getname(b)->data); + return getnamed(getname(a) + "-" + getname(b)); } -template value<std::string>* valloc<std::string>(std::string const & val); -template value<int>* valloc<int>(int const & val); - } } diff --git a/starts/meaning-vm/level-1/funcs.hpp b/starts/meaning-vm/level-1/funcs.hpp index eab37e5..741a5af 100644 --- a/starts/meaning-vm/level-1/funcs.hpp +++ b/starts/meaning-vm/level-1/funcs.hpp @@ -12,14 +12,13 @@ namespace intellect { namespace level1 { concept* getnamed(std::string const & name); -value<std::string>* getname(concept* r); +std::string& getname(concept* r); bool isa(concept* member, concept* group); concept* hyphenate(concept* a, concept* b); -template <typename T> -value<T>* valloc(T const & val); +concept* alloc(std::any val); } } |