rem: Scheme_Object *skip_rib)
add: Scheme_Object *skip_ribs)
context: static Scheme_Object *resolve_env(Scheme_Object *a, long phase, 				  int w_mod, Scheme_Object **get_names,				  Scheme_Object *skip_rib)/* Module binding ignored if w_mod is 0.   If module bound, result is module idx, and get_names[0] is set to source name,     get_names[1] is set to the nominal source module, get_names[2] is set to     the nominal source module's export, and get_names[3] is set to the phase of     the source definition   If lexically bound, result is env id, and a get_names[0] is set to scheme_undefined.   If neither, result is #f and get_names[0] is either unchanged or NULL. */{  WRAP_POS wraps;  Scheme_Object *o_rename_stack = scheme_null;  Scheme_Object *mresult = scheme_false;  Scheme_Object *modidx_shift_to = NULL, *modidx_shift_from = NULL;  Scheme_Object *rename_stack[QUICK_STACK_SIZE];  int stack_pos = 0;  int is_in_module = 0, skip_other_mods = 0;  Scheme_Lexical_Rib *rib = NULL, *did_rib = NULL;  WRAP_POS_INIT(wraps, ((Scheme_Stx *)a)->wraps);  while (1) {    if (WRAP_POS_END_P(wraps)) {      /* See rename case for info on rename_stack: */      Scheme_Object *result;      if (!noprint && !strcmp(SCHEME_SYM_VAL(SCHEME_STX_VAL(a)), "stx") && (cnter == 1332)) {	printf("done\n");      }      result = scheme_false;      while (!SCHEME_NULLP(o_rename_stack)) {	if (SAME_OBJ(SCHEME_CAAR(o_rename_stack), result))	  result = SCHEME_CDR(SCHEME_CAR(o_rename_stack));	o_rename_stack = SCHEME_CDR(o_rename_stack);      }      while (stack_pos) {	if (SAME_OBJ(rename_stack[stack_pos - 1], result))	  result = rename_stack[stack_pos - 2];	stack_pos -= 2;      }      if (SCHEME_FALSEP(result))	result = mresult;      else if (get_names)	get_names[0] = scheme_undefined;      if (!noprint && !strcmp(SCHEME_SYM_VAL(SCHEME_STX_VAL(a)), "stx")) {	cnter++;	printf("env: %s %d\n", (SCHEME_SYMBOLP(result) ? SCHEME_SYM_VAL(result) : "#f"), cnter);      }      return result;    } else if (SCHEME_RENAMESP(WRAP_POS_FIRST(wraps)) && w_mod) {      /* Module rename: */      Module_Renames *mrn = (Module_Renames *)WRAP_POS_FIRST(wraps);      if ((!is_in_module || (mrn->kind != mzMOD_RENAME_TOPLEVEL)) && !skip_other_mods) {	if (mrn->kind != mzMOD_RENAME_TOPLEVEL)	  is_in_module = 1;		if (phase == mrn->phase) {	  Scheme_Object *rename, *nominal = NULL, *glob_id;	  	  if (mrn->marked_names)	    glob_id = scheme_tl_id_sym((Scheme_Env *)mrn->marked_names, a, 0);	  else	    glob_id = SCHEME_STX_VAL(a);	  rename = scheme_hash_get(mrn->ht, glob_id);	  if (!rename && mrn->plus_kernel) {	    rename = scheme_hash_get(krn->ht, glob_id);	    nominal = mrn->plus_kernel_nominal_source;	  }	  	  if (rename) {	    if (mrn->kind == mzMOD_RENAME_MARKED)	      skip_other_mods = 1;	    /* match; set mresult, which is used in the case of no lexical capture: */	    if (SCHEME_PAIRP(rename))	      mresult = SCHEME_CAR(rename);	    else	      mresult = rename;	    	    if (modidx_shift_from)	      mresult = scheme_modidx_shift(mresult,					    modidx_shift_from,					    modidx_shift_to);	    if (get_names) {	      if (SCHEME_PAIRP(rename)) {		if (SCHEME_IMMUTABLEP(rename)) {		  /* (cons-immutable modidx nominal_modidx) case */		  get_names[0] = glob_id;		  get_names[1] = SCHEME_CDR(rename);		  get_names[2] = get_names[0];		} else {		  rename = SCHEME_CDR(rename);		  if (SCHEME_PAIRP(rename)) {		    /* (list* modidx [mod-phase] exportname nominal_modidx nominal_exportname) case */		    if (SCHEME_INTP(SCHEME_CAR(rename))) {		      get_names[3] = SCHEME_CAR(rename);		      rename = SCHEME_CDR(rename);		    }		    get_names[0] = SCHEME_CAR(rename);		    get_names[1] = SCHEME_CADR(rename);		    get_names[2] = SCHEME_CDDR(rename);		  } else {		    /* (cons modidx exportname) case */		    get_names[0] = rename;		    get_names[2] = NULL; /* finish below */		  }		}	      } else {		get_names[0] = glob_id;		get_names[2] = NULL; /* finish below */	      }	      if (!get_names[2]) {		get_names[2] = get_names[0];		if (nominal)		  get_names[1] = nominal;		else		  get_names[1] = mresult;	      }	    }	  } else {	    mresult = scheme_false;	    if (get_names)	      get_names[0] = NULL;	  }	}      }    } else if (SCHEME_BOXP(WRAP_POS_FIRST(wraps)) && w_mod) {      /* Phase shift */      Scheme_Object *vec, *n, *dest, *src;      vec = SCHEME_PTR_VAL(WRAP_POS_FIRST(wraps));      n = SCHEME_VEC_ELS(vec)[0];      phase -= SCHEME_INT_VAL(n);            src = SCHEME_VEC_ELS(vec)[1];      dest = SCHEME_VEC_ELS(vec)[2];      /* If src is #f, shift is just for phase; no redirection */      if (!SCHEME_FALSEP(src)) {	if (!modidx_shift_to) {	  modidx_shift_to = dest;	} else if (!SAME_OBJ(modidx_shift_from, dest)) {	  modidx_shift_to = scheme_modidx_shift(dest,						modidx_shift_from,						modidx_shift_to);	}		modidx_shift_from = src;      }    } else if (rib || SCHEME_VECTORP(WRAP_POS_FIRST(wraps))) {      /* Lexical rename: */      Scheme_Object *rename, *renamed;      int ri, c, istart, iend;      if (rib) {	rename = rib->rename;	rib = rib->next;      } else {	rename = WRAP_POS_FIRST(wraps);      }      c = SCHEME_RENAME_LEN(rename);      /* Get index from hash table, if there is one: */      if (!SCHEME_FALSEP(SCHEME_VEC_ELS(rename)[1])) {	void *pos;	pos = scheme_hash_get((Scheme_Hash_Table *)(SCHEME_VEC_ELS(rename)[1]), SCHEME_STX_VAL(a));	if (pos) {	  istart = SCHEME_INT_VAL(pos);	  if (istart < 0) {	    /* -1 indicates multiple slots matching this name. */	    istart = 0;	    iend = c;	  } else	    iend = istart + 1;	} else {	  istart = 0;	  iend = 0;	}      } else {	istart = 0;	iend = c;      }      for (ri = istart; ri < iend; ri++) {	renamed = SCHEME_VEC_ELS(rename)[2+ri];	if (SAME_OBJ(SCHEME_STX_VAL(a), SCHEME_STX_SYM(renamed))) {	  int same;	  {	    Scheme_Object *other_env, *envname;	    if (SCHEME_SYMBOLP(renamed)) {	      /* Simplified table */	      other_env = scheme_false;	      envname = SCHEME_VEC_ELS(rename)[2+c+ri];	      same = 1;	    } else {	      envname = SCHEME_VEC_ELS(rename)[0];	      other_env = SCHEME_VEC_ELS(rename)[2+c+ri];	    	      	      if (SCHEME_VOIDP(other_env)) {		noprint++;		other_env = resolve_env(renamed, 0, 0, NULL, WRAP_POS_FIRST(wraps));		--noprint;		SCHEME_VEC_ELS(rename)[2+c+ri] = other_env;	      }	      {		/* If same==2 because a barrier was used, then if the		   rename target itself was never renamed, mark		   barriers don't count. The same_marks check may have		   used mark barriers when it shouldn't, so		   double-check. */		/* If same==2 because a rib was used as a barrier, then		   we need to check again with a specific rib (possibly #f). */		WRAP_POS w2;		WRAP_POS_INIT(w2, ((Scheme_Stx *)renamed)->wraps);		same = same_marks(&w2, &wraps, SCHEME_FALSEP(other_env), other_env, WRAP_POS_FIRST(wraps));	      }	    }	    	    if (same) { /* (could have changed since last test) */	      /* If it turns out that we're going to return		 other_env, then return envname instead. */	      if (!noprint && !strcmp(SCHEME_SYM_VAL(SCHEME_STX_VAL(a)), "stx") && (cnter == 1332)) {		printf("match\n");	      }	      if (stack_pos < QUICK_STACK_SIZE) {		rename_stack[stack_pos++] = envname;		rename_stack[stack_pos++] = other_env;	      } else {		o_rename_stack = CONS(CONS(other_env, envname),				      o_rename_stack);	      }	      rib = NULL; /* skip rest of rib (if any) */	    }	    break;	  }	}      }    } else if (SCHEME_RIBP(WRAP_POS_FIRST(wraps))) {      /* Lexical-rename rib. Splice in the names. */      rib = (Scheme_Lexical_Rib *)WRAP_POS_FIRST(wraps);      if (SAME_OBJ(skip_rib, (Scheme_Object *)rib))	rib = NULL;      else if (SAME_OBJ(did_rib, rib))	rib = NULL;      else {	did_rib = rib;	rib = rib->next; /* First rib record has no rename */      }    } else if (SCHEME_NUMBERP(WRAP_POS_FIRST(wraps))	       || SAME_OBJ(WRAP_POS_FIRST(wraps), barrier_symbol)) {      did_rib = NULL;    }    if (!rib)      WRAP_POS_INC(wraps);  }}