diff --git a/eval.c b/eval.c index 899e146b..e4dd8bd5 100644 --- a/eval.c +++ b/eval.c @@ -40,12 +40,14 @@ static void sexp_warn (sexp ctx, char *msg, sexp x) { } } -void sexp_warn_undefs (sexp ctx, sexp from, sexp to, sexp res) { +sexp sexp_warn_undefs_op (sexp ctx, sexp self, sexp_sint_t n, sexp from, sexp to, sexp res) { sexp x, ignore = sexp_exceptionp(res) ? sexp_exception_irritants(res) : SEXP_NULL; + if (sexp_envp(from)) from = sexp_env_bindings(from); for (x=from; sexp_pairp(x) && x!=to; x=sexp_env_next_cell(x)) if (sexp_cdr(x) == SEXP_UNDEF && sexp_car(x) != ignore && sexp_not(sexp_memq(ctx, sexp_car(x), ignore))) sexp_warn(ctx, "reference to undefined variable: ", sexp_car(x)); + return SEXP_VOID; } @@ -1172,9 +1174,6 @@ sexp sexp_load_op (sexp ctx, sexp self, sexp_sint_t n, sexp source, sexp env) { res = SEXP_VOID; sexp_close_port(ctx, in); } -#if SEXP_USE_WARN_UNDEFS - sexp_warn_undefs(ctx, sexp_env_bindings(env), tmp, res); -#endif sexp_gc_release4(ctx); #if SEXP_USE_DL || SEXP_USE_STATIC_LIBS } diff --git a/include/chibi/eval.h b/include/chibi/eval.h index 14497a35..2400dcd2 100644 --- a/include/chibi/eval.h +++ b/include/chibi/eval.h @@ -82,7 +82,7 @@ SEXP_API sexp sexp_env_define (sexp ctx, sexp env, sexp sym, sexp val); SEXP_API sexp sexp_env_cell (sexp env, sexp sym, int localp); SEXP_API sexp sexp_env_ref (sexp env, sexp sym, sexp dflt); SEXP_API sexp sexp_parameter_ref (sexp ctx, sexp param); -SEXP_API void sexp_warn_undefs (sexp ctx, sexp from, sexp to, sexp res); +SEXP_API sexp sexp_warn_undefs_op (sexp ctx, sexp self, sexp_sint_t n, sexp from, sexp to, sexp res); SEXP_API sexp sexp_make_lit (sexp ctx, sexp value); SEXP_API sexp sexp_make_opcode (sexp, sexp, sexp, sexp, sexp, sexp, sexp, sexp, sexp, sexp, sexp, sexp, sexp_proc1); SEXP_API sexp sexp_make_procedure_op (sexp ctx, sexp self, sexp_sint_t n, sexp flags, sexp num_args, sexp bc, sexp vars); @@ -145,6 +145,7 @@ SEXP_API sexp sexp_make_setter_op (sexp ctx, sexp self, sexp_sint_t n, sexp name #define sexp_open_input_file(ctx, x) sexp_open_input_file_op(ctx, NULL, 1, x) #define sexp_open_output_file(ctx, x) sexp_open_output_file_op(ctx, NULL, 1, x) #define sexp_close_port(ctx, x) sexp_close_port_op(ctx, NULL, 1, x) +#define sexp_warn_undefs(ctx, from, to, res) sexp_warn_undefs_op(ctx, NULL, 3, from, to, res) #ifdef __cplusplus } /* extern "C" */ diff --git a/lib/meta.scm b/lib/meta.scm index ac5cd076..a2a80f58 100644 --- a/lib/meta.scm +++ b/lib/meta.scm @@ -146,6 +146,7 @@ ((body begin) (for-each (lambda (expr) (eval expr env)) (cdr x))))) (module-meta-data mod)) + (warn-undefs env #f) env)) (define (environment . ls) diff --git a/main.c b/main.c index 56a5c9c1..9c5109b9 100644 --- a/main.c +++ b/main.c @@ -472,7 +472,11 @@ void run_main (int argc, char **argv) { #endif /* load the script */ sexp_context_tracep(ctx) = 1; - check_exception(ctx, sexp_load(ctx, tmp=sexp_c_string(ctx, argv[i], -1), env)); + tmp = sexp_env_bindings(env); + check_exception(ctx, sexp_load(ctx, sym=sexp_c_string(ctx, argv[i], -1), env)); +#if SEXP_USE_WARN_UNDEFS + sexp_warn_undefs(ctx, env, tmp, SEXP_VOID); +#endif /* SRFI-22: run main if specified */ sym = sexp_intern(ctx, "main", -1); tmp = sexp_env_ref(env, sym, SEXP_FALSE); diff --git a/opcodes.c b/opcodes.c index 990b5bf7..0b487d3d 100644 --- a/opcodes.c +++ b/opcodes.c @@ -156,6 +156,7 @@ _FN2OPTP(SEXP_VOID, _I(SEXP_STRING), _I(SEXP_ENV), "load", (sexp)"interaction-en _FN4(SEXP_VOID, _I(SEXP_ENV), _I(SEXP_ENV), _I(SEXP_OBJECT), "%import", 0, sexp_env_import_op), _FN2OPTP(SEXP_VOID, _I(SEXP_EXCEPTION), _I(SEXP_OPORT), "print-exception", (sexp)"current-error-port", sexp_print_exception_op), _FN1OPTP(SEXP_VOID, _I(SEXP_OPORT), "print-stack-trace", (sexp)"current-error-port", sexp_stack_trace_op), +_FN3OPT(SEXP_VOID, _I(SEXP_OBJECT), _I(SEXP_OBJECT), _I(SEXP_OBJECT), "warn-undefs", SEXP_FALSE, sexp_warn_undefs_op), _FN1(_I(SEXP_OBJECT), _I(SEXP_EXCEPTION), "exception-type", 0, sexp_exception_type_op), _FN2OPT(_I(SEXP_STRING), _I(SEXP_FIXNUM), _I(SEXP_CHAR), "make-string", sexp_make_character(' '), sexp_make_string_op), _FN2OPT(_I(SEXP_STRING), _I(SEXP_FIXNUM), _I(SEXP_FIXNUM), "make-bytevector", SEXP_ZERO, sexp_make_bytes_op),