[Swfdec-commits] 2 commits - vivified/code

Benjamin Otte company at kemper.freedesktop.org
Thu Apr 24 12:56:27 PDT 2008


 vivified/code/Makefile.am             |    2 
 vivified/code/vivi_code_asm_get_url.c |  142 ++++++++++++++++++++++++++++++++++
 vivified/code/vivi_code_asm_get_url.h |   61 ++++++++++++++
 vivified/code/vivi_code_return.c      |   12 ++
 vivified/code/vivi_code_return.h      |    2 
 vivified/code/vivi_disassembler.c     |   21 ++++-
 6 files changed, 236 insertions(+), 4 deletions(-)

New commits:
commit 603f1dc0cc5393eb19b9127bef50c25093a1daad
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Apr 24 21:50:44 2008 +0200

    NULL is a valid return value
    
    In that case we push undefined.

diff --git a/vivified/code/vivi_code_return.c b/vivified/code/vivi_code_return.c
index e031805..c1a92c7 100644
--- a/vivified/code/vivi_code_return.c
+++ b/vivified/code/vivi_code_return.c
@@ -22,9 +22,10 @@
 #endif
 
 #include "vivi_code_return.h"
+#include "vivi_code_asm_code_default.h"
+#include "vivi_code_asm_push.h"
 #include "vivi_code_printer.h"
 #include "vivi_code_assembler.h"
-#include "vivi_code_asm_code_default.h"
 
 G_DEFINE_TYPE (ViviCodeReturn, vivi_code_return, VIVI_TYPE_CODE_STATEMENT)
 
@@ -61,7 +62,14 @@ vivi_code_return_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
   ViviCodeReturn *ret = VIVI_CODE_RETURN (token);
   ViviCodeAsm *code;
 
-  vivi_code_value_compile (ret->value, assembler);
+  if (ret->value) {
+    vivi_code_value_compile (ret->value, assembler);
+  } else {
+    ViviCodeAsm *push = vivi_code_asm_push_new ();
+    vivi_code_asm_push_add_undefined (VIVI_CODE_ASM_PUSH (push));
+    vivi_code_assembler_add_code (assembler, push);
+    g_object_unref (push);
+  }
 
   code = vivi_code_asm_return_new ();
   vivi_code_assembler_add_code (assembler, code);
diff --git a/vivified/code/vivi_code_return.h b/vivified/code/vivi_code_return.h
index c0e5aeb..f973deb 100644
--- a/vivified/code/vivi_code_return.h
+++ b/vivified/code/vivi_code_return.h
@@ -40,7 +40,7 @@ struct _ViviCodeReturn
 {
   ViviCodeStatement	statement;
 
-  ViviCodeValue *	value;
+  ViviCodeValue *	value;		/* value to return or NULL if none */
 };
 
 struct _ViviCodeReturnClass
commit 26ed62bf4f7137da019197c77f5f7699c298095a
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Apr 24 18:26:01 2008 +0200

    add GetURL action

diff --git a/vivified/code/Makefile.am b/vivified/code/Makefile.am
index 36d5642..2c22c85 100644
--- a/vivified/code/Makefile.am
+++ b/vivified/code/Makefile.am
@@ -22,6 +22,7 @@ libvivified_compiler_la_SOURCES = \
 	vivi_code_asm_code_default.c \
 	vivi_code_asm_function.c \
 	vivi_code_asm_function2.c \
+	vivi_code_asm_get_url.c \
 	vivi_code_asm_if.c \
 	vivi_code_asm_jump.c \
 	vivi_code_asm_pool.c \
@@ -93,6 +94,7 @@ noinst_HEADERS = \
 	vivi_code_asm_code_default.h \
 	vivi_code_asm_function.h \
 	vivi_code_asm_function2.h \
+	vivi_code_asm_get_url.h \
 	vivi_code_asm_if.h \
 	vivi_code_asm_jump.h \
 	vivi_code_asm_pool.h \
