-typedef struct _variable {
- int index;
- classinfo_t*type;
-} variable_t;
-
-static variable_t* find_variable(char*name)
-{
- state_t* s = state;
- while(s) {
- variable_t*v = 0;
- if(s->method)
- v = dict_lookup(s->vars, name);
- if(v) {
- return v;
- }
- s = s->old;
- }
- return 0;
-}
-static variable_t* find_variable_safe(char*name)
-{
- variable_t* v = find_variable(name);
- if(!v)
- syntaxerror("undefined variable: %s", name);
- return v;
-}
-static char variable_exists(char*name)
-{
- return dict_lookup(state->vars, name)!=0;
-}
-code_t*defaultvalue(code_t*c, classinfo_t*type);
-static int new_variable(char*name, classinfo_t*type, char init)
-{
- NEW(variable_t, v);
- v->index = global->variable_count;
- v->type = type;
-
- dict_put(state->vars, name, v);
-
- if(init && state->method && type) {
- /* if this is a typed variable:
- push default value for type on stack at the very beginning of the
- method, so that it always has that type regardless of the control
- path */
- state->method->initcode = defaultvalue(state->method->initcode, type);
- state->method->initcode = abc_setlocal(state->method->initcode, v->index);
- }
- return global->variable_count++;
-}
-#define TEMPVARNAME "__as3_temp__"
-static int gettempvar()
-{
- variable_t*v = find_variable(TEMPVARNAME);
- if(v)
- return v->index;
- return new_variable(TEMPVARNAME, 0, 0);
-}
-
-code_t* killvars(code_t*c)
-{
- int t;
- for(t=0;t<state->vars->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;
-}
-