[Swfdec-commits] swfdec/swfdec_as_context.c swfdec/swfdec_as_internal.h swfdec/swfdec_as_interpret.c swfdec/swfdec_as_types.c swfdec/swfdec_as_types.h swfdec/swfdec_resource.c
Benjamin Otte
company at kemper.freedesktop.org
Thu Nov 6 01:12:33 PST 2008
swfdec/swfdec_as_context.c | 13 ++++----
swfdec/swfdec_as_internal.h | 9 ++----
swfdec/swfdec_as_interpret.c | 6 +---
swfdec/swfdec_as_types.c | 3 --
swfdec/swfdec_as_types.h | 63 ++++++++++++++++++++-----------------------
swfdec/swfdec_resource.c | 2 -
6 files changed, 45 insertions(+), 51 deletions(-)
New commits:
commit f06eb2265ceda2d7bb3cc7a83402c322ba912d46
Author: Benjamin Otte <otte at gnome.org>
Date: Thu Nov 6 10:09:05 2008 +0100
make SwfdecAsValue pointer-sized
a SwfdecAsValue now looks like in all modern JS engines:
<X-3 bits for value> | <3 bits for type>
And will (after more surgery) be passed by value, not by reference.
So you will now pass "SwfdecAsValue" parameters around, and no longer
use "SwfdecAsValue *"
diff --git a/swfdec/swfdec_as_context.c b/swfdec/swfdec_as_context.c
index ccf1857..3759446 100644
--- a/swfdec/swfdec_as_context.c
+++ b/swfdec/swfdec_as_context.c
@@ -352,16 +352,17 @@ swfdec_as_string_mark (const char *string)
void
swfdec_as_value_mark (SwfdecAsValue *value)
{
+ SwfdecAsGcable *gcable = SWFDEC_AS_VALUE_GET_VALUE (value);
if (SWFDEC_AS_VALUE_IS_OBJECT (value)) {
- if (!SWFDEC_AS_GCABLE_FLAG_IS_SET (value->value.gcable, SWFDEC_AS_GC_MARK))
- swfdec_as_object_mark ((SwfdecAsObject *) value->value.gcable);
+ if (!SWFDEC_AS_GCABLE_FLAG_IS_SET (gcable, SWFDEC_AS_GC_MARK))
+ swfdec_as_object_mark ((SwfdecAsObject *) gcable);
} else if (SWFDEC_AS_VALUE_IS_MOVIE (value)) {
- if (!SWFDEC_AS_GCABLE_FLAG_IS_SET (value->value.gcable, SWFDEC_AS_GC_MARK))
- swfdec_as_movie_value_mark ((SwfdecAsMovieValue *) value->value.gcable);
+ if (!SWFDEC_AS_GCABLE_FLAG_IS_SET (gcable, SWFDEC_AS_GC_MARK))
+ swfdec_as_movie_value_mark ((SwfdecAsMovieValue *) gcable);
} else if (SWFDEC_AS_VALUE_IS_STRING (value) ||
SWFDEC_AS_VALUE_IS_NUMBER (value)) {
- if (!SWFDEC_AS_GCABLE_FLAG_IS_SET (value->value.gcable, SWFDEC_AS_GC_ROOT | SWFDEC_AS_GC_MARK))
- SWFDEC_AS_GCABLE_SET_FLAG (value->value.gcable, SWFDEC_AS_GC_MARK);
+ if (!SWFDEC_AS_GCABLE_FLAG_IS_SET (gcable, SWFDEC_AS_GC_ROOT | SWFDEC_AS_GC_MARK))
+ SWFDEC_AS_GCABLE_SET_FLAG (gcable, SWFDEC_AS_GC_MARK);
}
}
diff --git a/swfdec/swfdec_as_internal.h b/swfdec/swfdec_as_internal.h
index f69a54f..4f64951 100644
--- a/swfdec/swfdec_as_internal.h
+++ b/swfdec/swfdec_as_internal.h
@@ -53,15 +53,14 @@ G_BEGIN_DECLS
} G_STMT_END
#define SWFDEC_AS_VALUE_IS_MOVIE(val) (SWFDEC_AS_VALUE_GET_TYPE (val) == SWFDEC_AS_TYPE_MOVIE)
-#define SWFDEC_AS_VALUE_GET_MOVIE(val) (((SwfdecAsMovieValue *) (val)->value.gcable)->movie ? \
- ((SwfdecAsMovieValue *) (val)->value.gcable)->movie : swfdec_as_movie_value_get ((SwfdecAsMovieValue *) (val)->value.gcable))
+#define SWFDEC_AS_VALUE_GET_MOVIE(val) (((SwfdecAsMovieValue *) SWFDEC_AS_VALUE_GET_VALUE (val))->movie ? \
+ ((SwfdecAsMovieValue *) SWFDEC_AS_VALUE_GET_VALUE (val))->movie : swfdec_as_movie_value_get (SWFDEC_AS_VALUE_GET_VALUE (val)))
+#define SWFDEC_AS_VALUE_FROM_MOVIE(m) SWFDEC_AS_VALUE_COMBINE (m->as_value, SWFDEC_AS_TYPE_MOVIE)
#define SWFDEC_AS_VALUE_SET_MOVIE(val,m) G_STMT_START { \
- SwfdecAsValue *__val = (val); \
SwfdecMovie *__m = (m); \
g_assert (SWFDEC_IS_MOVIE (__m)); \
g_assert (__m->as_value); \
- (__val)->type = SWFDEC_AS_TYPE_MOVIE; \
- (__val)->value.gcable = (SwfdecAsGcable *) __m->as_value; \
+ *(val) = SWFDEC_AS_VALUE_FROM_MOVIE (__m); \
} G_STMT_END
/* swfdec_as_context.c */
diff --git a/swfdec/swfdec_as_interpret.c b/swfdec/swfdec_as_interpret.c
index 4411757..daeccef 100644
--- a/swfdec/swfdec_as_interpret.c
+++ b/swfdec/swfdec_as_interpret.c
@@ -1479,8 +1479,7 @@ swfdec_action_equals2_5 (SwfdecAsContext *cx, guint action, const guint8 *data,
/* else compare as numbers */
if (isnan (l) && isnan (r)) {
- cond = (ltype == rtype && ltype == SWFDEC_AS_TYPE_NUMBER &&
- ltmp.value.gcable == rtmp.value.gcable);
+ cond = (ltype == SWFDEC_AS_TYPE_NUMBER && ltmp == rtmp);
} else {
cond = l == r;
}
@@ -1545,8 +1544,7 @@ swfdec_action_equals2_6 (SwfdecAsContext *cx, guint action, const guint8 *data,
r = swfdec_as_value_to_number (cx, rval);
if (isnan (l) && isnan (r)) {
- cond = (ltype == rtype && ltype == SWFDEC_AS_TYPE_NUMBER &&
- lval->value.gcable == rval->value.gcable);
+ cond = (ltype == SWFDEC_AS_TYPE_NUMBER && *lval == *rval);
} else {
cond = l == r;
}
diff --git a/swfdec/swfdec_as_types.c b/swfdec/swfdec_as_types.c
index 91caa25..10f0d93 100644
--- a/swfdec/swfdec_as_types.c
+++ b/swfdec/swfdec_as_types.c
@@ -203,8 +203,7 @@ swfdec_as_value_set_number (SwfdecAsContext *context, SwfdecAsValue *val,
SWFDEC_AS_GCABLE_SET_NEXT (dval, context->numbers);
context->numbers = dval;
- val->type = SWFDEC_AS_TYPE_NUMBER;
- val->value.gcable = (SwfdecAsGcable *) dval;
+ *val = SWFDEC_AS_VALUE_COMBINE (dval, SWFDEC_AS_TYPE_NUMBER);
}
/**
diff --git a/swfdec/swfdec_as_types.h b/swfdec/swfdec_as_types.h
index b2e14a6..76d59f1 100644
--- a/swfdec/swfdec_as_types.h
+++ b/swfdec/swfdec_as_types.h
@@ -28,13 +28,13 @@ G_BEGIN_DECLS
/* fundamental types */
typedef enum {
SWFDEC_AS_TYPE_UNDEFINED = 0,
- SWFDEC_AS_TYPE_BOOLEAN,
- SWFDEC_AS_TYPE_INT, /* unimplemented, but reserved if someone wants it */
- SWFDEC_AS_TYPE_NUMBER,
- SWFDEC_AS_TYPE_STRING,
- SWFDEC_AS_TYPE_NULL,
- SWFDEC_AS_TYPE_OBJECT,
- SWFDEC_AS_TYPE_MOVIE
+ SWFDEC_AS_TYPE_NULL = 1,
+ SWFDEC_AS_TYPE_BOOLEAN = 2,
+ SWFDEC_AS_TYPE_INT = 3, /* unimplemented, but reserved if someone wants it */
+ SWFDEC_AS_TYPE_NUMBER = 4,
+ SWFDEC_AS_TYPE_STRING = 5,
+ SWFDEC_AS_TYPE_OBJECT = 6,
+ SWFDEC_AS_TYPE_MOVIE = 7
} SwfdecAsValueType;
typedef struct _SwfdecAsContext SwfdecAsContext;
@@ -47,7 +47,7 @@ typedef struct _SwfdecAsObject SwfdecAsObject;
typedef struct _SwfdecAsRelay SwfdecAsRelay;
typedef struct _SwfdecAsScope SwfdecAsScope;
typedef struct _SwfdecAsStack SwfdecAsStack;
-typedef struct _SwfdecAsValue SwfdecAsValue;
+typedef gsize SwfdecAsValue;
typedef void (* SwfdecAsNative) (SwfdecAsContext * context,
SwfdecAsObject * thisp,
guint argc,
@@ -58,29 +58,27 @@ typedef struct _SwfdecScript SwfdecScript;
/* IMPORTANT: a SwfdecAsValue memset to 0 is a valid undefined value */
-struct _SwfdecAsValue {
- SwfdecAsValueType type;
- /*< private >*/
- union {
- gboolean boolean;
- SwfdecAsGcable * gcable;
- SwfdecAsObject * object;
- } value;
-};
+#define SWFDEC_AS_VALUE_TYPE_BITS (3)
+#define SWFDEC_AS_VALUE_TYPE_MASK ((1 << SWFDEC_AS_VALUE_TYPE_BITS) - 1)
+#define SWFDEC_AS_VALUE_VALUE_MASK (~SWFDEC_AS_VALUE_TYPE_MASK)
-#define SWFDEC_AS_VALUE_GET_TYPE(val) ((val)->type)
+#define SWFDEC_AS_VALUE_GET_TYPE(val) (*(val) & SWFDEC_AS_VALUE_TYPE_MASK)
+#define SWFDEC_AS_VALUE_GET_VALUE(val) GSIZE_TO_POINTER (*(val) & SWFDEC_AS_VALUE_VALUE_MASK)
+#define SWFDEC_AS_VALUE_COMBINE(val, type) (GPOINTER_TO_SIZE (val) | type)
+#define SWFDEC_AS_VALUE_UNDEFINED SWFDEC_AS_VALUE_COMBINE (NULL, SWFDEC_AS_TYPE_UNDEFINED)
#define SWFDEC_AS_VALUE_IS_UNDEFINED(val) (SWFDEC_AS_VALUE_GET_TYPE (val) == SWFDEC_AS_TYPE_UNDEFINED)
-#define SWFDEC_AS_VALUE_SET_UNDEFINED(val) (val)->type = SWFDEC_AS_TYPE_UNDEFINED
+#define SWFDEC_AS_VALUE_SET_UNDEFINED(val) *(val) = SWFDEC_AS_VALUE_UNDEFINED
+#define SWFDEC_AS_VALUE_FALSE SWFDEC_AS_VALUE_COMBINE(NULL, SWFDEC_AS_TYPE_BOOLEAN)
+#define SWFDEC_AS_VALUE_TRUE SWFDEC_AS_VALUE_COMBINE(GSIZE_TO_POINTER (1 << SWFDEC_AS_VALUE_TYPE_BITS), SWFDEC_AS_TYPE_BOOLEAN)
#define SWFDEC_AS_VALUE_IS_BOOLEAN(val) (SWFDEC_AS_VALUE_GET_TYPE (val) == SWFDEC_AS_TYPE_BOOLEAN)
-#define SWFDEC_AS_VALUE_GET_BOOLEAN(val) ((val)->value.boolean)
+#define SWFDEC_AS_VALUE_GET_BOOLEAN(val) (SWFDEC_AS_VALUE_GET_VALUE (val) != NULL)
+#define SWFDEC_AS_VALUE_FROM_BOOLEAN(b) (b ? SWFDEC_AS_VALUE_TRUE : SWFDEC_AS_VALUE_FALSE)
#define SWFDEC_AS_VALUE_SET_BOOLEAN(val,b) G_STMT_START { \
- SwfdecAsValue *__val = (val); \
gboolean __tmp = (b); \
g_assert (__tmp == TRUE || __tmp == FALSE); \
- (__val)->value.boolean = __tmp; \
- (__val)->type = SWFDEC_AS_TYPE_BOOLEAN; \
+ *(val) = SWFDEC_AS_VALUE_FROM_BOOLEAN(__tmp); \
} G_STMT_END
struct _SwfdecAsDoubleValue {
@@ -89,28 +87,27 @@ struct _SwfdecAsDoubleValue {
};
#define SWFDEC_AS_VALUE_IS_NUMBER(val) (SWFDEC_AS_VALUE_GET_TYPE (val) == SWFDEC_AS_TYPE_NUMBER)
-#define SWFDEC_AS_VALUE_GET_NUMBER(val) (((SwfdecAsDoubleValue *) (val)->value.gcable)->number)
+#define SWFDEC_AS_VALUE_GET_NUMBER(val) (((SwfdecAsDoubleValue *) SWFDEC_AS_VALUE_GET_VALUE(val))->number)
#define SWFDEC_AS_VALUE_IS_STRING(val) (SWFDEC_AS_VALUE_GET_TYPE (val) == SWFDEC_AS_TYPE_STRING)
-#define SWFDEC_AS_VALUE_GET_STRING(val) (((SwfdecAsStringValue *) (val)->value.gcable)->string)
+#define SWFDEC_AS_VALUE_GET_STRING(val) (((SwfdecAsStringValue *) SWFDEC_AS_VALUE_GET_VALUE(val))->string)
+#define SWFDEC_AS_VALUE_FROM_STRING(s) SWFDEC_AS_VALUE_COMBINE (((guint8 *) (s) - G_STRUCT_OFFSET (SwfdecAsStringValue, string)), SWFDEC_AS_TYPE_STRING)
#define SWFDEC_AS_VALUE_SET_STRING(val,s) G_STMT_START { \
- SwfdecAsValue *__val = (val); \
- (__val)->value.gcable = (SwfdecAsGcable *) (gpointer) ((guint8 *) (s) - G_STRUCT_OFFSET (SwfdecAsStringValue, string)); \
- (__val)->type = SWFDEC_AS_TYPE_STRING; \
+ *(val) = SWFDEC_AS_VALUE_FROM_STRING (s); \
} G_STMT_END
+#define SWFDEC_AS_VALUE_NULL SWFDEC_AS_VALUE_COMBINE (NULL, SWFDEC_AS_TYPE_NULL)
#define SWFDEC_AS_VALUE_IS_NULL(val) (SWFDEC_AS_VALUE_GET_TYPE (val) == SWFDEC_AS_TYPE_NULL)
-#define SWFDEC_AS_VALUE_SET_NULL(val) (val)->type = SWFDEC_AS_TYPE_NULL
+#define SWFDEC_AS_VALUE_SET_NULL(val) *(val) = SWFDEC_AS_VALUE_NULL
#define SWFDEC_AS_VALUE_IS_OBJECT(val) (SWFDEC_AS_VALUE_GET_TYPE (val) == SWFDEC_AS_TYPE_OBJECT)
-#define SWFDEC_AS_VALUE_GET_OBJECT(val) ((SwfdecAsObject *) (val)->value.gcable)
+#define SWFDEC_AS_VALUE_GET_OBJECT(val) ((SwfdecAsObject *) SWFDEC_AS_VALUE_GET_VALUE (val))
+#define SWFDEC_AS_VALUE_FROM_OBJECT(o) SWFDEC_AS_VALUE_COMBINE (o, SWFDEC_AS_TYPE_OBJECT)
#define SWFDEC_AS_VALUE_SET_OBJECT(val,o) G_STMT_START { \
- SwfdecAsValue *__val = (val); \
SwfdecAsObject *__o = (o); \
g_assert (__o != NULL); \
g_assert (!__o->movie); \
- (__val)->type = SWFDEC_AS_TYPE_OBJECT; \
- (__val)->value.gcable = (SwfdecAsGcable *) __o; \
+ *(val) = SWFDEC_AS_VALUE_FROM_OBJECT (__o); \
} G_STMT_END
/* value setters */
diff --git a/swfdec/swfdec_resource.c b/swfdec/swfdec_resource.c
index 1948e82..3670a5b 100644
--- a/swfdec/swfdec_resource.c
+++ b/swfdec/swfdec_resource.c
@@ -131,7 +131,7 @@ swfdec_resource_emit_signal (SwfdecResource *resource, const char *name, gboolea
return;
}
if (name == SWFDEC_AS_STR_onLoadInit &&
- (SwfdecAsGcable *) movie->as_value != resource->movie.value.gcable) {
+ movie->as_value != SWFDEC_AS_VALUE_GET_VALUE (&resource->movie)) {
SWFDEC_INFO ("not emitting onLoadInit - the movie is different");
return;
}
More information about the Swfdec-commits
mailing list