embed icon indicating copy to clipboard operation
embed copied to clipboard

push before eval gets lost

Open ghost opened this issue 3 years ago • 3 comments

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;
}

ghost avatar Jul 07 '22 20:07 ghost

Ah yes, I got an email about this, and I don't have time to investigate unfortunately as I have way too much going one and I can't resolve it in half an hour, but it appears to be a valid issue. Do you have the IRC logs?

howerj avatar Jul 07 '22 20:07 howerj

There is a workaround so it's not a very big deal. I just wanted something I could point people to if they run into the same problem (unlikely if they use the embed_vm call).

ghost avatar Jul 07 '22 22:07 ghost

I think one of the unit tests fails if the work around is included, which is why I did not integrate it into eval. Never looked at the cause though.

howerj avatar Jul 08 '22 17:07 howerj