mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-22 07:09:18 +02:00
set! on an undefined variable now triggers an error
This commit is contained in:
parent
51df221034
commit
d6aaaa99d1
2 changed files with 10 additions and 2 deletions
5
eval.c
5
eval.c
|
@ -103,8 +103,11 @@ static sexp sexp_env_cell_define (sexp ctx, sexp env, sexp key,
|
|||
}
|
||||
#endif
|
||||
for (ls=sexp_env_bindings(env); sexp_pairp(ls); ls=sexp_env_next_cell(ls))
|
||||
if (sexp_car(ls) == key)
|
||||
if (sexp_car(ls) == key) {
|
||||
if (sexp_cdr(ls) == SEXP_UNDEF)
|
||||
sexp_cdr(ls) = value;
|
||||
return ls;
|
||||
}
|
||||
sexp_gc_preserve2(ctx, cell, ls);
|
||||
sexp_env_push(ctx, env, cell, key, value);
|
||||
sexp_gc_release2(ctx);
|
||||
|
|
7
vm.c
7
vm.c
|
@ -50,7 +50,7 @@ void sexp_stack_trace (sexp ctx, sexp out) {
|
|||
|
||||
sexp sexp_stack_trace_op (sexp ctx, sexp self, sexp_sint_t n, sexp out) {
|
||||
sexp_stack_trace(ctx, out);
|
||||
return SEXP_UNDEF;
|
||||
return SEXP_VOID;
|
||||
}
|
||||
|
||||
/************************* code generation ****************************/
|
||||
|
@ -197,6 +197,11 @@ static void generate_set (sexp ctx, sexp set) {
|
|||
}
|
||||
if (! sexp_lambdap(sexp_ref_loc(ref))) {
|
||||
/* global vars are set directly */
|
||||
if (sexp_cdr(sexp_ref_cell(ref)) == SEXP_UNDEF) {
|
||||
/* force an undefined variable error if still undef at runtime */
|
||||
generate_ref(ctx, ref, 1);
|
||||
emit(ctx, SEXP_OP_DROP);
|
||||
}
|
||||
emit_push(ctx, sexp_ref_cell(ref));
|
||||
emit(ctx, SEXP_OP_SET_CDR);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue