aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordan <[email protected]>2023-05-29 16:04:01 -0400
committerdan <[email protected]>2023-05-29 16:04:01 -0400
commiteeca88e98212d7b61253b4be5f4ebb2f4b36e770 (patch)
treed3384cfeec663c2e79574dbf8b9cc9a08ff6b8de
parent41b4e2123260eed2aab5ab76d42f106c73ec6bf2 (diff)
downloadforth-eeca88e98212d7b61253b4be5f4ebb2f4b36e770.tar.gz
forth-eeca88e98212d7b61253b4be5f4ebb2f4b36e770.tar.bz2
forth-eeca88e98212d7b61253b4be5f4ebb2f4b36e770.zip
feat: tuck and clearstack commands
-rw-r--r--optable.c15
-rw-r--r--stack.c4
-rw-r--r--stack.h2
3 files changed, 18 insertions, 3 deletions
diff --git a/optable.c b/optable.c
index 8bbca07..ffc4d83 100644
--- a/optable.c
+++ b/optable.c
@@ -55,10 +55,11 @@ static wordop optable[OPTABLE_MAX_SIZE] = {
{"then", builtin, {donothing}},
{"depth", builtin, {depth}},
{".s", builtin, {stack_printall}},
+ {"clearstack", builtin, {stack_clear}},
{"if", directive, {ifdirective}},
{":", directive, {defineop}},
};
-static int optablelen = 25;
+static int optablelen = 26;
#pragma clang diagnostic pop
compileditem* compilewords(int len, char** script) {
@@ -87,13 +88,21 @@ void optable_init() {
optable[optablelen].oplist = oplist;
optablelen++;
+ optable[optablelen].word = "tuck";
+ optable[optablelen].optype = compiled;
+ oplistlen = 3;
+ optable[optablelen].oplistlen = oplistlen;
+ char* ws2[] = {"dup", "rot", "rot"};
+ oplist = compilewords(oplistlen, ws2);
+ optable[optablelen].oplist = oplist;
+ optablelen++;
optable[optablelen].word = "incr";
optable[optablelen].optype = compiled;
oplistlen = 2;
optable[optablelen].oplistlen = oplistlen;
- char* ws2[] = {"1", "+"};
- oplist = compilewords(2, ws2);
+ char* ws3[] = {"1", "+"};
+ oplist = compilewords(2, ws3);
optable[optablelen].oplist = oplist;
optablelen++;
diff --git a/stack.c b/stack.c
index e1f0281..0fe7235 100644
--- a/stack.c
+++ b/stack.c
@@ -77,3 +77,7 @@ void stack_pick(stack *s) {
stack_push(s, 0);
}
}
+
+void stack_clear(stack* s) {
+ s->size = 0;
+}
diff --git a/stack.h b/stack.h
index 30dc49c..3bc308c 100644
--- a/stack.h
+++ b/stack.h
@@ -29,4 +29,6 @@ void stack_roll(stack *s);
void stack_pick(stack *s);
+void stack_clear(stack *s);
+
#endif