From 8ceeb5f83f22ed3db06fc02bb23710ccc1dbbb90 Mon Sep 17 00:00:00 2001 From: olpc user Date: Mon, 9 Dec 2019 03:26:04 -0800 Subject: use tls contexts for habits --- starts/meaning-vm/habit-starts/rhythm.cpp | 17 ++++++++--------- starts/meaning-vm/level-2/common.hpp | 9 +++++++++ starts/meaning-vm/level-2/funcs.cpp | 9 ++++++--- starts/meaning-vm/level-2/sugar.hpp | 8 ++++---- starts/meaning-vm/makefile | 4 +++- 5 files changed, 30 insertions(+), 17 deletions(-) (limited to 'starts/meaning-vm') diff --git a/starts/meaning-vm/habit-starts/rhythm.cpp b/starts/meaning-vm/habit-starts/rhythm.cpp index 33e102a..7afb8ed 100644 --- a/starts/meaning-vm/habit-starts/rhythm.cpp +++ b/starts/meaning-vm/habit-starts/rhythm.cpp @@ -34,22 +34,22 @@ int main() #undef self ahabit(next-habit, { - ref n = ctx.get(active-habit).get(next); + ref n = ctx[active-habit].get(next); ctx.set(active-habit, n); - return n(ctx); + return n(); }); ahabit(start-habit, { - ref s = ctx.get(start); + ref s = ctx[start]; ctx.set(active-habit, s); - return s(ctx); + return s(); }); ahabit(keep-doing-habit, { - (start-habit)(ctx); + (start-habit)(); while (true) { - (next-habit)(ctx); + (next-habit)(); } }); @@ -124,7 +124,6 @@ int main() }); - a(context, habit-context); - (habit-context).set(start, start-beat); - (keep-doing-habit)(habit-context); + ref::context().set(start, start-beat); + (keep-doing-habit)(); } diff --git a/starts/meaning-vm/level-2/common.hpp b/starts/meaning-vm/level-2/common.hpp index 6f70f09..aac072e 100644 --- a/starts/meaning-vm/level-2/common.hpp +++ b/starts/meaning-vm/level-2/common.hpp @@ -1 +1,10 @@ #pragma once + +namespace intellect { +namespace level2 { + +template struct baseref; +struct ref; + +} +} diff --git a/starts/meaning-vm/level-2/funcs.cpp b/starts/meaning-vm/level-2/funcs.cpp index 4ee02a4..c25ead2 100644 --- a/starts/meaning-vm/level-2/funcs.cpp +++ b/starts/meaning-vm/level-2/funcs.cpp @@ -1,13 +1,16 @@ -#include "funcs.hp" +#include "funcs.hpp" #include "../level-1/sugar.hpp" +#include "ref.hpp" + namespace intellect { +using namespace level1; namespace level2 { -level2::ref context() +ref context() { - static thread_local level1::ref ctx = level1::a("context"); + static thread_local auto ctx = a("context"); return ctx; } diff --git a/starts/meaning-vm/level-2/sugar.hpp b/starts/meaning-vm/level-2/sugar.hpp index 3e94c97..6734eae 100644 --- a/starts/meaning-vm/level-2/sugar.hpp +++ b/starts/meaning-vm/level-2/sugar.hpp @@ -11,12 +11,12 @@ #undef self #define ahabit(name, ...) \ a(habit, name); \ - (name).fun((std::function) \ - [=](ref ctx) -> ref\ + (name).fun((std::function) \ + [=]() -> ref\ { \ habitdelay; \ - ref self = name; \ - (void)self; \ + ref self = name; (void)self; \ + ref ctx = intellect::level2::ref::context(); (void) ctx;\ __VA_ARGS__ \ return intellect::level1::concepts::nothing; \ }); diff --git a/starts/meaning-vm/makefile b/starts/meaning-vm/makefile index dba9eac..fbb8a57 100644 --- a/starts/meaning-vm/makefile +++ b/starts/meaning-vm/makefile @@ -6,8 +6,10 @@ level0: level0.o liblevel0.a liblevel0.a: $(patsubst %.cpp,%.o,$(wildcard level-0/*.cpp)) level1: level1.o liblevel1.a liblevel1.a: $(patsubst %.cpp,%.o,$(wildcard level-0/*.cpp)) $(patsubst %.cpp,%.o,$(wildcard level-1/*.cpp)) +level2: liblevel2.a +liblevel2.a: $(patsubst %.cpp,%.o,$(wildcard level-0/*.cpp)) $(patsubst %.cpp,%.o,$(wildcard level-1/*.cpp)) $(patsubst %.cpp,%.o,$(wildcard level-2/*.cpp)) -habit-starts/rhythm: habit-starts/rhythm.o liblevel1.a +habit-starts/rhythm: habit-starts/rhythm.o liblevel2.a liblevel%.a: level-%/*.hpp %.a: -- cgit v1.2.3