From eeca88e98212d7b61253b4be5f4ebb2f4b36e770 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 29 May 2023 16:04:01 -0400 Subject: feat: tuck and clearstack commands --- optable.c | 15 ++++++++++++--- stack.c | 4 ++++ stack.h | 2 ++ 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 -- cgit v1.2.3