aboutsummaryrefslogtreecommitdiffstats
path: root/support.c
diff options
context:
space:
mode:
Diffstat (limited to 'support.c')
-rw-r--r--support.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/support.c b/support.c
index e079de6..e513d06 100644
--- a/support.c
+++ b/support.c
@@ -2,8 +2,10 @@
#include <stdint.h>
#include <stdlib.h>
-extern int32_t sp;
-extern int32_t stack;
+#define cell_t int64_t
+
+extern cell_t sp;
+extern cell_t stack;
void emit()
{
@@ -12,22 +14,22 @@ void emit()
void _print()
{
- printf("%d\n", *(&stack + --sp));
+ printf("%ld\n", *(&stack + --sp));
}
void sub()
{
- int32_t *st = &stack;
+ cell_t *st = &stack;
st[sp - 2] -= st[sp - 1];
--sp;
}
void cswap()
{
- int32_t *st = &stack;
+ cell_t *st = &stack;
--sp;
if (st[sp]) {
- int32_t tmp = st[sp - 1];
+ cell_t tmp = st[sp - 1];
st[sp - 1] = st[sp - 2];
st[sp - 2] = tmp;
}
@@ -35,44 +37,44 @@ void cswap()
void eq()
{
- int32_t *st = &stack;
+ cell_t *st = &stack;
--sp;
st[sp - 1] = st[sp - 1] == st[sp];
}
void alloc()
{
- int32_t *st = &stack;
- st[sp - 1] = (int32_t)malloc(st[sp - 1] * sizeof(int32_t));
+ cell_t *st = &stack;
+ st[sp - 1] = (cell_t)malloc(st[sp - 1] * sizeof(cell_t));
}
void dealloc()
{
- int32_t *st = &stack;
+ cell_t *st = &stack;
--sp;
- free((int32_t *)st[sp]);
+ free((cell_t *)st[sp]);
}
void peek()
{
- int32_t *st = &stack;
- st[sp - 1] = *(int32_t *)st[sp - 1];
+ cell_t *st = &stack;
+ st[sp - 1] = *(cell_t *)st[sp - 1];
}
void poke()
{
- int32_t *st = &stack;
+ cell_t *st = &stack;
sp -= 2;
- int32_t *ptr = (int32_t *)st[sp + 1];
+ cell_t *ptr = (cell_t *)st[sp + 1];
*ptr = st[sp];
}
void dumpstack()
{
- int32_t *st = &stack;
+ cell_t *st = &stack;
printf("<stack> ");
for (int i = 0; i < sp; ++i)
- printf("%d ", st[i]);
+ printf("%ld ", st[i]);
putchar('\n');
}