copy/paste caused some issues here
[swfdec.git] / libswfdec / swfdec_as_stack.h
blob7fc544c64670a2212ace98efe56e788a337e805c
1 /* Swfdec
2 * Copyright (C) 2007 Benjamin Otte <otte@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
20 #ifndef _SWFDEC_AS_STACK_H_
21 #define _SWFDEC_AS_STACK_H_
23 #include <libswfdec/swfdec_as_types.h>
25 G_BEGIN_DECLS
27 struct _SwfdecAsStack {
28 guint n_elements; /* number of elements */
29 guint used_elements; /* elements in use (only set on stored stack) */
30 SwfdecAsStack * next; /* pointer to next stack */
31 SwfdecAsValue elements[0]; /* the elements */
34 gboolean swfdec_as_stack_push_segment (SwfdecAsContext * context);
35 void swfdec_as_stack_pop_segment (SwfdecAsContext * context);
37 //#define SWFDEC_MAD_CHECKS
38 #ifdef SWFDEC_MAD_CHECKS
39 #define swfdec_as_stack_peek(cx,n) (&(cx)->cur[-(gssize)(n)])
41 static inline SwfdecAsValue *
42 swfdec_as_stack_pop (SwfdecAsContext *cx)
44 g_assert (stack != NULL);
45 g_assert (cx->cur > cx->base);
47 return --cx->cur;
50 static inline SwfdecAsValue *
51 swfdec_as_stack_pop_n (SwfdecAsContext *cx, guint n)
53 g_assert (cx != NULL);
54 g_assert ((guint) (cx->cur - cx->base) >= n);
56 return cx->cur -= n;
59 static inline SwfdecAsValue *
60 swfdec_as_stack_push (SwfdecAsContext *cx)
62 g_assert (cx != NULL);
63 g_assert (cx->cur < cx->end);
65 return cx->cur++;
67 #else /* SWFDEC_MAD_CHECKS */
68 #define swfdec_as_stack_peek(cx,n) (&(cx)->cur[-(gssize)(n)])
69 #define swfdec_as_stack_pop(cx) (--(cx)->cur)
70 #define swfdec_as_stack_pop_n(cx, n) ((cx)->cur -= (n))
71 #define swfdec_as_stack_push(cx) ((cx)->cur++)
72 #endif
73 #define swfdec_as_stack_swap(cx,x,y) G_STMT_START { \
74 SwfdecAsContext *__cx = (cx); \
75 SwfdecAsValue __tmp; \
76 guint __x = (x), __y = (y); \
77 __tmp = *swfdec_as_stack_peek(__cx, __x); \
78 *swfdec_as_stack_peek(__cx, __x) = *swfdec_as_stack_peek(__cx, __y); \
79 *swfdec_as_stack_peek(__cx, __y) = __tmp; \
80 }G_STMT_END
82 void swfdec_as_stack_mark (SwfdecAsStack * stack);
83 void swfdec_as_stack_ensure_size (SwfdecAsContext * context,
84 guint n_elements);
85 void swfdec_as_stack_ensure_free (SwfdecAsContext * context,
86 guint n_elements);
87 guint swfdec_as_stack_get_size (SwfdecAsContext * context);
90 G_END_DECLS
91 #endif