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_CONTEXT_H_
21 #define _SWFDEC_AS_CONTEXT_H_
23 #include <glib-object.h>
24 #include <libswfdec/swfdec_as_types.h>
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
{
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) */
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 */
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 */
68 SwfdecAsValue
* base
; /* stack base */
69 SwfdecAsValue
* end
; /* end of stack */
70 SwfdecAsValue
* cur
; /* pointer to current top of stack */
71 SwfdecAsStack
* stack
; /* current stack */
73 /* magic objects - initialized during swfdec_as_context_startup() */
74 SwfdecAsObject
* Function
; /* Function */
75 SwfdecAsObject
* Function_prototype
; /* Function.prototype */
76 SwfdecAsObject
* Object
; /* Object */
77 SwfdecAsObject
* Object_prototype
; /* Object.prototype */
80 SwfdecAsDebugger
* debugger
; /* debugger (or NULL if none) */
83 struct _SwfdecAsContextClass
{
84 GObjectClass object_class
;
86 /* mark all objects that should not be collected */
87 void (* mark
) (SwfdecAsContext
* context
);
88 /* overwrite if you want to report a different time than gettimeofday */
89 void (* get_time
) (SwfdecAsContext
* context
,
93 GType
swfdec_as_context_get_type (void);
95 void swfdec_as_context_startup (SwfdecAsContext
* context
,
98 gboolean swfdec_as_context_is_constructing
99 (SwfdecAsContext
* context
);
100 SwfdecAsFrame
* swfdec_as_context_get_frame (SwfdecAsContext
* context
);
101 void swfdec_as_context_get_time (SwfdecAsContext
* context
,
103 const char * swfdec_as_context_get_string (SwfdecAsContext
* context
,
104 const char * string
);
105 const char * swfdec_as_context_give_string (SwfdecAsContext
* context
,
108 void swfdec_as_context_abort (SwfdecAsContext
* context
,
109 const char * reason
);
111 gboolean
swfdec_as_context_use_mem (SwfdecAsContext
* context
,
113 void swfdec_as_context_unuse_mem (SwfdecAsContext
* context
,
115 void swfdec_as_object_mark (SwfdecAsObject
* object
);
116 void swfdec_as_value_mark (SwfdecAsValue
* value
);
117 void swfdec_as_string_mark (const char * string
);
118 void swfdec_as_context_gc (SwfdecAsContext
* context
);
119 void swfdec_as_context_maybe_gc (SwfdecAsContext
* context
);
121 void swfdec_as_context_run (SwfdecAsContext
* context
);
123 void swfdec_as_context_eval (SwfdecAsContext
* context
,
124 SwfdecAsObject
* obj
,
126 SwfdecAsValue
* val
);
127 void swfdec_as_context_eval_set (SwfdecAsContext
* context
,
128 SwfdecAsObject
* obj
,
130 const SwfdecAsValue
* val
);