diff options
author | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-12-07 17:14:57 -0800 |
---|---|---|
committer | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-12-07 17:14:57 -0800 |
commit | 5295068d67545c1149896ccd5ee6a7778a30f671 (patch) | |
tree | 183f5b19e2c55fbe5d3b2cbcb79831c509857989 /starts/meaning-vm/habit-starts/habit.hpp | |
parent | d341a2bbad41fd1def2bf46806fc572744b66533 (diff) | |
download | standingwithresilience-5295068d67545c1149896ccd5ee6a7778a30f671.tar.gz standingwithresilience-5295068d67545c1149896ccd5ee6a7778a30f671.zip |
habit sugar
Diffstat (limited to 'starts/meaning-vm/habit-starts/habit.hpp')
-rw-r--r-- | starts/meaning-vm/habit-starts/habit.hpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/starts/meaning-vm/habit-starts/habit.hpp b/starts/meaning-vm/habit-starts/habit.hpp new file mode 100644 index 0000000..5c6f5e8 --- /dev/null +++ b/starts/meaning-vm/habit-starts/habit.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include <stdlib.h> // int rand(); void srand(int seed); +#include <time.h> // int time(0); +#include <unistd.h> // 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(ref)>) \ + [=](ref ctx) \ + { \ + habitdelay; \ + ref self = name; \ + (void)self; \ + __VA_ARGS__ \ + return intellect::level1::concepts::nothing; \ + }); |