X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fas3%2Fexpr.c;h=1a6759498398ede8e1fe2e773c0d7c1f0aa3adf4;hb=c63b2bf21dc1df9a736f0b4c08f6cba828cdab92;hp=30cb8558d4cc2358506d7a3f66d695e122bf6ab7;hpb=5a9b4530f6a84ce3666a94605270bddaf43c9ff2;p=swftools.git diff --git a/lib/as3/expr.c b/lib/as3/expr.c index 30cb855..1a67594 100644 --- a/lib/as3/expr.c +++ b/lib/as3/expr.c @@ -1,4 +1,4 @@ -/* ast.c +/* expr.c Extension module for the rfxswf library. Part of the swftools package. @@ -90,16 +90,6 @@ static classinfo_t*join_types(classinfo_t*type1, classinfo_t*type2, nodetype_t*t return type1; return TYPE_ANY; } -static char is_getlocal(code_t*c) -{ - if(!c || c->prev || c->next) - return 0; - return(c->opcode == OPCODE_GETLOCAL - || c->opcode == OPCODE_GETLOCAL_0 - || c->opcode == OPCODE_GETLOCAL_1 - || c->opcode == OPCODE_GETLOCAL_2 - || c->opcode == OPCODE_GETLOCAL_3); -} static int getlocalnr(code_t*c) { if(c->opcode == OPCODE_GETLOCAL) {return (ptroff_t)c->data[0];} @@ -155,7 +145,8 @@ static code_t* toreadwrite(code_t*in, code_t*middlepart, char justassign, char r prefix = abc_dup(prefix); // we need the object, too } use_temp_var = 1; - } else if(m->type == MULTINAMEL || m->type == MULTINAMELA) { + } else if(m->type == MULTINAMEL || m->type == MULTINAMELA || + m->type == RTQNAME || m->type == RTQNAMEA) { if(!justassign) { /* dupping two values on the stack requires 5 operations and one register- couldn't adobe just have given us a dup2? */ @@ -278,6 +269,32 @@ static code_t* toreadwrite(code_t*in, code_t*middlepart, char justassign, char r return c; } +typedcode_t push_constant(constant_t*v) +{ + typedcode_t t; + switch(v->type) { + case CONSTANT_INT: t.c = abc_pushint(0, v->i);t.t = TYPE_INT;break; + case CONSTANT_UINT: t.c = abc_pushuint(0, v->u);t.t = TYPE_UINT;break; + case CONSTANT_FLOAT: t.c = abc_pushdouble(0, v->f);t.t = TYPE_FLOAT;break; + case CONSTANT_TRUE: t.c = abc_pushtrue(0);t.t = TYPE_BOOLEAN;break; + case CONSTANT_FALSE: t.c = abc_pushfalse(0);t.t = TYPE_BOOLEAN;break; + case CONSTANT_STRING: t.c = abc_pushstring2(0, v->s);t.t = TYPE_STRING;break; + case CONSTANT_NULL: t.c = abc_pushnull(0);t.t = TYPE_NULL;break; + case CONSTANT_UNDEFINED: t.c = abc_pushundefined(0);t.t = TYPE_ANY;break; + case CONSTANT_NAMESPACE: + case CONSTANT_NAMESPACE_PACKAGE: + case CONSTANT_NAMESPACE_PACKAGEINTERNAL: + case CONSTANT_NAMESPACE_PROTECTED: + case CONSTANT_NAMESPACE_EXPLICIT: + case CONSTANT_NAMESPACE_STATICPROTECTED: + case CONSTANT_NAMESPACE_PRIVATE: + t.c = abc_pushnamespace(0, v->ns);t.t = TYPE_NAMESPACE;break; + default: + syntaxerror("internal error: bad constant"); + } + return t; +} + code_t*converttype(code_t*c, classinfo_t*from, classinfo_t*to); int constant_to_int(constant_t*c) @@ -2620,7 +2637,16 @@ exec: node_const_exec typedcode_t node_code_write(node_t*n) { - syntaxerror("not implemented yet"); + typedcode_t t; + t.c = 0; + int tmp = gettempvar(); + t.c = abc_setlocal(t.c, tmp); + code_t*w = toreadwrite(n->code.c, abc_getlocal(0,tmp), 1, 0, 0); + t.c = code_append(t.c, w); + t.c = abc_kill(t.c, tmp); + n->code.c=0; + t.t = n->code.t; + return t; } typedcode_t node_code_read(node_t*n) { @@ -2719,6 +2745,16 @@ node_t* mkmultinode(nodetype_t*t, node_t*one) return n; } +node_t* mkstringnode(const char*s) +{ + return mkconstnode(constant_new_string(s)); +} + +node_t* mkaddnode(node_t*n1, node_t*n2) +{ + return mknode2(&node_plus, n1, n2); +} + node_t* multinode_extend(node_t*n, node_t*add) { n->child = realloc(n->child, (n->num_children+1)*sizeof(node_t*)); @@ -2785,7 +2821,20 @@ void node_free(node_t*n) typedcode_t node_read(node_t*n) { - typedcode_t t = n->type->read(n); + constant_t c = n->type->eval(n); + if(c.type == CONSTANT_UNKNOWN) { + typedcode_t t = n->type->read(n); + node_free(n); + return t; + } else { + typedcode_t t = push_constant(&c); + node_free(n); + return t; + } +} +typedcode_t node_write(node_t*n) +{ + typedcode_t t = n->type->write(n); node_free(n); return t; }