aboutsummaryrefslogtreecommitdiffstats
path: root/support.c
diff options
context:
space:
mode:
Diffstat (limited to 'support.c')
-rw-r--r--support.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/support.c b/support.c
index cc0304f..44a39e4 100644
--- a/support.c
+++ b/support.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdint.h>
+#include <stdlib.h>
extern int32_t sp;
extern int32_t stack;
@@ -9,6 +10,11 @@ void emit()
putchar(*(&stack + --sp));
}
+void print()
+{
+ printf("%d\n", *(&stack + --sp));
+}
+
void sub()
{
int32_t *st = &stack;
@@ -33,3 +39,33 @@ void eq()
--sp;
st[sp - 1] = st[sp - 1] == st[sp];
}
+
+void cons()
+{
+ int32_t *st = &stack;
+ int32_t *pair = malloc(2 * sizeof(int32_t));
+ --sp;
+ pair[0] = st[sp];
+ pair[1] = st[sp - 1];
+ st[sp - 1] = (int32_t)pair;
+}
+
+void car()
+{
+ int32_t *st = &stack;
+ st[sp - 1] = ((int32_t *)st[sp - 1])[0];
+}
+
+void cdr()
+{
+ int32_t *st = &stack;
+ st[sp - 1] = ((int32_t *)st[sp - 1])[1];
+}
+
+void decons()
+{
+ int32_t *st = &stack;
+ --sp;
+ free((int32_t *)st[sp]);
+}
+