summaryrefslogtreecommitdiff
path: root/src/runtime/c/gu/fun.h
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@gmail.com>2012-01-20 13:41:10 +0000
committerkr.angelov <kr.angelov@gmail.com>2012-01-20 13:41:10 +0000
commit2eee382a62a909d5a3f2f5eda94f30fe68fd5335 (patch)
treeb0b0d513535895f244214aebf6358e172b8dce6d /src/runtime/c/gu/fun.h
parentb9728357126f8b9a6311cca17d9f0dcc2a7bfb9b (diff)
initial import of the C runtime
Diffstat (limited to 'src/runtime/c/gu/fun.h')
-rw-r--r--src/runtime/c/gu/fun.h65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/runtime/c/gu/fun.h b/src/runtime/c/gu/fun.h
new file mode 100644
index 000000000..0004e9923
--- /dev/null
+++ b/src/runtime/c/gu/fun.h
@@ -0,0 +1,65 @@
+#ifndef GU_FUN_H_
+#define GU_FUN_H_
+
+#include <gu/defs.h>
+
+typedef void (*GuFn)();
+typedef void (*GuFn0)(GuFn* clo);
+typedef void (*GuFn1)(GuFn* clo, void* arg1);
+typedef void (*GuFn2)(GuFn* clo, void* arg1, void* arg2);
+
+#define gu_fn(fn_) (&(GuFn){ fn_ })
+
+static inline void
+gu_apply0(GuFn* fn) {
+ (*fn)(fn);
+}
+
+static inline void
+gu_apply1(GuFn* fn, void* arg1) {
+ (*fn)(fn, arg1);
+}
+
+static inline void
+gu_apply2(GuFn* fn, void* arg1, void* arg2) {
+ (*fn)(fn, arg1, arg2);
+}
+
+#define gu_apply(fn_, ...) \
+ ((fn_)->fn((fn_), __VA_ARGS__))
+
+typedef struct GuClo0 GuClo0;
+
+struct GuClo0 {
+ GuFn fn;
+};
+
+typedef struct GuClo1 GuClo1;
+
+struct GuClo1 {
+ GuFn fn;
+ void *env1;
+};
+
+typedef struct GuClo2 GuClo2;
+struct GuClo2 {
+ GuFn fn;
+ void *env1;
+ void *env2;
+};
+
+typedef struct GuClo3 GuClo3;
+struct GuClo3 {
+ GuFn fn;
+ void *env1;
+ void *env2;
+ void *env3;
+};
+
+typedef const struct GuEquality GuEquality;
+
+struct GuEquality {
+ bool (*is_equal)(GuEquality* self, const void* a, const void* b);
+};
+
+#endif // GU_FUN_H_