mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 05:39:18 +02:00
alternate approach to handling renamed forward refs
This commit is contained in:
parent
40d322ca5f
commit
8feb1e761e
2 changed files with 11 additions and 11 deletions
10
eval.c
10
eval.c
|
@ -58,6 +58,7 @@ sexp sexp_warn_undefs_op (sexp ctx, sexp self, sexp_sint_t n, sexp from, sexp to
|
||||||
if (sexp_envp(from)) from = sexp_env_bindings(from);
|
if (sexp_envp(from)) from = sexp_env_bindings(from);
|
||||||
for (x=from; sexp_pairp(x) && x!=to; x=sexp_env_next_cell(x))
|
for (x=from; sexp_pairp(x) && x!=to; x=sexp_env_next_cell(x))
|
||||||
if (sexp_cdr(x) == SEXP_UNDEF && sexp_car(x) != ignore
|
if (sexp_cdr(x) == SEXP_UNDEF && sexp_car(x) != ignore
|
||||||
|
&& !sexp_synclop(sexp_car(x))
|
||||||
&& sexp_not(sexp_memq(ctx, sexp_car(x), ignore)))
|
&& sexp_not(sexp_memq(ctx, sexp_car(x), ignore)))
|
||||||
sexp_warn(ctx, "reference to undefined variable: ", sexp_car(x));
|
sexp_warn(ctx, "reference to undefined variable: ", sexp_car(x));
|
||||||
return SEXP_VOID;
|
return SEXP_VOID;
|
||||||
|
@ -150,15 +151,6 @@ sexp sexp_env_cell_define (sexp ctx, sexp env, sexp key,
|
||||||
if (sexp_car(ls) == key) {
|
if (sexp_car(ls) == key) {
|
||||||
sexp_cdr(ls) = value;
|
sexp_cdr(ls) = value;
|
||||||
return ls;
|
return ls;
|
||||||
} else if (sexp_cdr(ls) == SEXP_UNDEF &&
|
|
||||||
sexp_synclop(sexp_car(ls)) &&
|
|
||||||
!sexp_synclop(key) &&
|
|
||||||
sexp_identifier_eq(ctx, env, key, sexp_synclo_env(sexp_car(ls)), sexp_synclo_expr(sexp_car(ls)))) {
|
|
||||||
/* handle an undefined renamed reference that would have */
|
|
||||||
/* resolved to this binding, renamed to what we define here */
|
|
||||||
sexp_car(ls) = key;
|
|
||||||
sexp_cdr(ls) = value;
|
|
||||||
return ls;
|
|
||||||
}
|
}
|
||||||
sexp_gc_preserve2(ctx, cell, ls);
|
sexp_gc_preserve2(ctx, cell, ls);
|
||||||
sexp_env_push(ctx, env, cell, key, value);
|
sexp_env_push(ctx, env, cell, key, value);
|
||||||
|
|
8
vm.c
8
vm.c
|
@ -1326,8 +1326,16 @@ sexp sexp_apply (sexp ctx, sexp proc, sexp args) {
|
||||||
break;
|
break;
|
||||||
case SEXP_OP_GLOBAL_REF:
|
case SEXP_OP_GLOBAL_REF:
|
||||||
_ALIGN_IP();
|
_ALIGN_IP();
|
||||||
|
if (sexp_cdr(_WORD0) == SEXP_UNDEF) {
|
||||||
|
/* handle renamed forward references by doing a final delayed */
|
||||||
|
/* lookup before throwing an undefined variable error */
|
||||||
|
if (sexp_synclop(sexp_car(_WORD0))) {
|
||||||
|
tmp1 = sexp_env_cell(ctx, sexp_synclo_env(sexp_car(_WORD0)), sexp_synclo_expr(sexp_car(_WORD0)), 0);
|
||||||
|
if (tmp1 != NULL) _WORD0 = tmp1;
|
||||||
|
}
|
||||||
if (sexp_cdr(_WORD0) == SEXP_UNDEF)
|
if (sexp_cdr(_WORD0) == SEXP_UNDEF)
|
||||||
sexp_raise("undefined variable", sexp_list1(ctx, sexp_car(_WORD0)));
|
sexp_raise("undefined variable", sexp_list1(ctx, sexp_car(_WORD0)));
|
||||||
|
}
|
||||||
/* ... FALLTHROUGH ... */
|
/* ... FALLTHROUGH ... */
|
||||||
case SEXP_OP_GLOBAL_KNOWN_REF:
|
case SEXP_OP_GLOBAL_KNOWN_REF:
|
||||||
_ALIGN_IP();
|
_ALIGN_IP();
|
||||||
|
|
Loading…
Add table
Reference in a new issue