-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Labels
Description
putting this on github since someone on ##forth IRC was asking about it
#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <embed.h>
int unix_putch(int ch, void *file);
int
main(void)
{
setvbuf(stdout, (char *) 0, _IONBF, (size_t) 0);
cell_t m[EMBED_CORE_SIZE] = {0};
embed_t h = {.m = m};
embed_default(&h);
embed_opt_t o = embed_opt_default();
o.in = stdin;
o.out = stdout;
o.put = unix_putch;
h.o = o;
// engine "primed" -- this removes the bad condition?
//embed_eval(&h, "\n");
embed_push(&h, 17);
embed_push(&h, 71);
printf("depth %lu == 2\n", embed_depth(&h));
// the + does not happen?? (nor the .s) unless the engine is
// first "primed"?
embed_eval(&h, " .s + .s \n");
cell_t value;
size_t d = embed_depth(&h);
printf("depth %lu == 1%s\n", d, d == 1 ? "" : " ??");
while (d) {
embed_pop(&h, &value);
printf(" %d", value);
d--;
}
putchar('\n');
return 0;
}
int
unix_putch(int ch, void *file)
{
int r = fputc(ch, file);
return r;
}