diff options
author | dan <[email protected]> | 2023-05-30 18:23:54 -0400 |
---|---|---|
committer | dan <[email protected]> | 2023-05-30 18:23:54 -0400 |
commit | 24272d599e1886a8fb47e3e47d33a0aa7dd74e22 (patch) | |
tree | 3105c1638ff0bb909dff1023102a8e0fe809c83c /optable.c | |
parent | 66d61a5546e5e0173f92e941ab489a1c6474473e (diff) | |
download | forth-24272d599e1886a8fb47e3e47d33a0aa7dd74e22.tar.gz forth-24272d599e1886a8fb47e3e47d33a0aa7dd74e22.tar.bz2 forth-24272d599e1886a8fb47e3e47d33a0aa7dd74e22.zip |
feat: web version also uses c code, compiled to wasm
Diffstat (limited to 'optable.c')
-rw-r--r-- | optable.c | 32 |
1 files changed, 20 insertions, 12 deletions
@@ -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) { |