Skip to content

Commit

Permalink
Add more specific warning for error on no import, clarify docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashinn committed Jan 30, 2024
1 parent 97a04bd commit 29dd1a3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
11 changes: 11 additions & 0 deletions doc/chibi.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
sexp_write(ctx, x, out);
if (x != SEXP_UNDEF) {
sexp_write(ctx, x, out);
}
sexp_write_char(ctx, '\n', out);
if (strictp) sexp_stack_trace(ctx, out);
}
Expand Down Expand Up @@ -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)) {
Expand Down
3 changes: 3 additions & 0 deletions examples/hello.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(import (scheme base))

(write-string "Hello world!\n")

0 comments on commit 29dd1a3

Please sign in to comment.