X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=lib%2Fas3%2Fparser.y;h=67c6cba8299ae792a3fe63699fa9dc4f4a457c07;hb=ff2096e7e8b2e52dd7fbb10d1f98a15582cfdb53;hp=413e694b3088bb0493cb3bbadf4f5ce03c030c40;hpb=dcdff914362d5464ca4afde566af17e656edf518;p=swftools.git diff --git a/lib/as3/parser.y b/lib/as3/parser.y index 413e694..67c6cba 100644 --- a/lib/as3/parser.y +++ b/lib/as3/parser.y @@ -51,8 +51,9 @@ typedcode_t value; typedcode_list_t*value_list; param_t* param; - param_list_t* param_list; + params_t params; char*string; + constant_t*constant; } @@ -124,6 +125,7 @@ %token T_MINUSMINUS "--" %token T_PLUSPLUS "++" %token T_DOTDOT ".." +%token T_DOTDOTDOT "..." %token T_SHL "<<" %token T_USHR ">>>" %token T_SHR ">>" @@ -153,10 +155,11 @@ %type MAYBETYPE %type GETSET %type PARAM -%type PARAM_LIST -%type MAYBE_PARAM_LIST +%type PARAM_LIST +%type MAYBE_PARAM_LIST %type MODIFIERS %type MODIFIER_LIST +%type STATICCONSTANT MAYBESTATICCONSTANT %type IMPLEMENTS_LIST %type EXTENDS %type EXTENDS_LIST @@ -184,8 +187,8 @@ %nonassoc ">>=" %nonassoc "<<=" %nonassoc ">>>=" -%nonassoc "||" -%nonassoc "&&" +%left "||" +%left "&&" %nonassoc '|' %nonassoc '^' %nonassoc '&' @@ -295,18 +298,37 @@ typedef struct _state { memberinfo_t*minfo; abc_method_body_t*m; - array_t*vars; - int local_var_base; + dict_t*vars; char late_binding; } state_t; +typedef struct _global { + int variable_count; +} global_t; + +static global_t*global = 0; static state_t* state = 0; DECLARE_LIST(state); #define MULTINAME(m,x) multiname_t m;namespace_t m##_ns;registry_fill_multiname(&m, &m##_ns, x); +/* warning: list length of namespace set is undefined */ +#define MULTINAME_LATE(m, access, package) \ + namespace_t m##_ns = {access, package}; \ + namespace_set_t m##_nsset; \ + namespace_list_t m##_l;m##_l.next = 0; \ + m##_nsset.namespaces = &m##_l; \ + m##_nsset = m##_nsset; \ + m##_l.namespace = &m##_ns; \ + multiname_t m = {MULTINAMEL, 0, &m##_nsset, 0}; + static state_list_t*state_stack=0; + +static void init_globals() +{ + global = rfx_calloc(sizeof(global_t)); +} static void new_state() { @@ -318,16 +340,13 @@ static void new_state() memcpy(s, state, sizeof(state_t)); //shallow copy sl->next = state_stack; sl->state = s; - if(oldstate) { - s->local_var_base = array_length(oldstate->vars) + oldstate->local_var_base; - } if(!s->imports) { s->imports = dict_new(); } state_stack = sl; state = s; state->level++; - state->vars = array_new(); + state->vars = dict_new(); state->initcode = 0; state->has_own_imports = 0; } @@ -359,6 +378,7 @@ static void old_state() } void initialize_state() { + init_globals(); new_state(); state->file = abc_file_new(); @@ -597,60 +617,6 @@ static void endclass() old_state(); } -static void startfunction(token_t*ns, token_t*mod, token_t*getset, token_t*name, - param_list_t*params, classinfo_t*type) -{ - token_list_t*t; - new_state(); - state->function = name->text; - - if(state->m) { - syntaxerror("not able to start another method scope"); - } - - multiname_t*type2 = sig2mname(type); - if(!strcmp(state->clsinfo->name,name->text)) { - state->m = abc_class_constructor(state->cls, type2, 0); - } else { - state->minfo = memberinfo_register(state->clsinfo, name->text, MEMBER_METHOD); - state->m = abc_class_method(state->cls, type2, name->text, 0); - state->minfo->slot = state->m->method->trait->slot_id; - } - if(getset->type == KW_GET) { - state->m->method->trait->kind = TRAIT_GETTER; - } - if(getset->type == KW_SET) { - state->m->method->trait->kind = TRAIT_SETTER; - } - - param_list_t*p; - for(p=params;p;p=p->next) { - multiname_t*m = sig2mname(p->param->type); - list_append(state->m->method->parameters, m); - } - - /* state->vars is initialized by state_new */ - array_append(state->vars, "this", 0); - for(p=params;p;p=p->next) { - array_append(state->vars, p->param->name, 0); - } -} -static void endfunction(code_t*body) -{ - code_t*c = 0; - if(state->late_binding) { - c = abc_getlocal_0(c); - c = abc_pushscope(c); - } - c = code_append(c, state->initcode); - c = code_append(c, body); - c = abc_returnvoid(c); - - if(state->m->code) syntaxerror("internal error"); - state->m->code = c; - old_state(); -} - static token_t* empty_token() { @@ -680,16 +646,21 @@ void extend_s(token_t*list, char*seperator, token_t*add) { list->text[l1+l2+l3]=0; } +typedef struct _variable { + int index; + classinfo_t*type; +} variable_t; + static int find_variable(char*name, classinfo_t**m) { state_list_t* s = state_stack; while(s) { - int i = array_find(s->state->vars, name); - if(i>=0) { + variable_t*v = dict_lookup(s->state->vars, name); + if(v) { if(m) { - *m = array_getvalue(s->state->vars, i); + *m = v->type; } - return i + s->state->local_var_base; + return v->index; } s = s->next; } @@ -704,11 +675,15 @@ static int find_variable_safe(char*name, classinfo_t**m) } static char variable_exists(char*name) { - return array_contains(state->vars, name); + return dict_lookup(state->vars, name)!=0; } static int new_variable(char*name, classinfo_t*type) { - return array_append(state->vars, name, type) + state->local_var_base; + NEW(variable_t, v); + v->index = global->variable_count; + v->type = type; + dict_put(state->vars, name, v); + return global->variable_count++; } #define TEMPVARNAME "__as3_temp__" static int gettempvar() @@ -724,17 +699,117 @@ static int gettempvar() code_t* killvars(code_t*c) { int t; - for(t=0;tvars->num;t++) { - classinfo_t*type = array_getvalue(state->vars, t); - //do this always, otherwise register types don't match - //in the verifier when doing nested loops - //if(!TYPE_IS_BUILTIN_SIMPLE(type)) { - c = abc_kill(c, t+state->local_var_base); - //} + for(t=0;tvars->hashsize;t++) { + dictentry_t*e =state->vars->slots[t]; + while(e) { + variable_t*v = (variable_t*)e->data; + //do this always, otherwise register types don't match + //in the verifier when doing nested loops + //if(!TYPE_IS_BUILTIN_SIMPLE(type)) { + c = abc_kill(c, v->index); + e = e->next; + } } return c; } + +static void check_constant_against_type(classinfo_t*t, constant_t*c) +{ +#define xassert(b) if(!(b)) syntaxerror("Invalid default value %s for type '%s'", constant_tostring(c), t->name) + if(TYPE_IS_NUMBER(t)) { + xassert(c->type == CONSTANT_FLOAT + || c->type == CONSTANT_INT + || c->type == CONSTANT_UINT); + } else if(TYPE_IS_UINT(t)) { + xassert(c->type == CONSTANT_UINT || + (c->type == CONSTANT_INT && c->i>0)); + } else if(TYPE_IS_INT(t)) { + xassert(c->type == CONSTANT_INT); + } else if(TYPE_IS_BOOLEAN(t)) { + xassert(c->type == CONSTANT_TRUE + || c->type == CONSTANT_FALSE); + } +} + +static void startfunction(token_t*ns, token_t*mod, token_t*getset, token_t*name, + params_t*params, classinfo_t*type) +{ + token_list_t*t; + new_state(); + global->variable_count = 0; + state->function = name->text; + + if(state->m) { + syntaxerror("not able to start another method scope"); + } + + multiname_t*type2 = sig2mname(type); + if(!strcmp(state->clsinfo->name,name->text)) { + state->m = abc_class_constructor(state->cls, type2, 0); + } else { + state->minfo = memberinfo_register(state->clsinfo, name->text, MEMBER_METHOD); + state->minfo->return_type = type; + state->m = abc_class_method(state->cls, type2, name->text, 0); + // getslot on a member slot only returns "undefined", so no need + // to actually store these + //state->minfo->slot = state->m->method->trait->slot_id; + } + if(getset->type == KW_GET) { + state->m->method->trait->kind = TRAIT_GETTER; + } + if(getset->type == KW_SET) { + state->m->method->trait->kind = TRAIT_SETTER; + } + if(params->varargs) { + state->m->method->flags |= METHOD_NEED_REST; + } + + char opt=0; + param_list_t*p=0; + for(p=params->list;p;p=p->next) { + if(params->varargs && !p->next) { + break; //varargs: omit last parameter in function signature + } + multiname_t*m = sig2mname(p->param->type); + list_append(state->m->method->parameters, m); + if(p->param->value) { + check_constant_against_type(p->param->type, p->param->value); + opt=1;list_append(state->m->method->optional_parameters, p->param->value); + } else if(opt) { + syntaxerror("non-optional parameter not allowed after optional parameters"); + } + } + + /* state->vars is initialized by state_new */ + if(new_variable("this", state->clsinfo)!=0) syntaxerror("Internal error"); + + for(p=params->list;p;p=p->next) { + new_variable(p->param->name, p->param->type); + } +} +static void endfunction(code_t*body) +{ + code_t*c = 0; + if(state->late_binding) { + c = abc_getlocal_0(c); + c = abc_pushscope(c); + } + c = code_append(c, state->initcode); + c = code_append(c, body); + + /* append return if necessary */ + if(!c || c->opcode != OPCODE_RETURNVOID && + c->opcode != OPCODE_RETURNVALUE) + c = abc_returnvoid(c); + + if(state->m->code) syntaxerror("internal error"); + state->m->code = c; + old_state(); +} + + + char is_subtype_of(classinfo_t*type, classinfo_t*supertype) { return 1; // FIXME @@ -755,7 +830,13 @@ void breakjumpsto(code_t*c, code_t*jump) classinfo_t*join_types(classinfo_t*type1, classinfo_t*type2, char op) { - return registry_getanytype(); // FIXME + if(!type1 || !type2) + return registry_getanytype(); + if(TYPE_IS_ANY(type1) || TYPE_IS_ANY(type2)) + return registry_getanytype(); + if(type1 == type2) + return type1; + return registry_getanytype(); } code_t*converttype(code_t*c, classinfo_t*from, classinfo_t*to) { @@ -793,7 +874,12 @@ char is_pushundefined(code_t*c) return (c && !c->prev && !c->next && c->opcode == OPCODE_PUSHUNDEFINED); } -static code_t* toreadwrite(code_t*in, code_t*middlepart) +void parserassert(int b) +{ + if(!b) syntaxerror("internal error: assertion failed"); +} + +static code_t* toreadwrite(code_t*in, code_t*middlepart, char justassign) { /* converts this: @@ -804,11 +890,12 @@ static code_t* toreadwrite(code_t*in, code_t*middlepart) [prefix code] ([dup]) [read instruction] [middlepart] [setvar] [write instruction] [getvar] */ + if(in && in->opcode == OPCODE_COERCE_A) { + in = code_cutlast(in); + } if(in->next) syntaxerror("internal error"); - int temp = gettempvar(); - /* chop off read instruction */ code_t*prefix = in; code_t*r = in; @@ -827,11 +914,15 @@ static code_t* toreadwrite(code_t*in, code_t*middlepart) write->data[0] = multiname_clone(m); if(m->type != QNAME) syntaxerror("illegal lvalue: can't assign a value to this expression (not a qname)"); - prefix = abc_dup(prefix); // we need the object, too + if(!justassign) { + prefix = abc_dup(prefix); // we need the object, too + } } else if(r->opcode == OPCODE_GETSLOT) { write->opcode = OPCODE_SETSLOT; write->data[0] = r->data[0]; - prefix = abc_dup(prefix); // we need the object, too + if(!justassign) { + prefix = abc_dup(prefix); // we need the object, too + } } else if(r->opcode == OPCODE_GETLOCAL) { write->opcode = OPCODE_SETLOCAL; write->data[0] = r->data[0]; @@ -849,14 +940,48 @@ static code_t* toreadwrite(code_t*in, code_t*middlepart) } code_t* c = 0; - c = code_append(c, prefix); - c = code_append(c, r); - c = code_append(c, middlepart); - c = abc_dup(c); - c = abc_setlocal(c, temp); - c = code_append(c, write); - c = abc_getlocal(c, temp); - c = abc_kill(c, temp); + int temp = -1; + if(!justassign) { +#if 1 + /* with getproperty/getslot, we have to be extra careful not + to execute the read code twice, as it might have side-effects + (e.g. if the property is in fact a setter/getter combination) + + So read the value, modify it, and write it again, + using prefix only once and making sure (by using a temporary + register) that the return value is what we just wrote */ + temp = gettempvar(); + c = code_append(c, prefix); + c = code_append(c, r); + c = code_append(c, middlepart); + c = abc_dup(c); + c = abc_setlocal(c, temp); + c = code_append(c, write); + c = abc_getlocal(c, temp); + c = abc_kill(c, temp); +#else + /* if we're allowed to execute the read code twice *and* + the middlepart doesn't modify the code, things are easier. + */ + code_t* r2 = code_dup(r); + //c = code_append(c, prefix); + parserassert(!prefix); + c = code_append(c, r); + c = code_append(c, middlepart); + c = code_append(c, write); + c = code_append(c, r2); +#endif + } else { + /* even smaller version: overwrite the value without reading + it out first */ + if(prefix) { + c = code_append(c, prefix); + c = abc_dup(c); + } + c = code_append(c, middlepart); + c = code_append(c, write); + c = code_append(c, r); + } return c; } @@ -879,7 +1004,8 @@ CODE: CODEPIECE {$$=$1;} CODEPIECE: PACKAGE_DECLARATION {$$=code_new();/*enters a scope*/} CODEPIECE: CLASS_DECLARATION {$$=code_new();/*enters a scope*/} -CODEPIECE: INTERFACE_DECLARATION {/*TODO*/$$=code_new();} +CODEPIECE: FUNCTION_DECLARATION {$$=code_new();/*enters a scope*/} +CODEPIECE: INTERFACE_DECLARATION {$$=code_new();} CODEPIECE: IMPORT {$$=code_new();/*adds imports to current scope*/} CODEPIECE: ';' {$$=code_new();} CODEPIECE: VARIABLE_DECLARATION {$$=$1} @@ -890,7 +1016,6 @@ CODEPIECE: BREAK {$$=$1} CODEPIECE: RETURN {$$=$1} CODEPIECE: IF {$$=$1} CODEPIECE: NAMESPACE_DECLARATION {/*TODO*/$$=code_new();} -CODEPIECE: FUNCTION_DECLARATION {/*TODO*/$$=code_new();} CODEPIECE: USE_NAMESPACE {/*TODO*/$$=code_new();} CODEBLOCK : '{' MAYBECODE '}' {$$=$2;} @@ -932,15 +1057,13 @@ ONE_VARIABLE: {} T_IDENTIFIER MAYBETYPE MAYBEEXPRESSION $$ = abc_setlocal($$, index); } - /* push default value for type on stack */ - state->initcode = defaultvalue(state->initcode, $3); - state->initcode = abc_setlocal(state->initcode, index); + /* if this is a typed variable: + push default value for type on stack */ + if($3) { + state->initcode = defaultvalue(state->initcode, $3); + state->initcode = abc_setlocal(state->initcode, index); + } } else { - /* only bother to actually set this variable if its syntax is either - var x:type; - or - var x=expr; - */ if($4.c->prev || $4.c->opcode != OPCODE_PUSHUNDEFINED) { $$ = $4.c; $$ = abc_coerce_a($$); @@ -1089,6 +1212,8 @@ DECLARATION : ';' DECLARATION : SLOT_DECLARATION DECLARATION : FUNCTION_DECLARATION +/* ------------ classes and interfaces (body, slots ) ------- */ + VARCONST: "var" | "const" SLOT_DECLARATION: MODIFIERS VARCONST T_IDENTIFIER MAYBETYPE MAYBEEXPRESSION { @@ -1117,8 +1242,65 @@ SLOT_DECLARATION: MODIFIERS VARCONST T_IDENTIFIER MAYBETYPE MAYBEEXPRESSION { } } +/* ------------ constants -------------------------------------- */ + +MAYBESTATICCONSTANT: {$$=0;} +MAYBESTATICCONSTANT: '=' STATICCONSTANT {$$=$2;} + +STATICCONSTANT : T_BYTE {$$ = constant_new_int($1);} +STATICCONSTANT : T_INT {$$ = constant_new_int($1);} +STATICCONSTANT : T_UINT {$$ = constant_new_uint($1);} +STATICCONSTANT : T_FLOAT {$$ = constant_new_float($1);} +STATICCONSTANT : T_STRING {$$ = constant_new_string($1);} +//STATICCONSTANT : T_NAMESPACE {$$ = constant_new_namespace($1);} +STATICCONSTANT : KW_TRUE {$$ = constant_new_true($1);} +STATICCONSTANT : KW_FALSE {$$ = constant_new_false($1);} +STATICCONSTANT : KW_NULL {$$ = constant_new_null($1);} + +/* ------------ classes and interfaces (body, functions) ------- */ + +// non-vararg version +MAYBE_PARAM_LIST: { + memset(&$$,0,sizeof($$)); +} +MAYBE_PARAM_LIST: PARAM_LIST { + $$=$1; +} + +// vararg version +MAYBE_PARAM_LIST: "..." PARAM { + memset(&$$,0,sizeof($$)); + $$.varargs=1; + list_append($$.list, $2); +} +MAYBE_PARAM_LIST: PARAM_LIST ',' "..." PARAM { + $$ =$1; + $$.varargs=1; + list_append($$.list, $4); +} + +// non empty +PARAM_LIST: PARAM_LIST ',' PARAM { + $$ = $1; + list_append($$.list, $3); +} +PARAM_LIST: PARAM { + memset(&$$,0,sizeof($$)); + list_append($$.list, $1); +} +PARAM: T_IDENTIFIER ':' TYPE MAYBESTATICCONSTANT { + $$ = malloc(sizeof(param_t)); + $$->name=$1->text; + $$->type = $3; + $$->value = $4; +} +PARAM: T_IDENTIFIER MAYBESTATICCONSTANT { + $$ = malloc(sizeof(param_t)); + $$->name=$1->text;$$->type = TYPE_ANY; +} + FUNCTION_DECLARATION: MODIFIERS "function" GETSET T_IDENTIFIER '(' MAYBE_PARAM_LIST ')' - MAYBETYPE '{' {startfunction(0,$1,$3,$4,$6,$8)} MAYBECODE '}' + MAYBETYPE '{' {startfunction(0,$1,$3,$4,&$6,$8)} MAYBECODE '}' { if(!state->m) syntaxerror("internal error: undefined function"); endfunction($11); @@ -1216,32 +1398,46 @@ FUNCTIONCALL : E '(' MAYBE_EXPRESSION_LIST ')' { l = l->next; len ++; } - + $$.c = $1.c; + if($$.c->opcode == OPCODE_COERCE_A) { + $$.c = code_cutlast($$.c); + } + + $$.t = TYPE_ANY; + multiname_t*name = 0; if($$.c->opcode == OPCODE_GETPROPERTY) { - multiname_t*name = multiname_clone($$.c->data[0]); + name = multiname_clone($$.c->data[0]); $$.c = code_cutlast($$.c); $$.c = code_append($$.c, paramcode); $$.c = abc_callproperty2($$.c, name, len); } else if($$.c->opcode == OPCODE_GETSLOT) { int slot = (int)(ptroff_t)$$.c->data[0]; trait_t*t = abc_class_find_slotid(state->cls,slot);//FIXME - if(t->kind!=TRAIT_METHOD) {syntaxerror("not a function");} - - abc_method_t*m = t->method; + if(t->kind!=TRAIT_METHOD) { + //flash allows to assign closures to members. + //syntaxerror("not a function"); + } + name = t->name; $$.c = code_cutlast($$.c); $$.c = code_append($$.c, paramcode); - - //$$.c = abc_callmethod($$.c, m, len); //#1051 illegal early access binding - $$.c = abc_callproperty2($$.c, t->name, len); + //$$.c = abc_callmethod($$.c, t->method, len); //#1051 illegal early access binding + $$.c = abc_callproperty2($$.c, name, len); } else { - int i = find_variable_safe("this", 0); - $$.c = abc_getlocal($$.c, i); + $$.c = abc_getlocal_0($$.c); $$.c = code_append($$.c, paramcode); $$.c = abc_call($$.c, len); } - /* TODO: look up the functions's return value */ - $$.t = TYPE_ANY; + + memberinfo_t*f = 0; + + if(TYPE_IS_FUNCTION($1.t) && + (f = registry_findmember($1.t, "call"))) { + $$.t = f->return_type; + } else { + $$.c = abc_coerce_a($$.c); + $$.t = TYPE_ANY; + } } RETURN: "return" %prec prec_none { @@ -1257,11 +1453,11 @@ NONCOMMAEXPRESSION : E %prec prec_belowminus {$$=$1;} EXPRESSION : E %prec prec_belowminus {$$ = $1;} EXPRESSION : EXPRESSION ',' E %prec prec_belowminus { $$.c = $1.c; - $$.c = abc_pop($$.c); + $$.c = cut_last_push($$.c); $$.c = code_append($$.c,$3.c); $$.t = $3.t; } -VOIDEXPRESSION : EXPRESSION %prec prec_belowminus {$$=abc_pop($1.c);} +VOIDEXPRESSION : EXPRESSION %prec prec_belowminus {$$=cut_last_push($1.c);} // ----------------------- expression evaluation ------------------------------------- @@ -1299,41 +1495,30 @@ E : E "||" E {$$.t = join_types($1.t, $3.t, 'O'); $$.c = converttype($$.c, $1.t, $$.t); $$.c = abc_dup($$.c); code_t*jmp = $$.c = abc_iftrue($$.c, 0); - $$.c = abc_pop($$.c); + $$.c = cut_last_push($$.c); $$.c = code_append($$.c,$3.c); - $$.c = converttype($$.c, $1.t, $$.t); + $$.c = converttype($$.c, $3.t, $$.t); code_t*label = $$.c = abc_label($$.c); jmp->branch = label; } -E : E "&&" E {$$.t = join_types($1.t, $3.t, 'A'); +E : E "&&" E { + $$.t = join_types($1.t, $3.t, 'A'); + /*printf("%08x:\n",$1.t); + code_dump($1.c, 0, 0, "", stdout); + printf("%08x:\n",$3.t); + code_dump($3.c, 0, 0, "", stdout); + printf("joining %08x and %08x to %08x\n", $1.t, $3.t, $$.t);*/ $$.c = $1.c; $$.c = converttype($$.c, $1.t, $$.t); $$.c = abc_dup($$.c); code_t*jmp = $$.c = abc_iffalse($$.c, 0); - $$.c = abc_pop($$.c); + $$.c = cut_last_push($$.c); $$.c = code_append($$.c,$3.c); - $$.c = converttype($$.c, $1.t, $$.t); + $$.c = converttype($$.c, $3.t, $$.t); code_t*label = $$.c = abc_label($$.c); jmp->branch = label; } -E : E '.' T_IDENTIFIER - {$$.c = $1.c; - if($$.t) { - //namespace_t ns = {$$.t->access, (char*)$$.t->package}; - namespace_t ns = {$$.t->access, ""}; - multiname_t m = {QNAME, &ns, 0, $3->text}; - $$.c = abc_getproperty2($$.c, &m); - /* FIXME: get type of ($1.t).$3 */ - $$.t = registry_getanytype(); - } else { - namespace_t ns = {ACCESS_PACKAGE, ""}; - multiname_t m = {QNAME, &ns, 0, $3->text}; - $$.c = abc_getproperty2($$.c, &m); - $$.t = registry_getanytype(); - } - } - E : '!' E {$$.c=$2.c; $$.c = abc_not($$.c); $$.t = TYPE_BOOLEAN; @@ -1356,6 +1541,14 @@ E : E "is" E E : '(' E ')' {$$=$2;} E : '-' E {$$=$2;} +E : E '[' E ']' { + $$.c = $1.c; + $$.c = code_append($$.c, $3.c); + + MULTINAME_LATE(m, $1.t?$1.t->access:ACCESS_PACKAGE, ""); + $$.c = abc_getproperty2($$.c, &m); +} + E : E "+=" E { code_t*c = $3.c; if(TYPE_IS_INT($3.t) || TYPE_IS_UINT($3.t)) { @@ -1365,7 +1558,7 @@ E : E "+=" E { } c=converttype(c, join_types($1.t, $3.t, '+'), $1.t); - $$.c = toreadwrite($1.c, c); + $$.c = toreadwrite($1.c, c, 0); $$.t = $1.t; } E : E "-=" E { code_t*c = $3.c; @@ -1376,14 +1569,13 @@ E : E "-=" E { code_t*c = $3.c; } c=converttype(c, join_types($1.t, $3.t, '-'), $1.t); - $$.c = toreadwrite($1.c, c); + $$.c = toreadwrite($1.c, c, 0); $$.t = $1.t; } E : E '=' E { code_t*c = 0; - c = abc_pop(c); c = code_append(c, $3.c); c = converttype(c, $3.t, $1.t); - $$.c = toreadwrite($1.c, c); + $$.c = toreadwrite($1.c, c, 1); $$.t = $1.t; } @@ -1397,7 +1589,7 @@ E : E "++" { code_t*c = 0; type = TYPE_NUMBER; } c=converttype(c, type, $1.t); - $$.c = toreadwrite($1.c, c); + $$.c = toreadwrite($1.c, c, 0); $$.t = $1.t; } E : E "--" { code_t*c = 0; @@ -1409,27 +1601,82 @@ E : E "--" { code_t*c = 0; type = TYPE_NUMBER; } c=converttype(c, type, $1.t); - $$.c = toreadwrite($1.c, c); + $$.c = toreadwrite($1.c, c, 0); $$.t = $1.t; } +E : "++" E { code_t*c = 0; + classinfo_t*type = $2.t; + if(TYPE_IS_INT(type) || TYPE_IS_UINT(type)) { + c=abc_increment_i(c); + } else { + c=abc_increment(c); + type = TYPE_NUMBER; + } + c=converttype(c, type, $2.t); + $$.c = toreadwrite($2.c, c, 0); + $$.t = $2.t; + } + +E : E '.' T_IDENTIFIER + {$$.c = $1.c; + if($$.t) { + memberinfo_t*f = registry_findmember($$.t, $3->text); + + if(f && f->slot) { + $$.c = abc_getslot($$.c, f->slot); + } else { + namespace_t ns = {$$.t->access, ""}; // needs to be "", not $$.t->package + multiname_t m = {QNAME, &ns, 0, $3->text}; + $$.c = abc_getproperty2($$.c, &m); + } + /* determine type */ + if(f) { + if(f->kind == MEMBER_METHOD) { + $$.t = TYPE_FUNCTION(f); + } else { + $$.t = f->type; + } + } else { + $$.c = abc_coerce_a($$.c); + $$.t = registry_getanytype(); + } + } else { + namespace_t ns = {ACCESS_PACKAGE, ""}; + multiname_t m = {QNAME, &ns, 0, $3->text}; + $$.c = abc_getproperty2($$.c, &m); + $$.c = abc_coerce_a($$.c); + $$.t = registry_getanytype(); + } + } + VAR_READ : T_IDENTIFIER { $$.t = 0; $$.c = 0; int i; - memberinfo_t*m; + memberinfo_t*f = 0; if((i = find_variable($1->text, &$$.t)) >= 0) { + // $1 is a local variable $$.c = abc_getlocal($$.c, i); - } else if((m = registry_findmember(state->clsinfo, $1->text))) { - $$.t = m->type; - if(m->slot>0) { + } else if((f = registry_findmember(state->clsinfo, $1->text))) { + // $1 is a function in this class + if(f->kind == MEMBER_METHOD) { + $$.t = TYPE_FUNCTION(f); + } else { + $$.t = f->type; + } + if(f->slot>0) { $$.c = abc_getlocal_0($$.c); - $$.c = abc_getslot($$.c, m->slot); + $$.c = abc_getslot($$.c, f->slot); } else { + namespace_t ns = {state->clsinfo->access, ""}; + multiname_t m = {QNAME, &ns, 0, $1->text}; $$.c = abc_getlocal_0($$.c); - $$.c = abc_getproperty($$.c, $1->text); + $$.c = abc_getproperty2($$.c, &m); } } else { + // let the avm2 resolve $1 + if(strcmp($1->text,"trace")) warning("Couldn't resolve %s, doing late binding", $1->text); state->late_binding = 1; @@ -1509,15 +1756,6 @@ GETSET : "get" {$$=$1;} | "set" {$$=$1;} | {$$=empty_token();} -MAYBE_PARAM_LIST: {$$=list_new();} -MAYBE_PARAM_LIST: PARAM_LIST {$$=$1;} -PARAM_LIST: PARAM_LIST ',' PARAM {$$ =$1; list_append($$, $3);} -PARAM_LIST: PARAM {$$ = list_new();list_append($$, $1);} -PARAM: T_IDENTIFIER ':' TYPE {$$ = malloc(sizeof(param_t)); - $$->name=$1->text;$$->type = $3;} -PARAM: T_IDENTIFIER {$$ = malloc(sizeof(param_t)); - $$->name=$1->text;$$->type = TYPE_ANY;} - IDECLARATION : VARIABLE_DECLARATION IDECLARATION : FUNCTION_DECLARATION