emit error message when compiling a reference to a closed variable
This commit is contained in:
parent
840593f5f3
commit
3ecfe821e2
10
src/vm.c
10
src/vm.c
|
@ -26,6 +26,7 @@ pic_assq(pic_state *pic, pic_value key, pic_value assoc)
|
|||
|
||||
enum scope_type {
|
||||
SCOPE_GLOBAL,
|
||||
SCOPE_NONLOCAL,
|
||||
SCOPE_LOCAL,
|
||||
};
|
||||
|
||||
|
@ -33,6 +34,7 @@ static enum scope_type
|
|||
env_lookup(pic_state *pic, pic_value sym, struct pic_env *env, struct pic_pair **p)
|
||||
{
|
||||
pic_value v;
|
||||
bool f = true;
|
||||
|
||||
enter:
|
||||
|
||||
|
@ -41,6 +43,7 @@ env_lookup(pic_state *pic, pic_value sym, struct pic_env *env, struct pic_pair *
|
|||
*p = pic_pair_ptr(v);
|
||||
goto leave;
|
||||
}
|
||||
f = false;
|
||||
if (env->parent) {
|
||||
env = env->parent;
|
||||
goto enter;
|
||||
|
@ -51,8 +54,13 @@ env_lookup(pic_state *pic, pic_value sym, struct pic_env *env, struct pic_pair *
|
|||
leave:
|
||||
|
||||
if (env->parent) {
|
||||
if (f) {
|
||||
return SCOPE_LOCAL;
|
||||
}
|
||||
else {
|
||||
return SCOPE_NONLOCAL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return SCOPE_GLOBAL;
|
||||
}
|
||||
|
@ -250,6 +258,8 @@ pic_gen(pic_state *pic, struct pic_irep *irep, pic_value obj, struct pic_env *en
|
|||
irep->code[irep->clen].u.gvar = gvar;
|
||||
irep->clen++;
|
||||
break;
|
||||
case SCOPE_NONLOCAL:
|
||||
pic_raise(pic, "reference to closed variable not supported");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue