aboutsummaryrefslogtreecommitdiffstats
path: root/optable.c
diff options
context:
space:
mode:
authordan <[email protected]>2023-05-26 14:03:17 -0400
committerdan <[email protected]>2023-05-26 14:03:17 -0400
commit4e26b8c0a1b7fc843741105d57da863997e7284b (patch)
tree3439e39efca784ed34e2e22c9ef98ecd53e785b5 /optable.c
parent1ac1b0c94195be3231a4aaa7335dc2f3a169820c (diff)
downloadforth-4e26b8c0a1b7fc843741105d57da863997e7284b.tar.gz
forth-4e26b8c0a1b7fc843741105d57da863997e7284b.tar.bz2
forth-4e26b8c0a1b7fc843741105d57da863997e7284b.zip
refactor: pop and peek are no longer special cases; remove dump command
Diffstat (limited to 'optable.c')
-rw-r--r--optable.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/optable.c b/optable.c
index fe7409b..d74e2e9 100644
--- a/optable.c
+++ b/optable.c
@@ -1,7 +1,6 @@
#include "optable.h"
#include <string.h>
-static void dump(stack* s);
static void not(stack *s);
static void drop(stack *s);
static void over(stack *s);
@@ -13,14 +12,17 @@ static void mult(stack *s);
static void s_div(stack *s);
static void sub(stack *s);
static void dup(stack *s);
+static void popout(stack *s);
+static void peekout(stack *s);
static wordop optable[OPTABLE_MAX_SIZE] = {
+ {".", false, popout},
+ {"peek", false, peekout},
{"+", false, add},
{"-", false, sub},
{"*", false, mult},
{"/", false, s_div},
{"dup", false, dup},
- {"dump", false, dump},
{"not", false, not},
{"=", false, eq},
{"swap", false, swap},
@@ -28,7 +30,7 @@ static wordop optable[OPTABLE_MAX_SIZE] = {
{"over", false, over},
{"rot", false, rot},
};
-static int optablelen = 12;
+static int optablelen = 13;
int defineop(int starti, char *input) {
// name by which the function will be called
@@ -82,13 +84,6 @@ wordop* getop(char *word) {
/* Implementations of builtin functions */
-static void dump(stack* s) {
- for (int i = 0; i < s->size; i++) {
- printf("%d,", s->start[i]);
- }
- printf("\n");
-}
-
static void not(stack *s) {
int x = pop(s);
push(s, !x);
@@ -157,3 +152,13 @@ static void dup(stack *s) {
push(s, x);
push(s, x);
}
+
+static void popout(stack *s) {
+ printf("%d\n", pop(s));
+}
+
+static void peekout(stack *s) {
+ int x = pop(s);
+ push(s, x);
+ printf("%d\n", x);
+}