diff options
author | kdx <kikoodx@paranoici.org> | 2023-01-14 21:24:47 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-01-14 21:24:47 +0100 |
commit | 49aeb9687849941d73e63669ff1313295e22af76 (patch) | |
tree | 956b7d8316c2377dcb29d9db7bfdd540a3ed43ad | |
parent | 37b650f1ea6086de77c8a46294cd04c35bcf0e02 (diff) | |
download | sloth-49aeb9687849941d73e63669ff1313295e22af76.tar.gz |
stdlib bs
-rw-r--r-- | README | 1 | ||||
-rw-r--r-- | sloth.c | 26 | ||||
-rw-r--r-- | sloth.h | 3 | ||||
-rw-r--r-- | stdlib | 6 |
4 files changed, 34 insertions, 2 deletions
@@ -15,6 +15,7 @@ supports string literal (array of bytes) + ( a b -- c ) < ( a b -- c ) . ( a -- ) +neg ( a -- b ) implementation of usually built-in features @@ -33,6 +33,11 @@ SlothError sloth_init(Sloth *ctx) sloth_deinit(ctx); return err; } + err = sloth_dict_append(ctx, SLOTH_DICT_C("neg", sloth_neg)); + if (err != NULL) { + sloth_deinit(ctx); + return err; + } err = sloth_dict_append(ctx, SLOTH_DICT_C(":", sloth_compile_begin)); if (err != NULL) { sloth_deinit(ctx); @@ -43,6 +48,11 @@ SlothError sloth_init(Sloth *ctx) sloth_deinit(ctx); return err; } + err = sloth_dict_append(ctx, SLOTH_DICT_C(".t", sloth_inspect_stack)); + if (err != NULL) { + sloth_deinit(ctx); + return err; + } return NULL; } @@ -283,6 +293,19 @@ SlothError sloth_compare(Sloth *ctx) return NULL; } +SlothError sloth_neg(Sloth *ctx) +{ + SlothError err; + SlothByte a; + err = sloth_pop(ctx, &a); + if (err != NULL) + return err; + err = sloth_push(ctx, -a); + if (err != NULL) + return err; + return NULL; +} + SlothError sloth_compile_begin(Sloth *ctx) { if (ctx->compile) @@ -311,9 +334,10 @@ SlothError sloth_compile_end(Sloth *ctx) return NULL; } -void sloth_inspect_stack(const Sloth *ctx) +SlothError sloth_inspect_stack(Sloth *ctx) { printf("<%lu> ", ctx->stack_size); for (size_t i = 0; i < ctx->stack_size; i++) printf("%d ", ctx->stack[i]); + return NULL; } @@ -55,6 +55,7 @@ SlothError sloth_write(Sloth *ctx); SlothError sloth_store(Sloth *ctx); SlothError sloth_retrieve(Sloth *ctx); SlothError sloth_compare(Sloth *ctx); +SlothError sloth_neg(Sloth *ctx); SlothError sloth_compile_begin(Sloth *ctx); SlothError sloth_compile_end(Sloth *ctx); -void sloth_inspect_stack(const Sloth *ctx); +SlothError sloth_inspect_stack(Sloth *ctx); @@ -0,0 +1,6 @@ +: dup 0 @ 0 ! 0 ! ; +: drop 0 @ ; +: swap 0 @ 1 @ 0 ! 1 ! ; +: - neg + ; +: not 1 swap - ; +: = - not ; |