From 65c656eb18216d54d753df2a62eb6d2f5eaa0edc Mon Sep 17 00:00:00 2001 From: olpc user Date: Sun, 8 Dec 2019 07:05:40 -0800 Subject: move habit macro into level-2 --- starts/meaning-vm/habit-starts/habit.hpp | 23 ----------------------- starts/meaning-vm/habit-starts/rhythm.cpp | 3 +-- starts/meaning-vm/level-2/level-2.hpp | 3 +++ starts/meaning-vm/level-2/sugar.hpp | 29 +++++++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 25 deletions(-) delete mode 100644 starts/meaning-vm/habit-starts/habit.hpp create mode 100644 starts/meaning-vm/level-2/level-2.hpp create mode 100644 starts/meaning-vm/level-2/sugar.hpp (limited to 'starts/meaning-vm') diff --git a/starts/meaning-vm/habit-starts/habit.hpp b/starts/meaning-vm/habit-starts/habit.hpp deleted file mode 100644 index 5c6f5e8..0000000 --- a/starts/meaning-vm/habit-starts/habit.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include // int rand(); void srand(int seed); -#include // int time(0); -#include // usleep(unsigned int usecs) - -__attribute__ ((visibility ("hidden"))) int __seed = (srand(time(0)), time(0)); -#define habitdelay \ - static int thisdelay = (double(rand()) / RAND_MAX * 400000 + 200000); \ - usleep(thisdelay) - -#undef self -#define ahabit(name, ...) \ - a(habit, name); \ - (name).fun((std::function) \ - [=](ref ctx) \ - { \ - habitdelay; \ - ref self = name; \ - (void)self; \ - __VA_ARGS__ \ - return intellect::level1::concepts::nothing; \ - }); diff --git a/starts/meaning-vm/habit-starts/rhythm.cpp b/starts/meaning-vm/habit-starts/rhythm.cpp index 3085da0..56172e8 100644 --- a/starts/meaning-vm/habit-starts/rhythm.cpp +++ b/starts/meaning-vm/habit-starts/rhythm.cpp @@ -4,7 +4,7 @@ // Ideally, a human would run the rhythm. #include "../level-1/level-1.hpp" -#include "habit.hpp" +#include "../level-2/level-2.hpp" #include @@ -121,7 +121,6 @@ int main() }); ahabit(wait-habit, { - habitdelay; usleep(micros); }); diff --git a/starts/meaning-vm/level-2/level-2.hpp b/starts/meaning-vm/level-2/level-2.hpp new file mode 100644 index 0000000..29ab89e --- /dev/null +++ b/starts/meaning-vm/level-2/level-2.hpp @@ -0,0 +1,3 @@ +#pragma once + +#include "sugar.hpp" diff --git a/starts/meaning-vm/level-2/sugar.hpp b/starts/meaning-vm/level-2/sugar.hpp new file mode 100644 index 0000000..2fa9414 --- /dev/null +++ b/starts/meaning-vm/level-2/sugar.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include // int rand(); void srand(int seed); +#include // int time(0); int clock_gettime(CLOCK_REALTIME, struct timespec *tp{tv_sec,tv_nsec}) +#include // usleep(unsigned int usecs) + +#define habitdelay \ + static int thisdelay = (double(rand()) / RAND_MAX * 400000 + 200000); \ + usleep(thisdelay) + +#undef self +#define ahabit(name, ...) \ + a(habit, name); \ + (name).fun((std::function) \ + [=](ref ctx) \ + { \ + habitdelay; \ + ref self = name; \ + (void)self; \ + __VA_ARGS__ \ + return intellect::level1::concepts::nothing; \ + }); + +// seed random number generator statically, for habitdelay +namespace __internal { +static struct timespec __tp; +static int __timeres = clock_gettime(CLOCK_REALTIME, &__tp); +static int __seed = (srand(__tp.tv_nsec), __tp.tv_nsec); +} -- cgit v1.2.3