From 12793ac154b8c9b2e9bb8869cb72bbc1a438dc3d Mon Sep 17 00:00:00 2001 From: olpc user Date: Mon, 9 Dec 2019 07:28:10 -0800 Subject: pass context to habits specifically --- starts/meaning-vm/level-2/funcs.cpp | 4 ++-- starts/meaning-vm/level-2/funcs.hpp | 2 +- starts/meaning-vm/level-2/sugar.hpp | 5 ++--- starts/meaning-vm/makefile | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) (limited to 'starts/meaning-vm') diff --git a/starts/meaning-vm/level-2/funcs.cpp b/starts/meaning-vm/level-2/funcs.cpp index b17d221..3c34c41 100644 --- a/starts/meaning-vm/level-2/funcs.cpp +++ b/starts/meaning-vm/level-2/funcs.cpp @@ -17,7 +17,7 @@ ref context() return ctx; } -ref makehabit(ref name, std::initializer_list argnames, std::function code) +ref makehabit(ref name, std::initializer_list argnames, std::function code) { ref habit = level1::a(habit, name); ref posarg = habit; @@ -46,7 +46,7 @@ ref dohabit(ref habit, std::initializer_list args) if (posarg.linked(next-positional-argument)) { throw std::invalid_argument("wrong number of arguments to habit"); } - ref ret = habit.fun<>()(); + ref ret = habit.fun()(ref::context()); posarg = habit; while (posarg.linked(next-positional-argument)) { posarg = posarg[next-positional-argument]; diff --git a/starts/meaning-vm/level-2/funcs.hpp b/starts/meaning-vm/level-2/funcs.hpp index 770ff0a..f32679c 100644 --- a/starts/meaning-vm/level-2/funcs.hpp +++ b/starts/meaning-vm/level-2/funcs.hpp @@ -9,7 +9,7 @@ namespace intellect { namespace level2 { ref context(); -ref makehabit(ref name, std::initializer_list argnames, std::function code); +ref makehabit(ref name, std::initializer_list argnames, std::function code); ref dohabit(ref habit, std::initializer_list args); } diff --git a/starts/meaning-vm/level-2/sugar.hpp b/starts/meaning-vm/level-2/sugar.hpp index 3b0e2c0..e0dfcd9 100644 --- a/starts/meaning-vm/level-2/sugar.hpp +++ b/starts/meaning-vm/level-2/sugar.hpp @@ -24,15 +24,14 @@ intellect::level2::makehabit( \ name, \ {_macro_call(_macro_for_each_parens, _macro_habit_argnameref _macro_comma_remove_parens(argnametoklist))}, \ - (std::function) \ - [=]() \ + (std::function) \ + [=](ref ctx) \ { \ { \ static int delay = (double(rand()) / RAND_MAX * 400000 + 200000); \ usleep(delay); \ } \ ref self = name; (void)self; \ - ref ctx = intellect::level2::ref::context(); (void) ctx;\ _macro_call(_macro_for_each_parens, _macro_habit_set_posarg _macro_comma_remove_parens(argnametoklist)); \ __VA_ARGS__ \ }); diff --git a/starts/meaning-vm/makefile b/starts/meaning-vm/makefile index bd0d2bd..325a07c 100644 --- a/starts/meaning-vm/makefile +++ b/starts/meaning-vm/makefile @@ -15,7 +15,7 @@ habit-starts/rhythm: habit-starts/rhythm.o liblevel2.a $(CXX) $(CXXFLAGS) -c $^ -o $@ %.ii: %.cpp $(CXX) $(CPPFLAGS) $(CXXFLAGS) -E $^ -o $@ -.INTERMEDIATE: $(patsubst %.cpp,%.ii,$(wildcard */*.cpp *.cpp)) +.INTERMEDIATE: $(patsubst %.cpp,%.ii,$(wildcard */*.cpp) $(wildcard *.cpp)) liblevel%.a: level-%/*.hpp %.a: -- cgit v1.2.3