diff options
author | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-12-05 04:12:23 -0800 |
---|---|---|
committer | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-12-05 04:12:23 -0800 |
commit | 680af2ca0b1ced4c82bbce620d6c4fc97dae88d0 (patch) | |
tree | 1a833fe6f12a1eb00aa9bc6659a09c2c338cbdea /starts/meaning-vm/level-1/baseref.hpp | |
parent | cae16e6c034808199f12a37ec0bdb4822c988dca (diff) | |
download | standingwithresilience-680af2ca0b1ced4c82bbce620d6c4fc97dae88d0.tar.gz standingwithresilience-680af2ca0b1ced4c82bbce620d6c4fc97dae88d0.zip |
add function syntaxes
Diffstat (limited to 'starts/meaning-vm/level-1/baseref.hpp')
-rw-r--r-- | starts/meaning-vm/level-1/baseref.hpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/starts/meaning-vm/level-1/baseref.hpp b/starts/meaning-vm/level-1/baseref.hpp index e8bdcb9..63045fa 100644 --- a/starts/meaning-vm/level-1/baseref.hpp +++ b/starts/meaning-vm/level-1/baseref.hpp @@ -5,6 +5,8 @@ #include "../level-0/ref.hpp" +#include <functional> + namespace intellect { namespace level1 { @@ -27,7 +29,38 @@ struct baseref : public level0::baseref<ref> ref operator-(ref other) { return hyphenate(self.ptr(), other.ptr()); } + template <typename T> + void vset(ref const & type, T const & v) { self.set(type, level1::alloc(v)); } + + template <typename... Ref> + std::function<ref(Ref...)> & fun() { return self.template val<std::function<ref(Ref...)>>(); } + template <typename... Ref> + void fun(std::function<ref(Ref...)> const & f) { val(f); } + template <typename... Ref> + void fun(std::function<void(Ref...)> const & f) { val(voidtoret(f)); } + template <typename... Ref> + void fget(ref const & type) { return self.template vget<std::function<ref(Ref...)>>(type); } + template <typename... Ref> + void fset(ref const & type, std::function<ref(Ref...)> f) { self.vset(type, f); } + template <typename... Ref> + void fset(ref const & type, std::function<void(Ref...)> f) { fset(type, voidtoret(f)); } + + template <typename... Ref> + ref operator()(Ref... args) { return self.template fun<Ref...>()(args...); } + std::string dump(ref skipmarkertype, ref skipmarkertarget); + +private: + template <typename... Refs> + std::function<ref(Refs...)> voidtoret(std::function<void(Refs...)> f) + { + return [f](Refs... args) -> ref + { + std::initializer_list<ref const *>({&args...}); + f(args...); + return concepts::nothing; + }; + } }; } |