diff options
author | dan <[email protected]> | 2023-05-29 16:04:01 -0400 |
---|---|---|
committer | dan <[email protected]> | 2023-05-29 16:04:01 -0400 |
commit | eeca88e98212d7b61253b4be5f4ebb2f4b36e770 (patch) | |
tree | d3384cfeec663c2e79574dbf8b9cc9a08ff6b8de | |
parent | 41b4e2123260eed2aab5ab76d42f106c73ec6bf2 (diff) | |
download | forth-eeca88e98212d7b61253b4be5f4ebb2f4b36e770.tar.gz forth-eeca88e98212d7b61253b4be5f4ebb2f4b36e770.tar.bz2 forth-eeca88e98212d7b61253b4be5f4ebb2f4b36e770.zip |
feat: tuck and clearstack commands
-rw-r--r-- | optable.c | 15 | ||||
-rw-r--r-- | stack.c | 4 | ||||
-rw-r--r-- | stack.h | 2 |
3 files changed, 18 insertions, 3 deletions
@@ -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++; @@ -77,3 +77,7 @@ void stack_pick(stack *s) { stack_push(s, 0); } } + +void stack_clear(stack* s) { + s->size = 0; +} @@ -29,4 +29,6 @@ void stack_roll(stack *s); void stack_pick(stack *s); +void stack_clear(stack *s); + #endif |