Add more specific warning for error on no import, clarify docs.

This commit is contained in:
Alex Shinn 2024-01-30 12:31:06 +09:00
parent 97a04bd2fc
commit 29dd1a3b81
3 changed files with 23 additions and 2 deletions

View file

@ -136,6 +136,8 @@ documentation system described in
build this manual. \ccode{chibi-ffi} is a tool to build wrappers for
C libraries, described in the FFI section below.
See the examples directory for some sample programs.
\section{Default Language}
\subsection{Scheme Standard}
@ -231,6 +233,15 @@ These forms perform basic selection and renaming of individual
identifiers from the given module. They may be composed to perform
combined selection and renaming.
Note while the repl provides default bindings as a convenience,
programs have strict semantics as in R7RS and must start with at least
one import, e.g.
\schemeblock{
(import (scheme base))
(write-string "Hello world!\n")
}
Some modules can be statically included in the initial configuration,
and even more may be included in image files, however in general
modules are searched for in a module load path. The definition of the

9
eval.c
View file

@ -45,7 +45,9 @@ void sexp_warn (sexp ctx, const char *msg, sexp x) {
if (sexp_oportp(out)) {
sexp_write_string(ctx, strictp ? "ERROR: " : "WARNING: ", out);
sexp_write_string(ctx, msg, out);
if (x != SEXP_UNDEF) {
sexp_write(ctx, x, out);
}
sexp_write_char(ctx, '\n', out);
if (strictp) sexp_stack_trace(ctx, out);
}
@ -1100,8 +1102,13 @@ static sexp analyze (sexp ctx, sexp object, int depth, int defok) {
} else if (sexp_idp(sexp_car(x))) {
if (! cell) {
res = analyze_app(ctx, x, depth);
if (sexp_exceptionp(res))
if (sexp_exceptionp(res)) {
sexp_warn(ctx, "exception inside undefined operator: ", sexp_car(x));
/* the common case of no imports */
if (!sexp_env_parent(sexp_context_env(ctx))) {
sexp_warn(ctx, "did you forget to import a language? e.g. (import (scheme base))", SEXP_UNDEF);
}
}
} else {
op = sexp_cdr(cell);
if (sexp_corep(op)) {

3
examples/hello.scm Normal file
View file

@ -0,0 +1,3 @@
(import (scheme base))
(write-string "Hello world!\n")