diff --git a/vivified/code/vivi_code_asm_get_url.c b/vivified/code/vivi_code_asm_get_url.c
new file mode 100644
index 0000000..ed8bb4b
--- /dev/null
+++ b/vivified/code/vivi_code_asm_get_url.c
@@ -0,0 +1,142 @@
+/* Vivified
+ * Copyright (C) 2008 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+
+#include <swfdec/swfdec_as_interpret.h>
+#include <swfdec/swfdec_bots.h>
+
+#include "vivi_code_asm_get_url.h"
+#include "vivi_code_asm.h"
+#include "vivi_code_emitter.h"
+#include "vivi_code_error.h"
+#include "vivi_code_printer.h"
+
+static gboolean
+vivi_code_asm_get_url_emit (ViviCodeAsm *code, ViviCodeEmitter *emitter, GError **error)
+{
+  ViviCodeAsmGetUrl *url = VIVI_CODE_ASM_GET_URL (code);
+  SwfdecBots *emit = vivi_code_emitter_get_bots (emitter);
+  gsize len;
+
+  swfdec_bots_put_u8 (emit, SWFDEC_AS_ACTION_GET_URL);
+  len = strlen (url->url) + strlen (url->target) + 2;
+  if (len > G_MAXUINT16) {
+    g_set_error (error, VIVI_CODE_ERROR, VIVI_CODE_ERROR_SIZE,
+	"url and target exceed maximum size");
+    return FALSE;
+  }
+  swfdec_bots_put_u16 (emit, len);
+  swfdec_bots_put_string (emit, url->url);
+  swfdec_bots_put_string (emit, url->target);
+
+  return TRUE;
+}
+
+static void
+vivi_code_asm_get_url_asm_init (ViviCodeAsmInterface *iface)
+{
+  iface->emit = vivi_code_asm_get_url_emit;
+}
+
+G_DEFINE_TYPE_WITH_CODE (ViviCodeAsmGetUrl, vivi_code_asm_get_url, VIVI_TYPE_CODE_ASM_CODE,
+    G_IMPLEMENT_INTERFACE (VIVI_TYPE_CODE_ASM, vivi_code_asm_get_url_asm_init))
+
+static void
+vivi_code_asm_get_url_print (ViviCodeToken *token, ViviCodePrinter*printer)
+{
+  ViviCodeAsmGetUrl *url = VIVI_CODE_ASM_GET_URL (token);
+  char *s;
+
+  vivi_code_printer_print (printer, "geturl ");
+  s = vivi_code_escape_string (url->url);
+  vivi_code_printer_print (printer, s);
+  g_free (s);
+  s = vivi_code_escape_string (url->target);
+  vivi_code_printer_print (printer, s);
+  g_free (s);
+}
+
+static void
+vivi_code_asm_get_url_dispose (GObject *object)
+{
+  ViviCodeAsmGetUrl *url = VIVI_CODE_ASM_GET_URL (object);
+
+  g_free (url->url);
+  url->url = NULL;
+  g_free (url->target);
+  url->target = NULL;
+
+  G_OBJECT_CLASS (vivi_code_asm_get_url_parent_class)->dispose (object);
+}
+
+static void
+vivi_code_asm_get_url_class_init (ViviCodeAsmGetUrlClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  ViviCodeTokenClass *token_class = VIVI_CODE_TOKEN_CLASS (klass);
+  ViviCodeAsmCodeClass *code_class = VIVI_CODE_ASM_CODE_CLASS (klass);
+
+  object_class->dispose = vivi_code_asm_get_url_dispose;
+
+  token_class->print = vivi_code_asm_get_url_print;
+
+  code_class->bytecode = SWFDEC_AS_ACTION_GET_URL;
+}
+
+static void
+vivi_code_asm_get_url_init (ViviCodeAsmGetUrl *get_url)
+{
+}
+
+ViviCodeAsm *
+vivi_code_asm_get_url_new (const char *url, const char *target)
+{
+  ViviCodeAsmGetUrl *ret;
+
+  g_return_val_if_fail (url != NULL, NULL);
+  g_return_val_if_fail (target != NULL, NULL);
+
+  ret = g_object_new (VIVI_TYPE_CODE_ASM_GET_URL, NULL);
+  ret->url = g_strdup (url);
+  ret->target = g_strdup (target);
+
+  return VIVI_CODE_ASM (ret);
+}
+
+const char *
+vivi_code_asm_get_url_get_url (ViviCodeAsmGetUrl *url)
+{
+  g_return_val_if_fail (VIVI_IS_CODE_ASM_GET_URL (url), NULL);
+
+  return url->url;
+}
+
+const char *
+vivi_code_asm_get_url_get_target (ViviCodeAsmGetUrl *url)
+{
+  g_return_val_if_fail (VIVI_IS_CODE_ASM_GET_URL (url), NULL);
+
+  return url->target;
+}
+
diff --git a/vivified/code/vivi_code_asm_get_url.h b/vivified/code/vivi_code_asm_get_url.h
new file mode 100644
index 0000000..74f4e36
--- /dev/null
+++ b/vivified/code/vivi_code_asm_get_url.h
@@ -0,0 +1,61 @@
+/* Vivified
+ * Copyright (C) 2008 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifndef _VIVI_CODE_ASM_GET_URL_H_
+#define _VIVI_CODE_ASM_GET_URL_H_
+
+#include <vivified/code/vivi_code_asm.h>
+#include <vivified/code/vivi_code_asm_code.h>
+
+G_BEGIN_DECLS
+
+typedef struct _ViviCodeAsmGetUrl ViviCodeAsmGetUrl;
+typedef struct _ViviCodeAsmGetUrlClass ViviCodeAsmGetUrlClass;
+
+#define VIVI_TYPE_CODE_ASM_GET_URL                    (vivi_code_asm_get_url_get_type())
+#define VIVI_IS_CODE_ASM_GET_URL(obj)                 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIVI_TYPE_CODE_ASM_GET_URL))
+#define VIVI_IS_CODE_ASM_GET_URL_CLASS(klass)         (G_TYPE_CHECK_CLASS_TYPE ((klass), VIVI_TYPE_CODE_ASM_GET_URL))
+#define VIVI_CODE_ASM_GET_URL(obj)                    (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIVI_TYPE_CODE_ASM_GET_URL, ViviCodeAsmGetUrl))
+#define VIVI_CODE_ASM_GET_URL_CLASS(klass)            (G_TYPE_CHECK_CLASS_CAST ((klass), VIVI_TYPE_CODE_ASM_GET_URL, ViviCodeAsmGetUrlClass))
+#define VIVI_CODE_ASM_GET_URL_GET_CLASS(obj)          (G_TYPE_INSTANCE_GET_CLASS ((obj), VIVI_TYPE_CODE_ASM_GET_URL, ViviCodeAsmGetUrlClass))
+
+struct _ViviCodeAsmGetUrl
+{
+  ViviCodeAsmCode	code;
+
+  char *		url;
+  char *		target;
+};
+
+struct _ViviCodeAsmGetUrlClass
+{
+  ViviCodeAsmCodeClass	code_class;
+};
+
+GType		vivi_code_asm_get_url_get_type	  	(void);
+
+ViviCodeAsm *	vivi_code_asm_get_url_new	      	(const char *		url,
+							 const char *		target);
+
+const char *	vivi_code_asm_get_url_get_url		(ViviCodeAsmGetUrl *	url);
+const char *	vivi_code_asm_get_url_get_target	(ViviCodeAsmGetUrl *	url);
+
+
+G_END_DECLS
+#endif
diff --git a/vivified/code/vivi_disassembler.c b/vivified/code/vivi_disassembler.c
index d967003..2163d6d 100644
--- a/vivified/code/vivi_disassembler.c
+++ b/vivified/code/vivi_disassembler.c
@@ -29,6 +29,7 @@
 #include "vivi_code_asm_code_default.h"
 #include "vivi_code_asm_function.h"
 #include "vivi_code_asm_function2.h"
+#include "vivi_code_asm_get_url.h"
 #include "vivi_code_asm_if.h"
 #include "vivi_code_asm_jump.h"
 #include "vivi_code_asm_pool.h"
@@ -42,6 +43,7 @@
 #define vivi_disassembler_warning(assembler,...) G_STMT_START { \
   char *__s = g_strdup_printf (__VA_ARGS__); \
   ViviCodeStatement *comment = vivi_code_comment_new (__s); \
+  g_printerr ("WARNING: %s\n", __s); \
   vivi_code_assembler_add_code (assembler, VIVI_CODE_ASM (comment)); \
   g_object_unref (comment); \
   g_free (__s); \
@@ -53,6 +55,21 @@ static ViviCodeAsm * (* simple_commands[0x80]) (void) = {
 };
 
 static void
+vivi_disassemble_get_url (ViviCodeAssembler *assembler, SwfdecBits *bits, guint version)
+{
+  ViviCodeAsm *code;
+  char *url, *target;
+
+  url = swfdec_bits_get_string (bits, version);
+  target = swfdec_bits_get_string (bits, version);
+  code = vivi_code_asm_get_url_new (url, target);
+  g_free (url);
+  g_free (target);
+  vivi_code_assembler_add_code (assembler, code);
+  g_object_unref (code);
+}
+
+static void
 vivi_disassemble_store (ViviCodeAssembler *assembler, SwfdecBits *bits)
 {
   ViviCodeAsm *code;
@@ -362,8 +379,10 @@ vivi_disassemble_script (SwfdecScript *script)
 	    g_object_unref (fun);
 	  }
 	  break;
-        case SWFDEC_AS_ACTION_GOTO_FRAME:
         case SWFDEC_AS_ACTION_GET_URL:
+	  vivi_disassemble_get_url (assembler, &bits, script->version);
+	  break;
+        case SWFDEC_AS_ACTION_GOTO_FRAME:
         case SWFDEC_AS_ACTION_STRICT_MODE:
         case SWFDEC_AS_ACTION_WAIT_FOR_FRAME:
         case SWFDEC_AS_ACTION_SET_TARGET:


More information about the Swfdec-commits mailing list