From 584ca7f9b6fca6da54608d3b28274273b2c9a4b8 Mon Sep 17 00:00:00 2001 From: olpc user Date: Mon, 9 Dec 2019 03:13:14 -0800 Subject: make level-2 have refs --- starts/meaning-vm/level-2/baseref.hpp | 25 +++++++++++++++++++++++++ starts/meaning-vm/level-2/common.hpp | 1 + starts/meaning-vm/level-2/concepts.hpp | 15 +++++++++++++++ starts/meaning-vm/level-2/funcs.cpp | 15 +++++++++++++++ starts/meaning-vm/level-2/funcs.hpp | 11 +++++++++++ starts/meaning-vm/level-2/level-2.hpp | 3 +++ starts/meaning-vm/level-2/ref.hpp | 15 +++++++++++++++ starts/meaning-vm/level-2/sugar.hpp | 21 ++++++++++++++++++++- 8 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 starts/meaning-vm/level-2/baseref.hpp create mode 100644 starts/meaning-vm/level-2/common.hpp create mode 100644 starts/meaning-vm/level-2/concepts.hpp create mode 100644 starts/meaning-vm/level-2/funcs.cpp create mode 100644 starts/meaning-vm/level-2/funcs.hpp create mode 100644 starts/meaning-vm/level-2/ref.hpp (limited to 'starts/meaning-vm/level-2') 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 + +namespace intellect { +namespace level2 { + +template +struct baseref : public level1::baseref +{ + using level1::template baseref::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 +{ + using baseref::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 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 ctx) \ + { \ + \ + }); +*/ + // seed random number generator statically, for habitdelay namespace __internal { static struct timespec __tp; -- cgit v1.2.3