aboutsummaryrefslogtreecommitdiff
path: root/sloth.c
diff options
context:
space:
mode:
Diffstat (limited to 'sloth.c')
-rw-r--r--sloth.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/sloth.c b/sloth.c
index 7c861c8..500c327 100644
--- a/sloth.c
+++ b/sloth.c
@@ -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;
}