From 680af2ca0b1ced4c82bbce620d6c4fc97dae88d0 Mon Sep 17 00:00:00 2001 From: olpc user Date: Thu, 5 Dec 2019 04:12:23 -0800 Subject: add function syntaxes --- starts/meaning-vm/level-1/baseref.hpp | 33 +++++++++++++++++++++++++++++++++ starts/meaning-vm/level-1/common.hpp | 2 ++ starts/meaning-vm/level-1/concepts.hpp | 1 - 3 files changed, 35 insertions(+), 1 deletion(-) (limited to 'starts/meaning-vm/level-1') 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 + namespace intellect { namespace level1 { @@ -27,7 +29,38 @@ struct baseref : public level0::baseref ref operator-(ref other) { return hyphenate(self.ptr(), other.ptr()); } + template + void vset(ref const & type, T const & v) { self.set(type, level1::alloc(v)); } + + template + std::function & fun() { return self.template val>(); } + template + void fun(std::function const & f) { val(f); } + template + void fun(std::function const & f) { val(voidtoret(f)); } + template + void fget(ref const & type) { return self.template vget>(type); } + template + void fset(ref const & type, std::function f) { self.vset(type, f); } + template + void fset(ref const & type, std::function f) { fset(type, voidtoret(f)); } + + template + ref operator()(Ref... args) { return self.template fun()(args...); } + std::string dump(ref skipmarkertype, ref skipmarkertarget); + +private: + template + std::function voidtoret(std::function f) + { + return [f](Refs... args) -> ref + { + std::initializer_list({&args...}); + f(args...); + return concepts::nothing; + }; + } }; } diff --git a/starts/meaning-vm/level-1/common.hpp b/starts/meaning-vm/level-1/common.hpp index 73de3b4..5dd2840 100644 --- a/starts/meaning-vm/level-1/common.hpp +++ b/starts/meaning-vm/level-1/common.hpp @@ -10,5 +10,7 @@ using level0::concept; template struct baseref; struct ref; +namespace concepts { extern ref nothing; } + } } diff --git a/starts/meaning-vm/level-1/concepts.hpp b/starts/meaning-vm/level-1/concepts.hpp index 3f49eca..6dfc64b 100644 --- a/starts/meaning-vm/level-1/concepts.hpp +++ b/starts/meaning-vm/level-1/concepts.hpp @@ -1,7 +1,6 @@ #pragma once #include "ref.hpp" -#include "sugar.hpp" namespace intellect { namespace level1 { -- cgit v1.2.3