added variable lookup
[swftools.git] / lib / as3 / opcodes.c
index ee43758..5a4cc57 100644 (file)
@@ -1,3 +1,26 @@
+/* opcodes.c
+
+   Routines for handling Flash2 AVM2 ABC Actionscript
+
+   Extension module for the rfxswf library.
+   Part of the swftools package.
+
+   Copyright (c) 2008 Matthias Kramm <kramm@quiss.org>
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
 #include "opcodes.h"
 code_t* abc_add(code_t*prev)
 {
@@ -12,7 +35,13 @@ code_t* abc_add_i(code_t*prev)
 code_t* abc_astype(code_t*prev, char* name)
 {
     code_t*self = add_opcode(prev, 0x86);
-    self->data[0] = multiname_fromstring(name); // FIXME
+    self->data[0] = multiname_fromstring(name);
+    return self;
+}
+code_t* abc_astype2(code_t*prev, multiname_t* name)
+{
+    code_t*self = add_opcode(prev, 0x86);
+    self->data[0] = multiname_clone(name);
     return self;
 }
 code_t* abc_astypelate(code_t*prev)
@@ -56,21 +85,42 @@ code_t* abc_callmethod(code_t*prev, abc_method_body_t* m, int v)
 code_t* abc_callproplex(code_t*prev, char* name, int v)
 {
     code_t*self = add_opcode(prev, 0x4c);
-    self->data[0] = multiname_fromstring(name); // FIXME
+    self->data[0] = multiname_fromstring(name);
+    self->data[1] = (void*)(ptroff_t)v;
+    return self;
+}
+code_t* abc_callproplex2(code_t*prev, multiname_t* name, int v)
+{
+    code_t*self = add_opcode(prev, 0x4c);
+    self->data[0] = multiname_clone(name);
     self->data[1] = (void*)(ptroff_t)v;
     return self;
 }
 code_t* abc_callproperty(code_t*prev, char* name, int v)
 {
     code_t*self = add_opcode(prev, 0x46);
-    self->data[0] = multiname_fromstring(name); // FIXME
+    self->data[0] = multiname_fromstring(name);
+    self->data[1] = (void*)(ptroff_t)v;
+    return self;
+}
+code_t* abc_callproperty2(code_t*prev, multiname_t* name, int v)
+{
+    code_t*self = add_opcode(prev, 0x46);
+    self->data[0] = multiname_clone(name);
     self->data[1] = (void*)(ptroff_t)v;
     return self;
 }
 code_t* abc_callpropvoid(code_t*prev, char* name, int v)
 {
     code_t*self = add_opcode(prev, 0x4f);
-    self->data[0] = multiname_fromstring(name); // FIXME
+    self->data[0] = multiname_fromstring(name);
+    self->data[1] = (void*)(ptroff_t)v;
+    return self;
+}
+code_t* abc_callpropvoid2(code_t*prev, multiname_t* name, int v)
+{
+    code_t*self = add_opcode(prev, 0x4f);
+    self->data[0] = multiname_clone(name);
     self->data[1] = (void*)(ptroff_t)v;
     return self;
 }
@@ -84,14 +134,28 @@ code_t* abc_callstatic(code_t*prev, abc_method_t* m, int v)
 code_t* abc_callsuper(code_t*prev, char* name, int v)
 {
     code_t*self = add_opcode(prev, 0x45);
-    self->data[0] = multiname_fromstring(name); // FIXME
+    self->data[0] = multiname_fromstring(name);
+    self->data[1] = (void*)(ptroff_t)v;
+    return self;
+}
+code_t* abc_callsuper2(code_t*prev, multiname_t* name, int v)
+{
+    code_t*self = add_opcode(prev, 0x45);
+    self->data[0] = multiname_clone(name);
     self->data[1] = (void*)(ptroff_t)v;
     return self;
 }
 code_t* abc_callsupervoid(code_t*prev, char* name, int v)
 {
     code_t*self = add_opcode(prev, 0x4e);
-    self->data[0] = multiname_fromstring(name); // FIXME
+    self->data[0] = multiname_fromstring(name);
+    self->data[1] = (void*)(ptroff_t)v;
+    return self;
+}
+code_t* abc_callsupervoid2(code_t*prev, multiname_t* name, int v)
+{
+    code_t*self = add_opcode(prev, 0x4e);
+    self->data[0] = multiname_clone(name);
     self->data[1] = (void*)(ptroff_t)v;
     return self;
 }
@@ -103,7 +167,13 @@ code_t* abc_checkfilter(code_t*prev)
 code_t* abc_coerce(code_t*prev, char* name)
 {
     code_t*self = add_opcode(prev, 0x80);
-    self->data[0] = multiname_fromstring(name); // FIXME
+    self->data[0] = multiname_fromstring(name);
+    return self;
+}
+code_t* abc_coerce2(code_t*prev, multiname_t* name)
+{
+    code_t*self = add_opcode(prev, 0x80);
+    self->data[0] = multiname_clone(name);
     return self;
 }
 code_t* abc_coerce_a(code_t*prev)
@@ -125,7 +195,14 @@ code_t* abc_construct(code_t*prev, int v)
 code_t* abc_constructprop(code_t*prev, char* name, int v)
 {
     code_t*self = add_opcode(prev, 0x4a);
-    self->data[0] = multiname_fromstring(name); // FIXME
+    self->data[0] = multiname_fromstring(name);
+    self->data[1] = (void*)(ptroff_t)v;
+    return self;
+}
+code_t* abc_constructprop2(code_t*prev, multiname_t* name, int v)
+{
+    code_t*self = add_opcode(prev, 0x4a);
+    self->data[0] = multiname_clone(name);
     self->data[1] = (void*)(ptroff_t)v;
     return self;
 }
@@ -208,7 +285,13 @@ code_t* abc_decrement_i(code_t*prev)
 code_t* abc_deleteproperty(code_t*prev, char* name)
 {
     code_t*self = add_opcode(prev, 0x6a);
-    self->data[0] = multiname_fromstring(name); // FIXME
+    self->data[0] = multiname_fromstring(name);
+    return self;
+}
+code_t* abc_deleteproperty2(code_t*prev, multiname_t* name)
+{
+    code_t*self = add_opcode(prev, 0x6a);
+    self->data[0] = multiname_clone(name);
     return self;
 }
 code_t* abc_divide(code_t*prev)
@@ -250,19 +333,37 @@ code_t* abc_esc_xelem(code_t*prev)
 code_t* abc_findproperty(code_t*prev, char* name)
 {
     code_t*self = add_opcode(prev, 0x5e);
-    self->data[0] = multiname_fromstring(name); // FIXME
+    self->data[0] = multiname_fromstring(name);
+    return self;
+}
+code_t* abc_findproperty2(code_t*prev, multiname_t* name)
+{
+    code_t*self = add_opcode(prev, 0x5e);
+    self->data[0] = multiname_clone(name);
     return self;
 }
 code_t* abc_findpropstrict(code_t*prev, char* name)
 {
     code_t*self = add_opcode(prev, 0x5d);
-    self->data[0] = multiname_fromstring(name); // FIXME
+    self->data[0] = multiname_fromstring(name);
+    return self;
+}
+code_t* abc_findpropstrict2(code_t*prev, multiname_t* name)
+{
+    code_t*self = add_opcode(prev, 0x5d);
+    self->data[0] = multiname_clone(name);
     return self;
 }
 code_t* abc_getdescendants(code_t*prev, char* name)
 {
     code_t*self = add_opcode(prev, 0x59);
-    self->data[0] = multiname_fromstring(name); // FIXME
+    self->data[0] = multiname_fromstring(name);
+    return self;
+}
+code_t* abc_getdescendants2(code_t*prev, multiname_t* name)
+{
+    code_t*self = add_opcode(prev, 0x59);
+    self->data[0] = multiname_clone(name);
     return self;
 }
 code_t* abc_getglobalscope(code_t*prev)
@@ -279,7 +380,13 @@ code_t* abc_getglobalslot(code_t*prev, int v)
 code_t* abc_getlex(code_t*prev, char* name)
 {
     code_t*self = add_opcode(prev, 0x60);
-    self->data[0] = multiname_fromstring(name); // FIXME
+    self->data[0] = multiname_fromstring(name);
+    return self;
+}
+code_t* abc_getlex2(code_t*prev, multiname_t* name)
+{
+    code_t*self = add_opcode(prev, 0x60);
+    self->data[0] = multiname_clone(name);
     return self;
 }
 code_t* abc_getlocal(code_t*prev, int reg)
@@ -311,7 +418,13 @@ code_t* abc_getlocal_3(code_t*prev)
 code_t* abc_getproperty(code_t*prev, char* name)
 {
     code_t*self = add_opcode(prev, 0x66);
-    self->data[0] = multiname_fromstring(name); // FIXME
+    self->data[0] = multiname_fromstring(name);
+    return self;
+}
+code_t* abc_getproperty2(code_t*prev, multiname_t* name)
+{
+    code_t*self = add_opcode(prev, 0x66);
+    self->data[0] = multiname_clone(name);
     return self;
 }
 code_t* abc_getscopeobject(code_t*prev, int v)
@@ -329,14 +442,25 @@ code_t* abc_getslot(code_t*prev, int v)
 code_t* abc_getsuper(code_t*prev, char* name)
 {
     code_t*self = add_opcode(prev, 0x04);
-    self->data[0] = multiname_fromstring(name); // FIXME
+    self->data[0] = multiname_fromstring(name);
     return self;
 }
-code_t* abc_greaterequals(code_t*prev)
+code_t* abc_getsuper2(code_t*prev, multiname_t* name)
+{
+    code_t*self = add_opcode(prev, 0x04);
+    self->data[0] = multiname_clone(name);
+    return self;
+}
+code_t* abc_greaterthan(code_t*prev)
 {
     code_t*self = add_opcode(prev, 0xaf);
     return self;
 }
+code_t* abc_greaterequals(code_t*prev)
+{
+    code_t*self = add_opcode(prev, 0xb0);
+    return self;
+}
 code_t* abc_hasnext(code_t*prev)
 {
     code_t*self = add_opcode(prev, 0x1f);
@@ -477,7 +601,13 @@ code_t* abc_increment_i(code_t*prev)
 code_t* abc_initproperty(code_t*prev, char* name)
 {
     code_t*self = add_opcode(prev, 0x68);
-    self->data[0] = multiname_fromstring(name); // FIXME
+    self->data[0] = multiname_fromstring(name);
+    return self;
+}
+code_t* abc_initproperty2(code_t*prev, multiname_t* name)
+{
+    code_t*self = add_opcode(prev, 0x68);
+    self->data[0] = multiname_clone(name);
     return self;
 }
 code_t* abc_instanceof(code_t*prev)
@@ -488,7 +618,13 @@ code_t* abc_instanceof(code_t*prev)
 code_t* abc_istype(code_t*prev, char* name)
 {
     code_t*self = add_opcode(prev, 0xb2);
-    self->data[0] = multiname_fromstring(name); // FIXME
+    self->data[0] = multiname_fromstring(name);
+    return self;
+}
+code_t* abc_istype2(code_t*prev, multiname_t* name)
+{
+    code_t*self = add_opcode(prev, 0xb2);
+    self->data[0] = multiname_clone(name);
     return self;
 }
 code_t* abc_istypelate(code_t*prev)
@@ -524,10 +660,10 @@ code_t* abc_lessthan(code_t*prev)
     code_t*self = add_opcode(prev, 0xad);
     return self;
 }
-code_t* abc_lookupswitch(code_t*prev, void* labels)
+code_t* abc_lookupswitch(code_t*prev, lookupswitch_t* l)
 {
     code_t*self = add_opcode(prev, 0x1b);
-    /* FIXME: write labels labels */
+    self->data[0] = l;
     return self;
 }
 code_t* abc_lshift(code_t*prev)
