first step at rewriting the button code - nothing works, but it compiles
[swfdec.git] / libswfdec / swfdec_as_context.h
blobdf09fa277ad9da3a6c5a25ea3ee783344c653886
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_CONTEXT_H_
21 #define _SWFDEC_AS_CONTEXT_H_
23 #include <glib-object.h>
24 #include <libswfdec/swfdec_as_types.h>
26 G_BEGIN_DECLS
28 typedef enum {
29 SWFDEC_AS_CONTEXT_NEW,
30 SWFDEC_AS_CONTEXT_RUNNING,
31 SWFDEC_AS_CONTEXT_INTERRUPTED,
32 SWFDEC_AS_CONTEXT_ABORTED
33 } SwfdecAsContextState;
35 typedef struct _SwfdecAsContextClass SwfdecAsContextClass;
37 #define SWFDEC_TYPE_AS_CONTEXT (swfdec_as_context_get_type())
38 #define SWFDEC_IS_AS_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SWFDEC_TYPE_AS_CONTEXT))
39 #define SWFDEC_IS_AS_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SWFDEC_TYPE_AS_CONTEXT))
40 #define SWFDEC_AS_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SWFDEC_TYPE_AS_CONTEXT, SwfdecAsContext))
41 #define SWFDEC_AS_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SWFDEC_TYPE_AS_CONTEXT, SwfdecAsContextClass))
42 #define SWFDEC_AS_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SWFDEC_TYPE_AS_CONTEXT, SwfdecAsContextClass))
44 struct _SwfdecAsContext {
45 GObject object;
47 SwfdecAsContextState state; /* our current state */
48 SwfdecAsObject * global; /* the global object */
49 GRand * rand; /* random number generator */
50 GTimeVal start_time; /* time this movie started (for GetTime action) */
52 /* GC properties */
53 gsize memory_until_gc;/* amount of memory allocations that trigger a GC */
55 /* bookkeeping for GC */
56 gsize memory; /* total memory currently in use */
57 gsize memory_since_gc;/* memory allocated since last GC run */
58 GHashTable * strings; /* string=>memory mapping the context manages */
59 GHashTable * objects; /* all objects the context manages */
61 /* execution state */
62 unsigned int version; /* currently active version */
63 unsigned int call_depth; /* current depth of call stack (equals length of frame list) */
64 SwfdecAsFrame * frame; /* topmost stack frame */
65 SwfdecAsFrame * last_frame; /* last frame before calling context_run */
66 gboolean exception; /* whether we are throwing an exception */
67 SwfdecAsValue exception_value; /* value of the exception being thrown, can be anything including undefined */
69 /* stack */
70 SwfdecAsValue * base; /* stack base */
71 SwfdecAsValue * end; /* end of stack */
72 SwfdecAsValue * cur; /* pointer to current top of stack */
73 SwfdecAsStack * stack; /* current stack */
75 /* magic objects - initialized during swfdec_as_context_startup() */
76 SwfdecAsObject * Function; /* Function */
77 SwfdecAsObject * Function_prototype; /* Function.prototype */
78 SwfdecAsObject * Object; /* Object */
79 SwfdecAsObject * Object_prototype; /* Object.prototype */
81 /* debugging */
82 SwfdecAsDebugger * debugger; /* debugger (or NULL if none) */
85 struct _SwfdecAsContextClass {
86 GObjectClass object_class;
88 /* mark all objects that should not be collected */
89 void (* mark) (SwfdecAsContext * context);
90 /* overwrite if you want to report a different time than gettimeofday */
91 void (* get_time) (SwfdecAsContext * context,
92 GTimeVal * tv);
93 /* overwrite if you want to abort on infinite loops */
94 gboolean (* check_continue) (SwfdecAsContext * context);
97 GType swfdec_as_context_get_type (void);
99 void swfdec_as_context_startup (SwfdecAsContext * context,
100 guint version);
102 gboolean swfdec_as_context_is_aborted (SwfdecAsContext * context);
103 gboolean swfdec_as_context_is_constructing
104 (SwfdecAsContext * context);
105 SwfdecAsFrame * swfdec_as_context_get_frame (SwfdecAsContext * context);
106 void swfdec_as_context_get_time (SwfdecAsContext * context,
107 GTimeVal * tv);
108 const char * swfdec_as_context_get_string (SwfdecAsContext * context,
109 const char * string);
110 const char * swfdec_as_context_give_string (SwfdecAsContext * context,
111 char * string);
113 void swfdec_as_context_abort (SwfdecAsContext * context,
114 const char * reason);
116 void swfdec_as_context_throw (SwfdecAsContext * context,
117 const SwfdecAsValue * value);
118 gboolean swfdec_as_context_catch (SwfdecAsContext * context,
119 SwfdecAsValue * value);
121 gboolean swfdec_as_context_use_mem (SwfdecAsContext * context,
122 gsize bytes);
123 void swfdec_as_context_unuse_mem (SwfdecAsContext * context,
124 gsize bytes);
125 void swfdec_as_object_mark (SwfdecAsObject * object);
126 void swfdec_as_value_mark (SwfdecAsValue * value);
127 void swfdec_as_string_mark (const char * string);
128 void swfdec_as_context_gc (SwfdecAsContext * context);
129 void swfdec_as_context_maybe_gc (SwfdecAsContext * context);
131 void swfdec_as_context_run (SwfdecAsContext * context);
133 void swfdec_as_context_eval (SwfdecAsContext * context,
134 SwfdecAsObject * obj,
135 const char * str,
136 SwfdecAsValue * val);
137 void swfdec_as_context_eval_set (SwfdecAsContext * context,
138 SwfdecAsObject * obj,
139 const char * str,
140 const SwfdecAsValue * val);
142 G_END_DECLS
143 #endif