X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fas3%2Fcode.c;h=86bae599a76f8aee23747910322fa1fafb06212a;hb=21ef4c306d38969e8f5fe821a27d155b855735b9;hp=7273900858812bf9ba01f31fd3876be00dda2236;hpb=6b8893f461e88e066487798ba4ddd800d277d136;p=swftools.git diff --git a/lib/as3/code.c b/lib/as3/code.c index 7273900..86bae59 100644 --- a/lib/as3/code.c +++ b/lib/as3/code.c @@ -1,3 +1,26 @@ +/* code.c + + Routines for handling Flash2 AVM2 ABC Actionscript + + Extension module for the rfxswf library. + Part of the swftools package. + + Copyright (c) 2008 Matthias Kramm + + 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 #include "code.h" #include "pool.h" @@ -20,14 +43,13 @@ n = u30 number of params i = u30 index into method info b = byte - s = short c = u30 index into class s = string (u30 index into strings) S = switch u = u30 r = register */ - + opcode_t opcodes[]={ {0xa0, "add", "", -2, 1, 0, 0}, {0xc5, "add_i", "", -2, 1, 0, 0}, @@ -130,7 +152,9 @@ opcode_t opcodes[]={ {0x57, "newactivation", "", 0, 1, 0, OP_NEED_ACTIVATION}, {0x56, "newarray", "n", 0, 1, 0, OP_STACK_ARGS}, {0x5a, "newcatch", "u", 0, 1, 0, 0}, //u = index into exception_info +#define OP_NEWCLASS 0x58 {0x58, "newclass", "c", -1, 1, 0, 0}, //c = index into class_info +#define OP_NEWFUNCTION 0x40 {0x40, "newfunction", "m", 0, 1, 0, 0}, //i = index into method_info {0x55, "newobject", "n", 0, 1, 0, OP_STACK_ARGS2}, {0x1e, "nextname", "", -2, 1, 0, 0}, @@ -645,6 +669,17 @@ static char callcode(currentstats_t*stats, int pos, int stack, int scope) stats->flags |= FLAGS_SET_DXNS; if(op->flags & OP_NEED_ACTIVATION) stats->flags |= FLAGS_ACTIVATION; + + if(c->opcode == OP_NEWCLASS) { + abc_class_t*cls = (abc_class_t*)(c->data[0]); + if(scope > cls->init_scope_depth) + cls->init_scope_depth = scope; + } + if(c->opcode == OP_NEWFUNCTION) { + abc_method_t*m = (abc_method_t*)(c->data[0]); + if(m->body && scope > m->body->init_scope_depth) + m->body->init_scope_depth = scope; + } if(op->flags & OP_REGISTER) { char*p = op->params; @@ -945,6 +980,7 @@ code_t* add_opcode(code_t*atag, U8 op) tmp->next = 0; if(atag) { tmp->prev = atag; + tmp->next = atag->next; atag->next = tmp; } else { tmp->prev = 0; @@ -959,3 +995,23 @@ void codestats_print(codestats_t*stats) printf("scope_depth: %d\n", stats->max_scope_depth); } +code_t* code_append(code_t*code, code_t*toappend) +{ + if(!code) + return toappend; + if(!toappend) + return code; + //find end of first list + while(code->next) { + code = code->next; + } + code_t*start=toappend; + //and start of second list + while(start->prev) { + start = start->prev; + } + code->next = start; + start->prev = code; + return toappend; +} +