[Swfdec-commits] 19 commits - configure.ac swfdec/swfdec_as_context.c swfdec/swfdec_as_interpret.c swfdec/swfdec_constant_pool.c test/trace vivified/code

Pekka Lampila medar at kemper.freedesktop.org
Wed May 28 04:39:52 PDT 2008


 configure.ac                                       |    3 
 swfdec/swfdec_as_context.c                         |    4 
 swfdec/swfdec_as_interpret.c                       |   18 +-
 swfdec/swfdec_constant_pool.c                      |    6 
 test/trace/Makefile.am                             |   27 +++
 test/trace/crash-0.7.1-throw-5.swf                 |binary
 test/trace/crash-0.7.1-throw-5.swf.trace           |    2 
 test/trace/crash-0.7.1-throw-6.swf                 |binary
 test/trace/crash-0.7.1-throw-6.swf.trace           |    2 
 test/trace/crash-0.7.1-throw-7.swf                 |binary
 test/trace/crash-0.7.1-throw-7.swf.trace           |    2 
 test/trace/crash-0.7.1-throw-8.swf                 |binary
 test/trace/crash-0.7.1-throw-8.swf.trace           |    2 
 test/trace/crash-0.7.1-throw.as                    |   19 ++
 test/trace/try-finally-5.swf                       |binary
 test/trace/try-finally-5.swf.trace                 |    4 
 test/trace/try-finally-6.swf                       |binary
 test/trace/try-finally-6.swf.trace                 |    4 
 test/trace/try-finally-7.swf                       |binary
 test/trace/try-finally-7.swf.trace                 |    4 
 test/trace/try-finally-8.swf                       |binary
 test/trace/try-finally-8.swf.trace                 |    4 
 test/trace/try-finally.as                          |   18 ++
 test/trace/try-flags-5.swf                         |binary
 test/trace/try-flags-5.swf.trace                   |    4 
 test/trace/try-flags-6.swf                         |binary
 test/trace/try-flags-6.swf.trace                   |    4 
 test/trace/try-flags-7.swf                         |binary
 test/trace/try-flags-7.swf.trace                   |    4 
 test/trace/try-flags-8.swf                         |binary
 test/trace/try-flags-8.swf.trace                   |    4 
 test/trace/try-flags.as                            |   71 +++++++++
 vivified/code/compiler.c                           |    9 -
 vivified/code/test/compiler/Makefile.am            |   10 +
 vivified/code/test/compiler/asm_get_url2.as        |    5 
 vivified/code/test/compiler/asm_get_url2.as.expect |    6 
 vivified/code/test/compiler/asm_pool.as            |    5 
 vivified/code/test/compiler/asm_pool.as.expect     |    6 
 vivified/code/test/compiler/asm_try.as             |   10 +
 vivified/code/test/compiler/asm_try.as.expect      |   14 +
 vivified/code/vivi_code_asm_get_url2.c             |   26 +++
 vivified/code/vivi_code_asm_get_url2.h             |   12 -
 vivified/code/vivi_code_asm_try.c                  |    5 
 vivified/code/vivi_parser.c                        |  163 ++++++++++++++++++++-
 44 files changed, 446 insertions(+), 31 deletions(-)

New commits:
commit 6842d12bdb33d92ff644b12f4508c332c266a16e
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed May 28 14:34:14 2008 +0300

    Add a test for the effects of has_catch and has_finally flags in try action

diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am
index e7342d7..7bc4bb4 100644
--- a/test/trace/Makefile.am
+++ b/test/trace/Makefile.am
@@ -3574,6 +3574,15 @@ EXTRA_DIST = \
 	try-finally-7.swf.trace \
 	try-finally-8.swf \
 	try-finally-8.swf.trace \
+	try-flags.as \
+	try-flags-5.swf \
+	try-flags-5.swf.trace \
+	try-flags-6.swf \
+	try-flags-6.swf.trace \
+	try-flags-7.swf \
+	try-flags-7.swf.trace \
+	try-flags-8.swf \
+	try-flags-8.swf.trace \
 	try-jump.as \
 	try-jump-6.swf \
 	try-jump-6.swf.trace \
