summaryrefslogtreecommitdiff
path: root/starts/meaning-vm/level-2/sugar.hpp
blob: 6734eae9327291b72710da848723d782bb017a8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#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<void()>) \
	[=]() -> ref\
	{ \
		habitdelay; \
		ref self = name; (void)self; \
		ref ctx = intellect::level2::ref::context(); (void) ctx;\
		__VA_ARGS__ \
		return intellect::level1::concepts::nothing; \
	});

// thinking on handling arguments with less boilerplate, more positional sugar
// transfer argslist to a context for calling?
// possibly transfer argslist to a function signature for the call
// transfer context to the argslist for handling call
// for each item of argslist, make a local variable, and set it to its value
/*
#define _positionalhabitarg(local, arg) \
	ref local = ctx.get(arg);
#define _ph

#define apositionalhabit(name, argslist, ...) \
	a(habit, name); \
	(name).fun((std::function<ref(ref)>) \
	[=](ref ctx) \
	{ \
		\
	});
*/

// 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);
}