@@ -631,10 +767,12 @@ code_t* abc_pushbyte(code_t*prev, int v)
     self->data[0] = (void*)(ptroff_t)v;
     return self;
 }
-code_t* abc_pushdouble(code_t*prev, int v)
+code_t* abc_pushdouble(code_t*prev, double f)
 {
     code_t*self = add_opcode(prev, 0x2f);
-    self->data[0] = (void*)(ptroff_t)v;
+    double*fp = malloc(sizeof(double));
+    *fp = f;
+    self->data[0] = fp;
     return self;
 }
 code_t* abc_pushfalse(code_t*prev)
@@ -642,10 +780,10 @@ code_t* abc_pushfalse(code_t*prev)
     code_t*self = add_opcode(prev, 0x27);
     return self;
 }
-code_t* abc_pushint(code_t*prev, int v)
+code_t* abc_pushint(code_t*prev, int i)
 {
     code_t*self = add_opcode(prev, 0x2d);
-    self->data[0] = (void*)(ptroff_t)v;
+    self->data[0] = (void*)(ptroff_t)i;
     return self;
 }
 code_t* abc_pushnamespace(code_t*prev, int v)
@@ -686,10 +824,10 @@ code_t* abc_pushtrue(code_t*prev)
     code_t*self = add_opcode(prev, 0x26);
     return self;
 }