diff --git a/test/trace/try-flags-5.swf b/test/trace/try-flags-5.swf
new file mode 100644
index 0000000..ffa18b5
Binary files /dev/null and b/test/trace/try-flags-5.swf differ
diff --git a/test/trace/try-flags-5.swf.trace b/test/trace/try-flags-5.swf.trace
new file mode 100644
index 0000000..0555767
--- /dev/null
+++ b/test/trace/try-flags-5.swf.trace
@@ -0,0 +1,4 @@
+Finally
+Catch
+Catch
+Try
diff --git a/test/trace/try-flags-6.swf b/test/trace/try-flags-6.swf
new file mode 100644
index 0000000..51b8b67
Binary files /dev/null and b/test/trace/try-flags-6.swf differ
diff --git a/test/trace/try-flags-6.swf.trace b/test/trace/try-flags-6.swf.trace
new file mode 100644
index 0000000..0555767
--- /dev/null
+++ b/test/trace/try-flags-6.swf.trace
@@ -0,0 +1,4 @@
+Finally
+Catch
+Catch
+Try
diff --git a/test/trace/try-flags-7.swf b/test/trace/try-flags-7.swf
new file mode 100644
index 0000000..f6aeeeb
Binary files /dev/null and b/test/trace/try-flags-7.swf differ
diff --git a/test/trace/try-flags-7.swf.trace b/test/trace/try-flags-7.swf.trace
new file mode 100644
index 0000000..0555767
--- /dev/null
+++ b/test/trace/try-flags-7.swf.trace
@@ -0,0 +1,4 @@
+Finally
+Catch
+Catch
+Try
diff --git a/test/trace/try-flags-8.swf b/test/trace/try-flags-8.swf
new file mode 100644
index 0000000..99b0036
Binary files /dev/null and b/test/trace/try-flags-8.swf differ
diff --git a/test/trace/try-flags-8.swf.trace b/test/trace/try-flags-8.swf.trace
new file mode 100644
index 0000000..0555767
--- /dev/null
+++ b/test/trace/try-flags-8.swf.trace
@@ -0,0 +1,4 @@
+Finally
+Catch
+Catch
+Try
diff --git a/test/trace/try-flags.as b/test/trace/try-flags.as
new file mode 100644
index 0000000..969a6bc
--- /dev/null
+++ b/test/trace/try-flags.as
@@ -0,0 +1,71 @@
+// vivi-compile -v 7 -s 200x150 -r 15 -o try-flags.swf try-flags.as
+
+try {
+  asm {
+    try has_catch has_finally "e" catch_start_1 finally_start_1 end_1
+    push "Try"
+    throw
+catch_start_1:
+    push "Catch"
+    throw
+finally_start_1:
+    push "Finally"
+    throw
+end_1:
+  }
+} catch (e) {
+  trace (e);
+}
+
+try {
+  asm {
+    try has_catch "e" catch_start_2 finally_start_2 end_2
+    push "Try"
+    throw
+catch_start_2:
+    push "Catch"
+    throw
+finally_start_2:
+    push "Finally"
+    throw
+end_2:
+  }
+} catch (e) {
+  trace (e);
+}
+
+try {
+  asm {
+    try has_finally "e" catch_start_3 finally_start_3 end_3
+    push "Try"
+    throw
+catch_start_3:
+    push "Catch"
+    throw
+finally_start_3:
+    push "Finally"
+    throw
+end_3:
+  }
+} catch (e) {
+  trace (e);
+}
+
+try {
+  asm {
+    try "e" catch_start_4 finally_start_4 end_4
+    push "Try"
+    throw
+catch_start_4:
+    push "Catch"
+    throw
+finally_start_4:
+    push "Finally"
+    throw
+end_4:
+  }
+} catch (e) {
+  trace (e);
+}
+
+getURL ("fscommand:quit", "");
commit 2c0e4c200e1c7f33aba6bce0871d72ab7a603bb1
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed May 28 14:29:39 2008 +0300

    Add a test for the earlier exception handling fix

diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am
index 4c13bce..e7342d7 100644
--- a/test/trace/Makefile.am
+++ b/test/trace/Makefile.am
@@ -797,6 +797,15 @@ EXTRA_DIST = \
 	crash-0.7.1-getTextExtent-8.swf \
 	crash-0.7.1-getTextExtent-8.swf.trace \
 	crash-0.7.1-getTextExtent.as \
+	crash-0.7.1-throw-5.swf \
+	crash-0.7.1-throw-5.swf.trace \
+	crash-0.7.1-throw-6.swf \
+	crash-0.7.1-throw-6.swf.trace \
+	crash-0.7.1-throw-7.swf \
+	crash-0.7.1-throw-7.swf.trace \
+	crash-0.7.1-throw-8.swf \
+	crash-0.7.1-throw-8.swf.trace \
+	crash-0.7.1-throw.as \
 	createTextField-returnvalue-5.swf \
 	createTextField-returnvalue-5.swf.trace \
 	createTextField-returnvalue-6.swf \
diff --git a/test/trace/crash-0.7.1-throw-5.swf b/test/trace/crash-0.7.1-throw-5.swf
new file mode 100644
index 0000000..62e4325
Binary files /dev/null and b/test/trace/crash-0.7.1-throw-5.swf differ
diff --git a/test/trace/crash-0.7.1-throw-5.swf.trace b/test/trace/crash-0.7.1-throw-5.swf.trace
new file mode 100644
index 0000000..13e150f
--- /dev/null
+++ b/test/trace/crash-0.7.1-throw-5.swf.trace
@@ -0,0 +1,2 @@
+Throw as next action after throwing from ending block
+Try
diff --git a/test/trace/crash-0.7.1-throw-6.swf b/test/trace/crash-0.7.1-throw-6.swf
new file mode 100644
index 0000000..47727e9
Binary files /dev/null and b/test/trace/crash-0.7.1-throw-6.swf differ
diff --git a/test/trace/crash-0.7.1-throw-6.swf.trace b/test/trace/crash-0.7.1-throw-6.swf.trace
new file mode 100644
index 0000000..13e150f
--- /dev/null
+++ b/test/trace/crash-0.7.1-throw-6.swf.trace
@@ -0,0 +1,2 @@
+Throw as next action after throwing from ending block
+Try
diff --git a/test/trace/crash-0.7.1-throw-7.swf b/test/trace/crash-0.7.1-throw-7.swf
new file mode 100644
index 0000000..dadde26
Binary files /dev/null and b/test/trace/crash-0.7.1-throw-7.swf differ
diff --git a/test/trace/crash-0.7.1-throw-7.swf.trace b/test/trace/crash-0.7.1-throw-7.swf.trace
new file mode 100644
index 0000000..13e150f
--- /dev/null
+++ b/test/trace/crash-0.7.1-throw-7.swf.trace
@@ -0,0 +1,2 @@
+Throw as next action after throwing from ending block
+Try
diff --git a/test/trace/crash-0.7.1-throw-8.swf b/test/trace/crash-0.7.1-throw-8.swf
new file mode 100644
index 0000000..fd06b70
Binary files /dev/null and b/test/trace/crash-0.7.1-throw-8.swf differ
diff --git a/test/trace/crash-0.7.1-throw-8.swf.trace b/test/trace/crash-0.7.1-throw-8.swf.trace
new file mode 100644
index 0000000..13e150f
--- /dev/null
+++ b/test/trace/crash-0.7.1-throw-8.swf.trace
@@ -0,0 +1,2 @@
+Throw as next action after throwing from ending block
+Try
diff --git a/test/trace/crash-0.7.1-throw.as b/test/trace/crash-0.7.1-throw.as
new file mode 100644
index 0000000..2e7cb79
--- /dev/null
+++ b/test/trace/crash-0.7.1-throw.as
@@ -0,0 +1,19 @@
+// vivi-compile -v 7 -s 200x150 -r 15 -o crash-0.7.1-throw.swf crash-0.7.1-throw.as
+
+trace ("Throw as next action after throwing from ending block");
+
+try {
+  asm {
+    try has_finally "" finally_start finally_start end
+    push "Try"
+    throw
+  finally_start:
+    push "Catch2"
+  end:
+    throw
+  }
+} catch (e) {
+  trace (e);
+}
+
+getURL ("fscommand:quit", "");
commit 4b68aa25f63bc751be0840ed19c44be4ac976826
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed May 28 14:13:10 2008 +0300

    If use_catch flag has not been set, don't take catch_size into account

