aboutsummaryrefslogtreecommitdiffstats
path: root/support.c
diff options
context:
space:
mode:
Diffstat (limited to 'support.c')
-rw-r--r--support.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/support.c b/support.c
index 44b4583..b400a05 100644
--- a/support.c
+++ b/support.c
@@ -40,32 +40,39 @@ void eq()
st[sp - 1] = st[sp - 1] == st[sp];
}
-void cons()
+void alloc()
+{
+ int32_t *st = &stack;
+ st[sp - 1] = (int32_t)malloc(st[sp - 1] * sizeof(int32_t));
+}
+
+void dealloc()
{
int32_t *st = &stack;
- int32_t *pair = (int32_t *)malloc(2 * sizeof(int32_t));
--sp;
- pair[0] = st[sp];
- pair[1] = st[sp - 1];
- st[sp - 1] = (int32_t)pair;
+ free((int32_t *)st[sp]);
}
-void car()
+void peek()
{
int32_t *st = &stack;
- st[sp - 1] = ((int32_t *)st[sp - 1])[0];
+ st[sp - 1] = *(int32_t *)st[sp - 1];
}
-void cdr()
+void poke()
{
int32_t *st = &stack;
- st[sp - 1] = ((int32_t *)st[sp - 1])[1];
+ sp -= 2;
+ int32_t *ptr = (int32_t *)st[sp + 1];
+ *ptr = st[sp];
}
-void decons()
+void dumpstack()
{
int32_t *st = &stack;
- --sp;
- free((int32_t *)st[sp]);
+ printf("<stack> ");
+ for (int i = 0; i < sp; ++i)
+ printf("%d ", st[i]);
+ putchar('\n');
}