From 24272d599e1886a8fb47e3e47d33a0aa7dd74e22 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 30 May 2023 18:23:54 -0400 Subject: feat: web version also uses c code, compiled to wasm --- optable.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'optable.c') diff --git a/optable.c b/optable.c index efd01e3..de2aab0 100644 --- a/optable.c +++ b/optable.c @@ -201,25 +201,33 @@ static void dup(stack *s) { stack_push(s, x); } +//#ifdef __EMSCRIPTEN__ +int outputline = 0; +char* outputbuffer; +//#endif static void popout(stack *s) { -#ifdef __EMSCRIPTEN__ - sprintf(outputbuffer, "%d\n", stack_pop(s)); - (*outputline)++; -#else - printf("%d\n", stack_pop(s)); -#endif +if (outputbuffer) { + char x[WORD_LEN_LIMIT]; + sprintf(x, "%d\n", stack_pop(s)); + strcat(outputbuffer, x); + outputline++; +} else { + printf("%d\n", stack_pop(s)); +} } static void peekout(stack *s) { int x = stack_pop(s); stack_push(s, x); -#ifdef __EMSCRIPTEN__ - sprintf(outputbuffer, "%d\n", x); - (*outputline)++; -#else - printf("%d\n", x); -#endif +if (outputbuffer) { + char y[WORD_LEN_LIMIT]; + sprintf(y, "%d\n", x); + strcat(outputbuffer, y); + outputline++; +} else { + printf("%d\n", x); +} } static void donothing(stack *s) { -- cgit v1.2.3