diff --git a/swfdec/swfdec_as_interpret.c b/swfdec/swfdec_as_interpret.c
index 373849a..a6d7044 100644
--- a/swfdec/swfdec_as_interpret.c
+++ b/swfdec/swfdec_as_interpret.c
@@ -2692,8 +2692,10 @@ swfdec_action_try (SwfdecAsContext *cx, guint action, const guint8 *data, guint
   try_data->finally_size = swfdec_bits_get_u16 (&bits);
   if (use_catch)
     try_data->catch_start = data + len + try_size;
-  if (use_finally)
-    try_data->finally_start = data + len + try_size + try_data->catch_size;
+  if (use_finally) {
+    try_data->finally_start = data + len + try_size +
+      (use_catch ? try_data->catch_size : 0);
+  }
 
   if (try_data->use_register) {
     try_data->register_number = swfdec_bits_get_u8 (&bits);
commit b70c7207b2e5cc833e1ce39a45caffd8bfc81025
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed May 28 14:07:35 2008 +0300

    Fix exception fired when ending a block not handled immediately
    
    This allowed one more action to be ran after throwing and catching, could lead
    to assert

diff --git a/swfdec/swfdec_as_context.c b/swfdec/swfdec_as_context.c
index 397ebb7..6bb28e9 100644
--- a/swfdec/swfdec_as_context.c
+++ b/swfdec/swfdec_as_context.c
@@ -924,7 +924,11 @@ start:
       pc = frame->pc;
       if (frame != context->frame)
 	goto start;
+      if (context->exception)
+	break;
     }
+    if (context->exception)
+      continue;
 
     /* decode next action */
     action = *pc;
commit 0e330ec0f91f86d03d5b55512c7d77e6f83c84b8
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed May 28 13:29:17 2008 +0300

    Fix -a option for the compiler (the value was not initialized)

diff --git a/vivified/code/compiler.c b/vivified/code/compiler.c
index 22dce75..f622458 100644
--- a/vivified/code/compiler.c
+++ b/vivified/code/compiler.c
@@ -87,7 +87,7 @@ main (int argc, char *argv[])
   char *size_string = NULL;
   SwfdecRect size_rect = { 0, 0, 2000, 3000 };
   const char *output_filename = NULL;
-  gboolean use_asm;
+  gboolean use_asm = FALSE;
   GError *error = NULL;
 
   GOptionEntry options[] = {
commit 996fe5f1cc934dd66980d8c501041d7d6a336d76
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Mon May 26 17:39:29 2008 +0300

    Fix try actions that have only a catch statement

diff --git a/swfdec/swfdec_as_interpret.c b/swfdec/swfdec_as_interpret.c
index 40fca64..373849a 100644
--- a/swfdec/swfdec_as_interpret.c
+++ b/swfdec/swfdec_as_interpret.c
@@ -2591,7 +2591,7 @@ swfdec_action_try_end_catch (SwfdecAsFrame *frame, gpointer data)
     try_data->scope_object = NULL;
   }
 
-  if (swfdec_as_context_catch (cx, &val))
+  if (try_data->finally_start && swfdec_as_context_catch (cx, &val))
   {
     // we got an exception while in catch block:
     // create new block for finally to pass on the exception
commit 5b1e294d20714058fb6d31475be35fb03a6cd90e
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Mon May 26 17:19:22 2008 +0300

    Add a test for try statement with only finally block

diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am
index abd5ad5..4c13bce 100644
--- a/test/trace/Makefile.am
+++ b/test/trace/Makefile.am
@@ -3556,6 +3556,15 @@ EXTRA_DIST = \
 	try-7.swf.trace \
 	try-8.swf \
 	try-8.swf.trace \
+	try-finally.as \
+	try-finally-5.swf \
+	try-finally-5.swf.trace \
+	try-finally-6.swf \
+	try-finally-6.swf.trace \
+	try-finally-7.swf \
+	try-finally-7.swf.trace \
+	try-finally-8.swf \
+	try-finally-8.swf.trace \
 	try-jump.as \
 	try-jump-6.swf \
 	try-jump-6.swf.trace \
diff --git a/test/trace/try-finally-5.swf b/test/trace/try-finally-5.swf
new file mode 100644
index 0000000..303d1db
Binary files /dev/null and b/test/trace/try-finally-5.swf differ
diff --git a/test/trace/try-finally-5.swf.trace b/test/trace/try-finally-5.swf.trace
new file mode 100644
index 0000000..b3bdc43
--- /dev/null
+++ b/test/trace/try-finally-5.swf.trace
@@ -0,0 +1,4 @@
+Try
+Finally
+Finally
+Error
diff --git a/test/trace/try-finally-6.swf b/test/trace/try-finally-6.swf
new file mode 100644
index 0000000..ff7015c
Binary files /dev/null and b/test/trace/try-finally-6.swf differ
diff --git a/test/trace/try-finally-6.swf.trace b/test/trace/try-finally-6.swf.trace
new file mode 100644
index 0000000..b3bdc43
--- /dev/null
+++ b/test/trace/try-finally-6.swf.trace
@@ -0,0 +1,4 @@
+Try
+Finally
+Finally
+Error
diff --git a/test/trace/try-finally-7.swf b/test/trace/try-finally-7.swf
new file mode 100644
index 0000000..7c8cdf5
Binary files /dev/null and b/test/trace/try-finally-7.swf differ
diff --git a/test/trace/try-finally-7.swf.trace b/test/trace/try-finally-7.swf.trace
new file mode 100644
index 0000000..b3bdc43
--- /dev/null
+++ b/test/trace/try-finally-7.swf.trace
@@ -0,0 +1,4 @@
+Try
+Finally
+Finally
+Error
diff --git a/test/trace/try-finally-8.swf b/test/trace/try-finally-8.swf
new file mode 100644
index 0000000..85b7b7b
Binary files /dev/null and b/test/trace/try-finally-8.swf differ
diff --git a/test/trace/try-finally-8.swf.trace b/test/trace/try-finally-8.swf.trace
new file mode 100644
index 0000000..b3bdc43
--- /dev/null
+++ b/test/trace/try-finally-8.swf.trace
@@ -0,0 +1,4 @@
+Try
+Finally
+Finally
+Error
diff --git a/test/trace/try-finally.as b/test/trace/try-finally.as
new file mode 100644
index 0000000..b50443b
--- /dev/null
+++ b/test/trace/try-finally.as
@@ -0,0 +1,18 @@
+// makeswf -v 7 -r 1 -o try-finally-7.swf try-finally.as
+
+try {
+  try {
+    trace ("Try");
+  } finally {
+    trace ("Finally");
+  };
+  try {
+    throw "Error";
+  } finally {
+    trace ("Finally");
+  };
+} catch (e) {
+  trace (e);
+};
+
+getURL ("FSCommand:quit", "");
commit 5a10bbaa42cd8d9f1edb806c24ca128e8b3b1a17
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Mon May 26 17:17:19 2008 +0300

    Fix handling of try actions with only finally statement

diff --git a/swfdec/swfdec_as_interpret.c b/swfdec/swfdec_as_interpret.c
index 831f8a3..40fca64 100644
--- a/swfdec/swfdec_as_interpret.c
+++ b/swfdec/swfdec_as_interpret.c
@@ -2584,10 +2584,12 @@ swfdec_action_try_end_catch (SwfdecAsFrame *frame, gpointer data)
 
   cx = SWFDEC_AS_OBJECT (frame)->context;
 
-  g_assert (frame->scope_chain->data == try_data->scope_object);
-  frame->scope_chain =
-    g_slist_delete_link (frame->scope_chain, frame->scope_chain);
-  try_data->scope_object = NULL;
+  if (try_data->scope_object) {
+    g_assert (frame->scope_chain->data == try_data->scope_object);
+    frame->scope_chain =
+      g_slist_delete_link (frame->scope_chain, frame->scope_chain);
+    try_data->scope_object = NULL;
+  }
 
   if (swfdec_as_context_catch (cx, &val))
   {
@@ -2691,7 +2693,7 @@ swfdec_action_try (SwfdecAsContext *cx, guint action, const guint8 *data, guint
   if (use_catch)
     try_data->catch_start = data + len + try_size;
   if (use_finally)
-    try_data->finally_start = try_data->catch_start + try_data->catch_size;
+    try_data->finally_start = data + len + try_size + try_data->catch_size;
 
   if (try_data->use_register) {
     try_data->register_number = swfdec_bits_get_u8 (&bits);
commit 98e99c1db29da5a591ddf21f5ad80f3350553b72
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Mon May 26 16:21:15 2008 +0300

    vivi-compile: Print the error message to the user when script assembling fails

diff --git a/vivified/code/compiler.c b/vivified/code/compiler.c
index a41f1b6..22dce75 100644
--- a/vivified/code/compiler.c
+++ b/vivified/code/compiler.c
@@ -195,11 +195,12 @@ main (int argc, char *argv[])
     g_object_unref (assembler);
   } else {
     SwfdecScript *script =
-      vivi_code_assembler_assemble_script (assembler, version, NULL);
+      vivi_code_assembler_assemble_script (assembler, version, &error);
     g_object_unref (assembler);
 
-    if (script == NULL) {
-      g_printerr ("Script assembling failed\n");
+    if (error != NULL) {
+      g_printerr ("Script assembling failed: %s\n", error->message);
+      g_error_free (error);
       return 1;
     }
 
commit bf16ba892200ec6ed7068a97ee1e5c7055af0be0
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Mon May 26 16:03:57 2008 +0300

    Add a vivi-compile test for asm try statements

diff --git a/vivified/code/test/compiler/Makefile.am b/vivified/code/test/compiler/Makefile.am
index c60797a..b17c4b0 100644
--- a/vivified/code/test/compiler/Makefile.am
+++ b/vivified/code/test/compiler/Makefile.am
@@ -36,6 +36,8 @@ EXTRA_DIST = \
 	asm_push.as.expect \
 	asm_store.as \
 	asm_store.as.expect \
+	asm_try.as \
+	asm_try.as.expect \
 	assignment.as \
 	assignment.as.expect \
 	assignment_member.as \
diff --git a/vivified/code/test/compiler/asm_try.as b/vivified/code/test/compiler/asm_try.as
new file mode 100644
index 0000000..987687f
--- /dev/null
+++ b/vivified/code/test/compiler/asm_try.as
@@ -0,0 +1,10 @@
+asm {
+  try has_catch has_finally reserved1 reserved2 reserved3 reserved4 reserved5 1 catch_start finally_start end
+  try "a" catch_start finally_start end
+catch_start:
+  try has_catch "a" finally_start end end
+finally_start:
+  try "a" end end end
+  try has_catch has_finally 1 end end end
+end:
+}
diff --git a/vivified/code/test/compiler/asm_try.as.expect b/vivified/code/test/compiler/asm_try.as.expect
new file mode 100644
index 0000000..e2bb40f
--- /dev/null
+++ b/vivified/code/test/compiler/asm_try.as.expect
@@ -0,0 +1,14 @@
+asm {
+  try has_catch has_finally reserved1 reserved2 reserved3 reserved4 reserved5 1 catch_start finally_start end
+  try "a" catch_start finally_start end
+
+catch_start:
+  try has_catch "a" finally_start end end
+
+finally_start:
+  try "a" end end end
+  try has_catch has_finally 1 end end end
+
+end:
+  end
+}
commit fbe4730c5ef5b1c84d50e75c93bc488fc32cd5cd
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Mon May 26 16:03:06 2008 +0300

    Parse try asm statements

diff --git a/vivified/code/vivi_parser.c b/vivified/code/vivi_parser.c
index 878fc0d..67d9121 100644
--- a/vivified/code/vivi_parser.c
+++ b/vivified/code/vivi_parser.c
@@ -34,6 +34,7 @@
 #include "vivi_code_asm_pool.h"
 #include "vivi_code_asm_push.h"
 #include "vivi_code_asm_store.h"
+#include "vivi_code_asm_try.h"
 #include "vivi_code_assignment.h"
 #include "vivi_code_binary_default.h"
 #include "vivi_code_bit_not.h"
@@ -1010,6 +1011,101 @@ parse_asm_store (ParseData *data)
 }
 
 static ViviCodeAsm *
+parse_asm_try (ParseData *data)
+{
+  gboolean has_catch, has_finally;
+  guint reserved_flags, id;
+  const char *name;
+  char *variable;
+  ViviCodeLabel *label_catch, *label_finally, *label_end;
+  ViviCodeAsm *try_;
+
+  has_catch = FALSE;
+  has_finally = FALSE;
+  reserved_flags = 0;
+
+  while (peek_identifier (data) && !peek_line_terminator (data)) {
+    name = parse_identifier_value (data);
+
+    if (!g_ascii_strcasecmp (name, "has_catch")) {
+      has_catch = TRUE;
+    } else if (!g_ascii_strcasecmp (name, "has_finally")) {
+      has_finally = TRUE;
+    } else {
+      guint i;
+
+      for (i = 0; i < 5; i++) {
+	char *str = g_strdup_printf ("reserved%i", i + 1);
+	if (!g_ascii_strcasecmp (name, str)) {
+	  g_free (str);
+	  break;
+	}
+	g_free (str);
+      }
+      if (i < 5) {
+	reserved_flags |= (1 << i);
+      } else {
+	vivi_parser_error (data, "Unknown flag for try: %s", name);
+      }
+    }
+  }
+
+  id = 0; // silence compiler warning
+  if (peek_string (data)) {
+    variable = g_strdup (parse_string_value (data));
+  } else if (peek_numeric (data)) {
+    // TODO: warning/error if not int
+    variable = NULL;
+    id = swfdec_as_double_to_integer (parse_numeric_value (data));
+    if (id > G_MAXUINT8) {
+      vivi_parser_error (data, "Too large register number for try: %i", id);
+      id = 0;
+    }
+  } else {
+    vivi_parser_error_unexpected_or (data, TOKEN_STRING, TOKEN_NUMBER,
+	TOKEN_NONE);
+    variable = g_strdup ("undefined");
+  }
+
+  name = parse_identifier_value (data);
+  label_catch = vivi_parser_get_label (data, name);
+  if (label_catch == NULL) {
+    label_catch = VIVI_CODE_LABEL (vivi_code_label_new (name));
+    vivi_parser_add_waiting_label (data, label_catch);
+  }
+
+  name = parse_identifier_value (data);
+  label_finally = vivi_parser_get_label (data, name);
+  if (label_finally == NULL) {
+    label_finally = VIVI_CODE_LABEL (vivi_code_label_new (name));
+    vivi_parser_add_waiting_label (data, label_finally);
+  }
+
+  name = parse_identifier_value (data);
+  label_end = vivi_parser_get_label (data, name);
+  if (label_end == NULL) {
+    label_end = VIVI_CODE_LABEL (vivi_code_label_new (name));
+    vivi_parser_add_waiting_label (data, label_end);
+  }
+
+  parse_automatic_semicolon (data);
+
+  if (variable != NULL) {
+    try_ = vivi_code_asm_try_new (label_catch, label_finally, label_end,
+	variable);
+  } else {
+    try_ = vivi_code_asm_try_new_register (label_catch, label_finally,
+	label_end, id);
+  }
+  vivi_code_asm_try_set_has_catch (VIVI_CODE_ASM_TRY (try_), has_catch);
+  vivi_code_asm_try_set_has_finally (VIVI_CODE_ASM_TRY (try_), has_finally);
+  vivi_code_asm_try_set_reserved_flags (VIVI_CODE_ASM_TRY (try_),
+      reserved_flags);
+
+  return try_;
+}
+
+static ViviCodeAsm *
 parse_asm_pool (ParseData *data)
 {
   SwfdecConstantPool *pool;
@@ -1181,7 +1277,8 @@ static const AsmStatement asm_statements[] = {
   { "get_url2", NULL, parse_asm_get_url2 },
   { "pool", NULL, parse_asm_pool },
   { "push", NULL, parse_asm_push },
-  { "store", NULL, parse_asm_store }
+  { "store", NULL, parse_asm_store },
+  { "try", NULL, parse_asm_try }
 };
 #if 0
 DEFAULT_ASM (GotoFrame, goto_frame, SWFDEC_AS_ACTION_GOTO_FRAME)
@@ -1213,6 +1310,8 @@ parse_asm_code (ParseData *data)
 
   if (try_parse_token (data, TOKEN_THROW)) {
     identifier = g_strdup ("throw");
+  } else if (try_parse_token (data, TOKEN_TRY)) {
+    identifier = g_strdup ("try");
   } else if (try_parse_token (data, TOKEN_IMPLEMENTS)) {
     identifier = g_strdup ("implements");
   } else if (try_parse_token (data, TOKEN_DELETE)) {
@@ -1294,6 +1393,7 @@ parse_asm_statement (ParseData *data)
       g_object_unref (code);
     } while (peek_token (data, TOKEN_IDENTIFIER) ||
 	peek_token (data, TOKEN_THROW) ||
+	peek_token (data, TOKEN_TRY) ||
 	peek_token (data, TOKEN_IMPLEMENTS) ||
 	peek_token (data, TOKEN_DELETE) ||
 	peek_token (data, TOKEN_RETURN) ||
commit d40ec2aafc9217c318020e257d610ae2fbb22ae9
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Mon May 26 16:00:59 2008 +0300

    Don't output "use_register" flag for try asm statement. Fix a typo
    
    use_register depends on whether a string or a number is given

diff --git a/vivified/code/vivi_code_asm_try.c b/vivified/code/vivi_code_asm_try.c
index 1a29f38..c92b1c5 100644
--- a/vivified/code/vivi_code_asm_try.c
+++ b/vivified/code/vivi_code_asm_try.c
@@ -192,12 +192,9 @@ vivi_code_asm_try_print (ViviCodeToken *token, ViviCodePrinter *printer)
   if (try_->has_finally)
     vivi_code_printer_print (printer, "has_finally ");
 
-  if (try_->use_register)
-    vivi_code_printer_print (printer, "use_register ");
-
   for (i = 0; i < 5; i++) {
     if (try_->reserved_flags & (1 << i)) {
-      char *str = g_strdup_printf ("reserverd%i ", i + 1);
+      char *str = g_strdup_printf ("reserved%i ", i + 1);
       vivi_code_printer_print (printer, str);
       g_free (str);
     }
commit 4b0cc3a08a4a528ea8c63d63cfdf8bc539587f48
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Mon May 26 14:39:07 2008 +0300

    Only require lex in configure when building with vivi

diff --git a/configure.ac b/configure.ac
index 476649f..6fd23d9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -53,8 +53,6 @@ AM_PROG_CC_STDC
 AM_PROG_CC_C_O
 AM_PROG_AS
 AC_PROG_AWK
-dnl FIXME only require lex for vivi
-AM_PROG_LEX
 
 AC_HEADER_STDC
 
@@ -231,6 +229,7 @@ AC_ARG_ENABLE(vivified,
 	enable_vivi=$enableval,
 	enable_vivi="no")
 if test "$enable_vivi" = "yes"; then
+	AM_PROG_LEX
 	MING_REQUIRED=0.4.0.beta5
 	VIVI_GTK_REQUIRED=2.11.6
 	VIVI_GLIB_REQUIRED=2.14
commit 6b5bf86093189def11587831a01990b03343c449
Merge: c869345... ab5f00a...
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Mon May 26 14:25:00 2008 +0300

    Merge branch 'master' of ssh://medar@git.freedesktop.org/git/swfdec/swfdec

commit c8693454b4d6dbdc3a9564b4bf502a0430f7fada
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Mon May 26 13:37:22 2008 +0300

    Add a test for compiling pool asm statement

diff --git a/vivified/code/test/compiler/Makefile.am b/vivified/code/test/compiler/Makefile.am
index 97eccd6..c60797a 100644
--- a/vivified/code/test/compiler/Makefile.am
+++ b/vivified/code/test/compiler/Makefile.am
@@ -30,6 +30,8 @@ EXTRA_DIST = \
 	asm_get_url2.as.expect \
 	asm_label.as \
 	asm_label.as.expect \
+	asm_pool.as \
+	asm_pool.as.expect \
 	asm_push.as \
 	asm_push.as.expect \
 	asm_store.as \
diff --git a/vivified/code/test/compiler/asm_pool.as b/vivified/code/test/compiler/asm_pool.as
new file mode 100644
index 0000000..2452e95
--- /dev/null
+++ b/vivified/code/test/compiler/asm_pool.as
@@ -0,0 +1,5 @@
+asm {
+  pool
+  pool "Hello"
+  pool "Hello", ", ", "World", "!"
+}
diff --git a/vivified/code/test/compiler/asm_pool.as.expect b/vivified/code/test/compiler/asm_pool.as.expect
new file mode 100644
index 0000000..2001680
--- /dev/null
+++ b/vivified/code/test/compiler/asm_pool.as.expect
@@ -0,0 +1,6 @@
+asm {
+  pool
+  pool "Hello"
+  pool "Hello", ", ", "World", "!"
+  end
+}
commit 2919f279b9a78d425b31848f55582eaf34914171
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Mon May 26 13:36:18 2008 +0300

    Allow empty SwfdecConstantPools

diff --git a/swfdec/swfdec_constant_pool.c b/swfdec/swfdec_constant_pool.c
index 487af45..7cf70b3 100644
--- a/swfdec/swfdec_constant_pool.c
+++ b/swfdec/swfdec_constant_pool.c
@@ -69,10 +69,8 @@ swfdec_constant_pool_new (SwfdecAsContext *context, SwfdecBuffer *buffer, guint
   swfdec_bits_init (&bits, buffer);
 
   n = swfdec_bits_get_u16 (&bits);
-  if (n == 0)
-    return NULL;
 
-  size = sizeof (SwfdecConstantPool) + (n - 1) * sizeof (char *);
+  size = sizeof (SwfdecConstantPool) + (MAX (1, n) - 1) * sizeof (char *);
   pool = g_slice_alloc0 (size);
   pool->n_strings = n;
   for (i = 0; i < n; i++) {
@@ -142,7 +140,7 @@ swfdec_constant_pool_unref (SwfdecConstantPool *pool)
     }
   }
   swfdec_buffer_unref (pool->buffer);
-  g_slice_free1 (sizeof (SwfdecConstantPool) + (pool->n_strings - 1) * sizeof (char *), pool);
+  g_slice_free1 (sizeof (SwfdecConstantPool) + (MAX (1, pool->n_strings) - 1) * sizeof (char *), pool);
 }
 
 /**
commit d1bbbeef5d9a5b30f1aa50ca141105c1c9bdd827
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Mon May 26 13:29:39 2008 +0300

    Implement the parsing of pool asm statements

diff --git a/vivified/code/vivi_parser.c b/vivified/code/vivi_parser.c
index f08324a..878fc0d 100644
--- a/vivified/code/vivi_parser.c
+++ b/vivified/code/vivi_parser.c
@@ -31,6 +31,7 @@
 #include "vivi_code_and.h"
 #include "vivi_code_asm_code_default.h"
 #include "vivi_code_asm_get_url2.h"
+#include "vivi_code_asm_pool.h"
 #include "vivi_code_asm_push.h"
 #include "vivi_code_asm_store.h"
 #include "vivi_code_assignment.h"
@@ -1009,6 +1010,40 @@ parse_asm_store (ParseData *data)
 }
 
 static ViviCodeAsm *
+parse_asm_pool (ParseData *data)
+{
+  SwfdecConstantPool *pool;
+  ViviCodeAsm *code;
+  SwfdecBots *bots;
+  SwfdecBuffer *buffer;
+  guint num;
+
+  bots = swfdec_bots_open ();
+  swfdec_bots_put_u16 (bots, 0);
+
+  num = 0;
+  if (!try_parse_restricted_semicolon (data)) {
+    do {
+      swfdec_bots_put_string (bots, parse_string_value (data));
+      num++;
+    } while (try_parse_token (data, TOKEN_COMMA));
+
+    parse_automatic_semicolon (data);
+  }
+
+  *(guint16 *)bots->data = GUINT16_TO_LE (num);
+
+  // FIXME: version
+  buffer =  swfdec_bots_close (bots);
+  pool = swfdec_constant_pool_new (NULL, buffer, 8);
+  swfdec_buffer_unref (buffer);
+  code = vivi_code_asm_pool_new (pool);
+  swfdec_constant_pool_unref (pool);
+
+  return code;
+}
+
+static ViviCodeAsm *
 parse_asm_push (ParseData *data)
 {
   ViviCodeAsmPush *push;
@@ -1144,6 +1179,7 @@ static const AsmStatement asm_statements[] = {
 #include "vivi_code_defaults.h"
 #undef DEFAULT_ASM
   { "get_url2", NULL, parse_asm_get_url2 },
+  { "pool", NULL, parse_asm_pool },
   { "push", NULL, parse_asm_push },
   { "store", NULL, parse_asm_store }
 };
commit 1b3797315b4102812ffcebf5646c92f48cf6ce3b
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Mon May 26 13:04:59 2008 +0300

    Get rid of duplication of get_url2's flag name list

diff --git a/vivified/code/vivi_code_asm_get_url2.c b/vivified/code/vivi_code_asm_get_url2.c
index 03bb0f4..53bde1a 100644
--- a/vivified/code/vivi_code_asm_get_url2.c
+++ b/vivified/code/vivi_code_asm_get_url2.c
@@ -64,6 +64,28 @@ static const char *flag_names[8] = {
   "variables"
 };
 
+int
+vivi_code_asm_get_url2_flag_name_to_value (const char *name)
+{
+  guint i;
+
+  for (i = 0; i < G_N_ELEMENTS (flag_names); i++) {
+    if (!g_ascii_strcasecmp (flag_names[i], name))
+      return i;
+  }
+
+  return -1;
+}
+
+const char *
+vivi_code_asm_get_url2_flag_value_to_name (guint value)
+{
+  if (value >= G_N_ELEMENTS (flag_names))
+    return NULL;
+
+  return flag_names[value];
+}
+
 static void
 vivi_code_asm_get_url2_print (ViviCodeToken *token, ViviCodePrinter *printer)
 {
diff --git a/vivified/code/vivi_code_asm_get_url2.h b/vivified/code/vivi_code_asm_get_url2.h
index 82e39f7..552d2a6 100644
--- a/vivified/code/vivi_code_asm_get_url2.h
+++ b/vivified/code/vivi_code_asm_get_url2.h
@@ -47,14 +47,16 @@ struct _ViviCodeAsmGetUrl2Class
   ViviCodeAsmCodeClass	code_class;
 };
 
-GType		vivi_code_asm_get_url2_get_type	  	(void);
+GType		vivi_code_asm_get_url2_get_type			(void);
 
-ViviCodeAsm *	vivi_code_asm_get_url2_new		(SwfdecLoaderRequest		method,
-							 gboolean			internal,
-							 gboolean			variables);
+ViviCodeAsm *	vivi_code_asm_get_url2_new			(SwfdecLoaderRequest		method,
+								 gboolean			internal,
+								 gboolean			variables);
 
-ViviCodeAsm *	vivi_code_asm_get_url2_new_from_flags	(guint				flags);
+ViviCodeAsm *	vivi_code_asm_get_url2_new_from_flags		(guint				flags);
 
+int		vivi_code_asm_get_url2_flag_name_to_value	(const char *			name);
+const char *	vivi_code_asm_get_url2_flag_value_to_name	(guint				value);
 
 G_END_DECLS
 #endif
diff --git a/vivified/code/vivi_parser.c b/vivified/code/vivi_parser.c
index 1679223..f08324a 100644
--- a/vivified/code/vivi_parser.c
+++ b/vivified/code/vivi_parser.c
@@ -1106,18 +1106,6 @@ parse_asm_push (ParseData *data)
   return VIVI_CODE_ASM (push);
 }
 
-/* FIXME: export for compiler */
-static const char *get_url2_flag_names[8] = {
-  "get",
-  "post",
-  "reserved1",
-  "reserved2",
-  "reserved3",
-  "reserved4",
-  "internal",
-  "variables"
-};
-
 static ViviCodeAsm *
 parse_asm_get_url2 (ParseData *data)
 {
@@ -1125,17 +1113,14 @@ parse_asm_get_url2 (ParseData *data)
 
   while (peek_identifier (data) && !peek_line_terminator (data)) {
     const char *name = parse_identifier_value (data);
-    guint i;
+    int value = vivi_code_asm_get_url2_flag_name_to_value (name);
 
-    for (i = 0; i < G_N_ELEMENTS (get_url2_flag_names); i++) {
-      if (!g_ascii_strcasecmp (name, get_url2_flag_names[i])) {
-	// TODO: warn if already set?
-	flags |= 1 << i;
-	break;
-      }
-    }
-    if (i == G_N_ELEMENTS (get_url2_flag_names))
+    if (value == -1) {
       vivi_parser_error (data, "Invalid flag for get_url2: %s", name);
+    } else {
+      // TODO: warn if already set?
+      flags |= 1 << value;
+    }
   }
 
   parse_automatic_semicolon (data);
commit 7a041f5c353a36fe34de3a621464ec3af34c79ac
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Mon May 26 11:51:15 2008 +0300

    Implement parsing of the get_url2 asm statement. Add a test

diff --git a/vivified/code/test/compiler/Makefile.am b/vivified/code/test/compiler/Makefile.am
index 4e494f4..97eccd6 100644
--- a/vivified/code/test/compiler/Makefile.am
+++ b/vivified/code/test/compiler/Makefile.am
@@ -22,10 +22,12 @@ EXTRA_DIST = \
 	array_literal_empty.as.expect \
 	array_literal_missing_values.as \
 	array_literal_missing_values.as.expect \
-	asm_empty.as \
-	asm_empty.as.expect \
 	asm_default.as \
 	asm_default.as.expect \
+	asm_empty.as \
+	asm_empty.as.expect \
+	asm_get_url2.as \
+	asm_get_url2.as.expect \
 	asm_label.as \
 	asm_label.as.expect \
 	asm_push.as \
diff --git a/vivified/code/test/compiler/asm_get_url2.as b/vivified/code/test/compiler/asm_get_url2.as
new file mode 100644
index 0000000..1f45d1c
--- /dev/null
+++ b/vivified/code/test/compiler/asm_get_url2.as
@@ -0,0 +1,5 @@
+asm {
+  get_url2
+  get_url2 get internal
+  get_url2 get post internal variables reserved1 reserved2 reserved3 reserved4
+}
diff --git a/vivified/code/test/compiler/asm_get_url2.as.expect b/vivified/code/test/compiler/asm_get_url2.as.expect
new file mode 100644
index 0000000..c45307f
--- /dev/null
+++ b/vivified/code/test/compiler/asm_get_url2.as.expect
@@ -0,0 +1,6 @@
+asm {
+  get_url2
+  get_url2 get internal
+  get_url2 get post reserved1 reserved2 reserved3 reserved4 internal variables
+  end
+}
diff --git a/vivified/code/vivi_code_asm_get_url2.c b/vivified/code/vivi_code_asm_get_url2.c
index 210eb33..03bb0f4 100644
--- a/vivified/code/vivi_code_asm_get_url2.c
+++ b/vivified/code/vivi_code_asm_get_url2.c
@@ -53,7 +53,7 @@ G_DEFINE_TYPE_WITH_CODE (ViviCodeAsmGetUrl2, vivi_code_asm_get_url2, VIVI_TYPE_C
 
 
 /* FIXME: export for compiler */
-static const char *flag_names[16] = {
+static const char *flag_names[8] = {
   "get",
   "post",
   "reserved1",
@@ -101,7 +101,7 @@ vivi_code_asm_get_url2_new_from_flags (guint flags)
 {
   ViviCodeAsmGetUrl2 *get_url;
 
-  g_return_val_if_fail (flags < G_MAXUINT8, NULL);
+  g_return_val_if_fail (flags <= G_MAXUINT8, NULL);
 
   get_url = g_object_new (VIVI_TYPE_CODE_ASM_GET_URL2, NULL);
   get_url->flags = flags;
diff --git a/vivified/code/vivi_parser.c b/vivified/code/vivi_parser.c
index 689be01..1679223 100644
--- a/vivified/code/vivi_parser.c
+++ b/vivified/code/vivi_parser.c
@@ -30,6 +30,7 @@
 
 #include "vivi_code_and.h"
 #include "vivi_code_asm_code_default.h"
+#include "vivi_code_asm_get_url2.h"
 #include "vivi_code_asm_push.h"
 #include "vivi_code_asm_store.h"
 #include "vivi_code_assignment.h"
@@ -1105,6 +1106,44 @@ parse_asm_push (ParseData *data)
   return VIVI_CODE_ASM (push);
 }
 
+/* FIXME: export for compiler */
+static const char *get_url2_flag_names[8] = {
+  "get",
+  "post",
+  "reserved1",
+  "reserved2",
+  "reserved3",
+  "reserved4",
+  "internal",
+  "variables"
+};
+
+static ViviCodeAsm *
+parse_asm_get_url2 (ParseData *data)
+{
+  guint flags = 0;
+
+  while (peek_identifier (data) && !peek_line_terminator (data)) {
+    const char *name = parse_identifier_value (data);
+    guint i;
+
+    for (i = 0; i < G_N_ELEMENTS (get_url2_flag_names); i++) {
+      if (!g_ascii_strcasecmp (name, get_url2_flag_names[i])) {
+	// TODO: warn if already set?
+	flags |= 1 << i;
+	break;
+      }
+    }
+    if (i == G_N_ELEMENTS (get_url2_flag_names))
+      vivi_parser_error (data, "Invalid flag for get_url2: %s", name);
+  }
+
+  parse_automatic_semicolon (data);
+
+  return vivi_code_asm_get_url2_new_from_flags (flags);
+}
+
+
 typedef ViviCodeAsm *(*AsmConstructor) (void);
 typedef ViviCodeAsm *(*ParseAsmFunction) (ParseData *data);
 
@@ -1119,6 +1158,7 @@ static const AsmStatement asm_statements[] = {
   { G_STRINGIFY (underscore_name), vivi_code_asm_ ## underscore_name ## _new, NULL },
 #include "vivi_code_defaults.h"
 #undef DEFAULT_ASM
+  { "get_url2", NULL, parse_asm_get_url2 },
   { "push", NULL, parse_asm_push },
   { "store", NULL, parse_asm_store }
 };


More information about the Swfdec-commits mailing list