+void unknown_variable(char*name)
+{
+ if(!state->method->unresolved_variables)
+ state->method->unresolved_variables = dict_new();
+ if(!dict_contains(state->method->unresolved_variables, name))
+ dict_put(state->method->unresolved_variables, name, 0);
+}
+
+#define parserassert(b) {if(!(b)) parsererror(__FILE__, __LINE__,__func__);}
+
+static void parsererror(const char*file, int line, const char*f)
+{
+ syntaxerror("internal error in %s, %s:%d", f, file, line);
+}
+
+
+static code_t* add_scope_code(code_t*c, methodstate_t*m, char init)
+{
+ if(m->uses_slots || (m->late_binding && !m->inner)) { //???? especially inner functions need the pushscope
+ c = abc_getlocal_0(c);
+ c = abc_pushscope(c);
+ }
+ if(m->uses_slots) {
+ /* FIXME: this alloc_local() causes variable indexes to be
+ different in pass2 than in pass1 */
+ if(!m->activation_var)
+ m->activation_var = alloc_local();
+ if(init) {
+ c = abc_newactivation(c);
+ c = abc_dup(c);
+ c = abc_pushscope(c);
+ c = abc_setlocal(c, m->activation_var);
+ } else {
+ c = abc_getlocal(c, m->activation_var);
+ c = abc_pushscope(c);
+ }
+ }
+ return c;
+}
+
+static code_t* method_header(methodstate_t*m)
+{
+ code_t*c = 0;
+
+ c = add_scope_code(c, m, 1);
+
+ methodstate_list_t*l = m->innerfunctions;
+ while(l) {
+ parserassert(l->methodstate->abc);
+ if(m->uses_slots && l->methodstate->is_a_slot) {
+ c = abc_getscopeobject(c, 1);
+ c = abc_newfunction(c, l->methodstate->abc);
+ c = abc_dup(c);
+ c = abc_setlocal(c, l->methodstate->var_index);
+ c = abc_setslot(c, l->methodstate->slot_index);
+ } else {
+ c = abc_newfunction(c, l->methodstate->abc);
+ c = abc_setlocal(c, l->methodstate->var_index);
+ }
+ free(l->methodstate);l->methodstate=0;
+ l = l->next;
+ }
+ if(m->header) {
+ c = code_append(c, m->header);
+ m->header = 0;
+ }
+ if(m->is_constructor && !m->has_super) {
+ // call default constructor
+ c = abc_getlocal_0(c);
+ c = abc_constructsuper(c, 0);
+ }
+
+ if(m->slots) {
+ /* all parameters that are used by inner functions
+ need to be copied from local to slot */
+ parserassert(m->activation_var);
+ DICT_ITERATE_ITEMS(m->slots,char*,name,variable_t*,v) {
+ if(v->is_parameter) {
+ c = abc_getlocal(c, m->activation_var);
+ c = abc_getlocal(c, v->index);
+ c = abc_setslot(c, v->index);
+ }
+ }
+ }
+ list_free(m->innerfunctions);
+ m->innerfunctions = 0;
+ return c;
+}
+
+