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.
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>
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 #include <libswfdec/swfdec_as_context.h>
40 static inline SwfdecAsValue
*
41 swfdec_as_stack_peek (SwfdecAsContext
*cx
, guint n
)
43 g_assert (cx
!= NULL
);
45 g_assert (cx
->cur
- n
>= cx
->base
);
47 return &(cx
)->cur
[-(gssize
)(n
)];
50 static inline SwfdecAsValue
*
51 swfdec_as_stack_pop (SwfdecAsContext
*cx
)
53 g_assert (cx
!= NULL
);
54 g_assert (cx
->cur
> cx
->base
);
59 static inline SwfdecAsValue
*
60 swfdec_as_stack_pop_n (SwfdecAsContext
*cx
, guint n
)
62 g_assert (cx
!= NULL
);
63 g_assert ((guint
) (cx
->cur
- cx
->base
) >= n
);
68 static inline SwfdecAsValue
*
69 swfdec_as_stack_push (SwfdecAsContext
*cx
)
71 g_assert (cx
!= NULL
);
72 g_assert (cx
->cur
< cx
->end
);
74 cx
->cur
->type
= SWFDEC_AS_TYPE_OBJECT
+ 1;
77 #else /* SWFDEC_MAD_CHECKS */
78 #define swfdec_as_stack_peek(cx,n) (&(cx)->cur[-(gssize)(n)])
79 #define swfdec_as_stack_pop(cx) (--(cx)->cur)
80 #define swfdec_as_stack_pop_n(cx, n) ((cx)->cur -= (n))
81 #define swfdec_as_stack_push(cx) ((cx)->cur++)
83 #define swfdec_as_stack_swap(cx,x,y) G_STMT_START { \
84 SwfdecAsContext *__cx = (cx); \
85 SwfdecAsValue __tmp; \
86 guint __x = (x), __y = (y); \
87 __tmp = *swfdec_as_stack_peek(__cx, __x); \
88 *swfdec_as_stack_peek(__cx, __x) = *swfdec_as_stack_peek(__cx, __y); \
89 *swfdec_as_stack_peek(__cx, __y) = __tmp; \
92 void swfdec_as_stack_mark (SwfdecAsStack
* stack
);
93 void swfdec_as_stack_ensure_size (SwfdecAsContext
* context
,
95 void swfdec_as_stack_ensure_free (SwfdecAsContext
* context
,
97 guint
swfdec_as_stack_get_size (SwfdecAsContext
* context
);