diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2003-11-04 08:10:07 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2003-11-04 08:10:07 +0000 |
commit | b8d0aaee5832dbe3573e099413c8d983768cbbc5 (patch) | |
tree | 21f3cc09d52f63de73b952f070fdc78953642fc9 /usr.bin/dc/stack.c | |
parent | 504f47951d34b0d731259bc032ba27f595c14046 (diff) |
Duh, a stack machine without swap; implement GNU compatible 'r'
(swap) operator. Prompted by Michael Knudsen <e at molioner dot dk>
Diffstat (limited to 'usr.bin/dc/stack.c')
-rw-r--r-- | usr.bin/dc/stack.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/usr.bin/dc/stack.c b/usr.bin/dc/stack.c index d700b787677..03e2f771369 100644 --- a/usr.bin/dc/stack.c +++ b/usr.bin/dc/stack.c @@ -1,4 +1,4 @@ -/* $OpenBSD: stack.c,v 1.4 2003/10/18 20:34:26 otto Exp $ */ +/* $OpenBSD: stack.c,v 1.5 2003/11/04 08:10:06 otto Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net> @@ -17,7 +17,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: stack.c,v 1.4 2003/10/18 20:34:26 otto Exp $"; +static const char rcsid[] = "$OpenBSD: stack.c,v 1.5 2003/11/04 08:10:06 otto Exp $"; #endif /* not lint */ #include <err.h> @@ -116,6 +116,20 @@ stack_dup(struct stack *stack) stack_push(stack, stack_dup_value(value, ©)); } +void +stack_swap(struct stack *stack) +{ + struct value copy; + + if (stack->sp < 1) { + warnx("stack empty"); + return; + } + copy = stack->stack[stack->sp]; + stack->stack[stack->sp] = stack->stack[stack->sp-1]; + stack->stack[stack->sp-1] = copy; +} + static void stack_grow(struct stack *stack) { |