rem: if (modname && !(flags & SCHEME_RESOLVE_MODIDS) && !SAME_OBJ(modidx, kernel_symbol)) {
add: if (modname && !(flags & SCHEME_RESOLVE_MODIDS) && (!SAME_OBJ(modidx, kernel_symbol) || (flags & SCHEME_REFERENCING))) {
context: scheme_lookup_binding(Scheme_Object *find_id, Scheme_Comp_Env *env, int flags,		      Scheme_Object *certs, Scheme_Object *in_modidx,		      Scheme_Env **_menv, int *_protected){  Scheme_Comp_Env *frame;  int j = 0, p = 0, modpos, skip_stops = 0, mod_defn_phase, module_self_reference = 0;  Scheme_Bucket *b;  Scheme_Object *val, *modidx, *modname, *src_find_id, *find_global_id;  Scheme_Env *genv;  long phase;  /* Need to know the phase being compiled */  phase = env->genv->phase;    /* Walk through the compilation frames */  frame = env;  for (frame = env; frame->next != NULL; frame = frame->next) {    int i;    Scheme_Object *uid;    if (frame->flags & SCHEME_LAMBDA_FRAME)      j++;              if (!skip_stops || !(frame->flags & SCHEME_FOR_STOPS)) {      if (frame->flags & SCHEME_FOR_STOPS)	skip_stops = 1;      uid = scheme_env_frame_uid(frame);      for (i = frame->num_bindings; i--; ) {	if (frame->values[i]) {	  if (frame->uids) 	    uid = frame->uids[i];	  if (SAME_OBJ(SCHEME_STX_VAL(find_id), SCHEME_STX_VAL(frame->values[i]))	      && (scheme_stx_env_bound_eq(find_id, frame->values[i], uid, phase)		  || ((frame->flags & SCHEME_CAPTURE_WITHOUT_RENAME)		      && scheme_stx_module_eq(find_id, frame->values[i], phase))		  || ((frame->flags & SCHEME_CAPTURE_LIFTED)		      && scheme_stx_bound_eq(find_id, frame->values[i], phase)))) {	    /* Found a lambda- or let-bound variable: */	    /* First, check certs (don't bind with fewer certs): */	    if (!(flags & SCHEME_NO_CERT_CHECKS) 		&& !(frame->flags & (SCHEME_CAPTURE_WITHOUT_RENAME | SCHEME_CAPTURE_LIFTED))) {	      if (scheme_stx_has_more_certs(find_id, certs, frame->values[i], frame->certs)) {		scheme_wrong_syntax(scheme_compile_stx_string, NULL, find_id,				    "reference is more certified than binding");		return NULL;	      }	    }	    /* Looks ok; return a lexical reference */	    if (flags & SCHEME_DONT_MARK_USE)	      return scheme_make_local(scheme_local_type, 0);	    else	      return (Scheme_Object *)get_frame_loc(frame, i, j, p, flags);	  }	}      }      for (i = COMPILE_DATA(frame)->num_const; i--; ) {	int issame;	if (frame->flags & SCHEME_CAPTURE_WITHOUT_RENAME)	  issame = scheme_stx_module_eq(find_id, COMPILE_DATA(frame)->const_names[i], phase);	else {	  if (COMPILE_DATA(frame)->const_uids) uid = COMPILE_DATA(frame)->const_uids[i];	  issame = (SAME_OBJ(SCHEME_STX_VAL(find_id), 			     SCHEME_STX_VAL(COMPILE_DATA(frame)->const_names[i]))		    && scheme_stx_env_bound_eq(find_id, COMPILE_DATA(frame)->const_names[i], uid, phase));	}      	if (issame) {	  if (!(flags & SCHEME_NO_CERT_CHECKS) 	      && !(frame->flags & SCHEME_CAPTURE_WITHOUT_RENAME)) {	    if (scheme_stx_has_more_certs(find_id, certs, COMPILE_DATA(frame)->const_names[i], frame->certs)) {	      scheme_wrong_syntax(scheme_compile_stx_string, NULL, find_id,				  "reference is more certified than binding");	      return NULL;	    }	  }	  val = COMPILE_DATA(frame)->const_vals[i];		  if (!val) {	    scheme_wrong_syntax(scheme_compile_stx_string, NULL, find_id,				"variable used out of context");	    return NULL;	  }	  if (SCHEME_FALSEP(val)) {	    /* Corresponds to a run-time binding (but will be replaced later	       through a renaming to a different binding) */	    return NULL;	  }	  if (!(flags & SCHEME_ENV_CONSTANTS_OK)) {	    if (SAME_TYPE(SCHEME_TYPE(val), scheme_macro_type))	      return val;	    else if (SAME_TYPE(SCHEME_TYPE(val), scheme_lazy_macro_type))	      return force_lazy_macro(val, phase);	    else	      scheme_wrong_syntax(scheme_set_stx_string, NULL, find_id,				  "local syntax identifier cannot be mutated");	    return NULL;	  }	  return val;	}      }    }    p += frame->num_bindings;  }  src_find_id = find_id;  modidx = scheme_stx_module_name(&find_id, phase, NULL, NULL, &mod_defn_phase);  /* Used out of context? */  if (SAME_OBJ(modidx, scheme_undefined)) {    if (!(flags & SCHEME_OUT_OF_CONTEXT_OK))      scheme_wrong_syntax(scheme_compile_stx_string, NULL, find_id,			  "identifier used out of context");    return NULL;  }  if (modidx) {    /* If it's an access path, resolve it: */    modname = scheme_module_resolve(modidx);    if (env->genv->module && SAME_OBJ(modname, env->genv->module->modname)) {      modidx = NULL;      modname = NULL;      genv = env->genv;      /* So we can distinguish between unbound variables in a module	 and references to top-level definitions: */      module_self_reference = 1;    } else {      genv = scheme_module_access(modname, env->genv, mod_defn_phase);      if (!genv) {	if (env->genv->phase) {	  /* The failure might be due a laziness in required-syntax	     execution. Force all laziness at the prior level 	     and try again. */	  scheme_module_force_lazy(env->genv, 1);	  genv = scheme_module_access(modname, env->genv, mod_defn_phase);	}	if (!genv) {	  scheme_wrong_syntax("require", NULL, src_find_id, 			      "broken compiled code (phase %d, defn-phase %d): cannot find module %S",			      env->genv->phase, mod_defn_phase, modname);	  return NULL;	}      }    }  } else {    genv = env->genv;    modname = NULL;    if (genv->module && !genv->rename) {      /* Free variable. Maybe don't continue. */      if (flags & (SCHEME_SETTING | SCHEME_REFERENCING)) {	scheme_wrong_syntax(((flags & SCHEME_SETTING) 			     ? scheme_set_stx_string			     : scheme_var_ref_string),			    NULL, src_find_id, "unbound variable in module");	return NULL;      }      if (flags & SCHEME_NULL_FOR_UNBOUND)	return NULL;    }  }  if (_menv && genv->module)    *_menv = genv;    if (!modname && SCHEME_STXP(find_id))    find_global_id = scheme_tl_id_sym(env->genv, find_id, 0);  else    find_global_id = find_id;  /* Try syntax table: */  if (modname) {    val = scheme_module_syntax(modname, env->genv, find_id);    if (val && !(flags & SCHEME_NO_CERT_CHECKS))      scheme_check_accessible_in_module(genv, env->insp, in_modidx, 					find_id, src_find_id, certs, NULL, -2, 0, 					NULL);  } else {    /* Only try syntax table if there's not an explicit (later)       variable mapping: */    if (genv->shadowed_syntax 	&& scheme_hash_get(genv->shadowed_syntax, find_global_id))      val = NULL;    else      val = scheme_lookup_in_table(genv->syntax, (const char *)find_global_id);  }    if (val) {    if (SAME_TYPE(SCHEME_TYPE(val), scheme_lazy_macro_type))      return force_lazy_macro(val, phase);    return val;  }  if (modname) {    Scheme_Object *pos;    if (flags & SCHEME_NO_CERT_CHECKS)       pos = 0;    else      pos = scheme_check_accessible_in_module(genv, env->insp, in_modidx, 					      find_id, src_find_id, certs, NULL, -1, 1,					      _protected);    modpos = SCHEME_INT_VAL(pos);  } else    modpos = -1;  if (modname && (flags & SCHEME_SETTING)) {    if (SAME_OBJ(src_find_id, find_id) || SAME_OBJ(SCHEME_STX_SYM(src_find_id), find_id))      find_id = NULL;    scheme_wrong_syntax(scheme_set_stx_string, find_id, src_find_id, "cannot mutate module-required variable");    return NULL;  }  if (!modname && (flags & (SCHEME_SETTING | SCHEME_REFERENCING)) && (genv->module && !genv->rename)) {    /* Check for set! of unbound variable: */        if (!scheme_lookup_in_table(genv->toplevel, (const char *)find_global_id)) {      scheme_wrong_syntax(((flags & SCHEME_SETTING) 			     ? scheme_set_stx_string			     : scheme_var_ref_string), 			  NULL, src_find_id, "unbound variable in module");      return NULL;    }  }  if (!modname && (flags & SCHEME_NULL_FOR_UNBOUND)) {    if (module_self_reference) {      /* Since the module has a rename for this id, it's certainly defined. */      if (!(flags & SCHEME_RESOLVE_MODIDS)) {	/* This is the same thing as #%top handling in compile mode. But	   for expand mode, it prevents wrapping the identifier with #%top. */	/* Don't need a pos, because the symbol's gensym-ness (if any) will be	   preserved within the module. */	return scheme_hash_module_variable(genv, genv->module->self_modidx, find_id, 					   genv->module->insp,					   -1, genv->mod_phase);      }    } else      return NULL;  }  /* Used to have `&& !SAME_OBJ(modidx, modname)' below, but that was a bad     idea, because it causes module instances to be preserved. */  if (modname && !(flags & SCHEME_RESOLVE_MODIDS) && !SAME_OBJ(modidx, kernel_symbol)) {    /* Create a module variable reference, so that idx is preserved: */    return scheme_hash_module_variable(env->genv, modidx, find_id, 				       genv->module->insp,				       modpos, mod_defn_phase);  }  if (!modname && (flags & (SCHEME_SETTING | SCHEME_REFERENCING)) && genv->module) {    /* Need to return a variable reference in this case, too. */    return scheme_hash_module_variable(env->genv, genv->module->self_modidx, find_global_id, 				       genv->module->insp,				       modpos, genv->mod_phase);  }  b = scheme_bucket_from_table(genv->toplevel, (char *)find_global_id);  if ((flags & SCHEME_ELIM_CONST) && b && b->val       && (((Scheme_Bucket_With_Flags *)b)->flags & GLOB_IS_CONST)      && !(flags & SCHEME_GLOB_ALWAYS_REFERENCE))    return (Scheme_Object *)b->val;  if (!((Scheme_Bucket_With_Home *)b)->home)    ((Scheme_Bucket_With_Home *)b)->home = genv;    return (Scheme_Object *)b;}