aboutsummaryrefslogtreecommitdiffstats
path: root/optable.c
diff options
context:
space:
mode:
authordan <[email protected]>2023-05-30 18:23:54 -0400
committerdan <[email protected]>2023-05-30 18:23:54 -0400
commit24272d599e1886a8fb47e3e47d33a0aa7dd74e22 (patch)
tree3105c1638ff0bb909dff1023102a8e0fe809c83c /optable.c
parent66d61a5546e5e0173f92e941ab489a1c6474473e (diff)
downloadforth-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.c32
1 files changed, 20 insertions, 12 deletions
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) {