-code_t* abc_pushuint(code_t*prev, int v)
+code_t* abc_pushuint(code_t*prev, unsigned int u)
 {
     code_t*self = add_opcode(prev, 0x2e);
-    self->data[0] = (void*)(ptroff_t)v;
+    self->data[0] = (void*)(ptroff_t)u;
     return self;
 }
 code_t* abc_pushundefined(code_t*prev)
@@ -752,19 +890,31 @@ code_t* abc_setglobalslot(code_t*prev, int v)
 code_t* abc_setproperty(code_t*prev, char* name)
 {
     code_t*self = add_opcode(prev, 0x61);
-    self->data[0] = multiname_fromstring(name); // FIXME
+    self->data[0] = multiname_fromstring(name);
+    return self;
+}
+code_t* abc_setproperty2(code_t*prev, multiname_t* name)
+{
+    code_t*self = add_opcode(prev, 0x61);
+    self->data[0] = multiname_clone(name);
     return self;
 }
-code_t* abc_setslot(code_t*prev, char* name)
+code_t* abc_setslot(code_t*prev, int v)
 {
     code_t*self = add_opcode(prev, 0x6d);
-    self->data[0] = multiname_fromstring(name); // FIXME
+    self->data[0] = (void*)(ptroff_t)v;
     return self;
 }
 code_t* abc_setsuper(code_t*prev, char* name)
 {
     code_t*self = add_opcode(prev, 0x05);
-    self->data[0] = multiname_fromstring(name); // FIXME
+    self->data[0] = multiname_fromstring(name);
+    return self;
+}
+code_t* abc_setsuper2(code_t*prev, multiname_t* name)
+{
+    code_t*self = add_opcode(prev, 0x05);
+    self->data[0] = multiname_clone(name);
     return self;
 }
 code_t* abc_strictequals(code_t*prev)
@@ -802,8 +952,3 @@ code_t* abc_urshift(code_t*prev)
     code_t*self = add_opcode(prev, 0xa7);
     return self;
 }
-code_t* abc_xxx(code_t*prev)
-{
-    code_t*self = add_opcode(prev, 0xb0);
-    return self;
-}