summaryrefslogtreecommitdiff
path: root/starts/meaning-vm/level-2
diff options
context:
space:
mode:
authorolpc user <olpc@xo-5d-f7-86.localdomain>2019-12-08 07:05:40 -0800
committerolpc user <olpc@xo-5d-f7-86.localdomain>2019-12-08 07:05:40 -0800
commit65c656eb18216d54d753df2a62eb6d2f5eaa0edc (patch)
treeb46eb1b692484ab299d23c27f2dcd973a44df3db /starts/meaning-vm/level-2
parent866a37a12e722f4aa89df56d05ac8666c308a63d (diff)
downloadstandingwithresilience-65c656eb18216d54d753df2a62eb6d2f5eaa0edc.tar.gz
standingwithresilience-65c656eb18216d54d753df2a62eb6d2f5eaa0edc.zip
move habit macro into level-2
Diffstat (limited to 'starts/meaning-vm/level-2')
-rw-r--r--starts/meaning-vm/level-2/level-2.hpp3
-rw-r--r--starts/meaning-vm/level-2/sugar.hpp29
2 files changed, 32 insertions, 0 deletions
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 <stdlib.h> // int rand(); void srand(int seed);
+#include <time.h> // int time(0); int clock_gettime(CLOCK_REALTIME, struct timespec *tp{tv_sec,tv_nsec})
+#include <unistd.h> // 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(ref)>) \
+ [=](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);
+}