commit 03316cc81ea9eb5b9d2289f0c7b452628f4bd233
parent 92af5e8e4c3614880d5fd51b0e030b6bfe9a952b
Author: phoebos <ben@bvnf.space>
Date: Mon, 10 Oct 2022 18:08:40 +0100
move p to join other ops
Diffstat:
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/baddc.c b/baddc.c
@@ -64,6 +64,11 @@ int stack_len(void) {
return 1 + (stackp - stack);
}
+void view_top(void) {
+ RETURN_IF_FEWER_THAN(1);
+ oprint(peek());
+}
+
void view_stack(void) {
for (int *p = stackp; p - stack >= 0; p--)
oprint(*p);
@@ -168,6 +173,7 @@ struct {
char op;
void (*f)(void);
} ops[] = {
+ { 'p', view_top },
{ 'f', view_stack },
{ 'd', duplicate },
{ 'c', clear },
@@ -231,11 +237,6 @@ int main(int argc, char **argv) {
continue;
} if (isdigit(buf[i])) {
push(buf[i] - '0');
- } else if (buf[i] == 'p') {
- if (stack_len() < 1)
- fprintf(stderr, "stack too short!\n");
- else
- oprint(peek());
} else {
for (size_t j = 0; j < NUM_OPS; j++) {
if (buf[i] == ops[j].op) {