diff options
author | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-12-09 03:13:14 -0800 |
---|---|---|
committer | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-12-09 03:13:14 -0800 |
commit | 584ca7f9b6fca6da54608d3b28274273b2c9a4b8 (patch) | |
tree | d553b549cf246ddb24c93f9a95467bf9e019c052 | |
parent | 8d238e65a88502b897f1944b7844afffdbc0d761 (diff) | |
download | standingwithresilience-584ca7f9b6fca6da54608d3b28274273b2c9a4b8.tar.gz standingwithresilience-584ca7f9b6fca6da54608d3b28274273b2c9a4b8.zip |
make level-2 have refs
-rw-r--r-- | starts/meaning-vm/habit-starts/common.hpp | 10 | ||||
-rw-r--r-- | starts/meaning-vm/habit-starts/rhythm.cpp | 5 | ||||
-rw-r--r-- | starts/meaning-vm/level-0/baseref.hpp | 4 | ||||
-rw-r--r-- | starts/meaning-vm/level-0/common.hpp | 15 | ||||
-rw-r--r-- | starts/meaning-vm/level-1/sugar.hpp | 2 | ||||
-rw-r--r-- | starts/meaning-vm/level-2/baseref.hpp | 25 | ||||
-rw-r--r-- | starts/meaning-vm/level-2/common.hpp | 1 | ||||
-rw-r--r-- | starts/meaning-vm/level-2/concepts.hpp | 15 | ||||
-rw-r--r-- | starts/meaning-vm/level-2/funcs.cpp | 15 | ||||
-rw-r--r-- | starts/meaning-vm/level-2/funcs.hpp | 11 | ||||
-rw-r--r-- | starts/meaning-vm/level-2/level-2.hpp | 3 | ||||
-rw-r--r-- | starts/meaning-vm/level-2/ref.hpp | 15 | ||||
-rw-r--r-- | starts/meaning-vm/level-2/sugar.hpp | 21 |
13 files changed, 132 insertions, 10 deletions
diff --git a/starts/meaning-vm/habit-starts/common.hpp b/starts/meaning-vm/habit-starts/common.hpp new file mode 100644 index 0000000..963bbea --- /dev/null +++ b/starts/meaning-vm/habit-starts/common.hpp @@ -0,0 +1,10 @@ +#pragma once + +#include "../level-1/level-1.hpp" +#include "../level-2/level-2.hpp" + +namespace habitstarts { + +decl(habit); + +} diff --git a/starts/meaning-vm/habit-starts/rhythm.cpp b/starts/meaning-vm/habit-starts/rhythm.cpp index d5b2161..33e102a 100644 --- a/starts/meaning-vm/habit-starts/rhythm.cpp +++ b/starts/meaning-vm/habit-starts/rhythm.cpp @@ -8,14 +8,13 @@ #include <iostream> -using namespace intellect::level1; +using namespace intellect::level2; int main() { - srand(time(0)); - int micros = 400000 + double(rand()) / RAND_MAX * 400000; // do something, wait a constant (secret) time, and do it again. + int micros = 400000 + double(rand()) / RAND_MAX * 400000; // the time things take is usually not known in advance, especially // for events one is still learning about. diff --git a/starts/meaning-vm/level-0/baseref.hpp b/starts/meaning-vm/level-0/baseref.hpp index 068ccfa..fbb7a28 100644 --- a/starts/meaning-vm/level-0/baseref.hpp +++ b/starts/meaning-vm/level-0/baseref.hpp @@ -74,6 +74,10 @@ public: operator level3::ref &() { return *reinterpret_cast<level3::ref*>(this); } operator level4::ref &() { return *reinterpret_cast<level4::ref*>(this); } operator level5::ref &() { return *reinterpret_cast<level5::ref*>(this); } + operator level6::ref &() { return *reinterpret_cast<level6::ref*>(this); } + operator level7::ref &() { return *reinterpret_cast<level7::ref*>(this); } + operator level8::ref &() { return *reinterpret_cast<level8::ref*>(this); } + operator level9::ref &() { return *reinterpret_cast<level9::ref*>(this); } bool operator==(ref const & other) const { return self.p == other.p; } bool operator!=(ref const & other) const { return self.p == other.p; } diff --git a/starts/meaning-vm/level-0/common.hpp b/starts/meaning-vm/level-0/common.hpp index 613028d..e06e478 100644 --- a/starts/meaning-vm/level-0/common.hpp +++ b/starts/meaning-vm/level-0/common.hpp @@ -28,9 +28,14 @@ struct concept; struct ref; } -namespace level1 { struct ref; template <typename> struct vref; } -namespace level2 { struct ref; template <typename> struct vref; } -namespace level3 { struct ref; template <typename> struct vref; } -namespace level4 { struct ref; template <typename> struct vref; } -namespace level5 { struct ref; template <typename> struct vref; } +namespace level1 { struct ref; } +namespace level2 { struct ref; } +namespace level3 { struct ref; } +namespace level4 { struct ref; } +namespace level5 { struct ref; } +namespace level6 { struct ref; } +namespace level7 { struct ref; } +namespace level8 { struct ref; } +namespace level9 { struct ref; } + } diff --git a/starts/meaning-vm/level-1/sugar.hpp b/starts/meaning-vm/level-1/sugar.hpp index 240f768..dd62476 100644 --- a/starts/meaning-vm/level-1/sugar.hpp +++ b/starts/meaning-vm/level-1/sugar.hpp @@ -22,7 +22,7 @@ namespace internal { void init_ref_names(std::string names, T &... refrefs) { std::stringstream ss(names); - ref* refptrs[] = {&refrefs...}; + ref* refptrs[] = {&static_cast<ref&>(refrefs)...}; for (std::size_t i = 0; i < sizeof...(refrefs); ++ i) { std::string name; ss >> name; diff --git a/starts/meaning-vm/level-2/baseref.hpp b/starts/meaning-vm/level-2/baseref.hpp new file mode 100644 index 0000000..c2bc0d1 --- /dev/null +++ b/starts/meaning-vm/level-2/baseref.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include "common.hpp" + +#include "funcs.hpp" + +#include "../level-1/common.hpp" + +#include <functional> + +namespace intellect { +namespace level2 { + +template <typename ref> +struct baseref : public level1::baseref<ref> +{ + using level1::template baseref<ref>::baseref; + + // thread-local context + static ref context() { return level2::context(); } + +}; + +} +} diff --git a/starts/meaning-vm/level-2/common.hpp b/starts/meaning-vm/level-2/common.hpp new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/starts/meaning-vm/level-2/common.hpp @@ -0,0 +1 @@ +#pragma once diff --git a/starts/meaning-vm/level-2/concepts.hpp b/starts/meaning-vm/level-2/concepts.hpp new file mode 100644 index 0000000..a8cfb0d --- /dev/null +++ b/starts/meaning-vm/level-2/concepts.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include "ref.hpp" + +namespace intellect { +namespace level2 { + +namespace concepts { + +static ref context("context"); + +} + +} +} diff --git a/starts/meaning-vm/level-2/funcs.cpp b/starts/meaning-vm/level-2/funcs.cpp new file mode 100644 index 0000000..4ee02a4 --- /dev/null +++ b/starts/meaning-vm/level-2/funcs.cpp @@ -0,0 +1,15 @@ +#include "funcs.hp" + +#include "../level-1/sugar.hpp" + +namespace intellect { +namespace level2 { + +level2::ref context() +{ + static thread_local level1::ref ctx = level1::a("context"); + return ctx; +} + +} +} diff --git a/starts/meaning-vm/level-2/funcs.hpp b/starts/meaning-vm/level-2/funcs.hpp new file mode 100644 index 0000000..52c041d --- /dev/null +++ b/starts/meaning-vm/level-2/funcs.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "common.hpp" + +namespace intellect { +namespace level2 { + +ref context(); + +} +} diff --git a/starts/meaning-vm/level-2/level-2.hpp b/starts/meaning-vm/level-2/level-2.hpp index 29ab89e..7c7dd9a 100644 --- a/starts/meaning-vm/level-2/level-2.hpp +++ b/starts/meaning-vm/level-2/level-2.hpp @@ -1,3 +1,6 @@ #pragma once +#include "common.hpp" +#include "concepts.hpp" #include "sugar.hpp" +#include "ref.hpp" diff --git a/starts/meaning-vm/level-2/ref.hpp b/starts/meaning-vm/level-2/ref.hpp new file mode 100644 index 0000000..7a2d58d --- /dev/null +++ b/starts/meaning-vm/level-2/ref.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include "common.hpp" +#include "baseref.hpp" + +namespace intellect { +namespace level2 { + +struct ref : public baseref<ref> +{ + using baseref<ref>::baseref; +}; + +} +} diff --git a/starts/meaning-vm/level-2/sugar.hpp b/starts/meaning-vm/level-2/sugar.hpp index 2fa9414..3e94c97 100644 --- a/starts/meaning-vm/level-2/sugar.hpp +++ b/starts/meaning-vm/level-2/sugar.hpp @@ -12,7 +12,7 @@ #define ahabit(name, ...) \ a(habit, name); \ (name).fun((std::function<ref(ref)>) \ - [=](ref ctx) \ + [=](ref ctx) -> ref\ { \ habitdelay; \ ref self = name; \ @@ -21,6 +21,25 @@ return intellect::level1::concepts::nothing; \ }); +// thinking on handling arguments with less boilerplate, more positional sugar +// transfer argslist to a context for calling? +// possibly transfer argslist to a function signature for the call +// transfer context to the argslist for handling call +// for each item of argslist, make a local variable, and set it to its value +/* +#define _positionalhabitarg(local, arg) \ + ref local = ctx.get(arg); +#define _ph + +#define apositionalhabit(name, argslist, ...) \ + a(habit, name); \ + (name).fun((std::function<ref(ref)>) \ + [=](ref ctx) \ + { \ + \ + }); +*/ + // seed random number generator statically, for habitdelay namespace __internal { static struct timespec __tp; |