switching to SRFI-22 semantics.

-s is no longer needed, only the first non-option argument is
loaded (though you can use -- if the script name begins with a -).
main is then called automatically if defined.  -u was changed to -m.
This commit is contained in:
Alex Shinn 2009-12-28 16:30:51 +09:00
parent 2810fb8b1b
commit 007c3f07fe
5 changed files with 63 additions and 53 deletions

View file

@ -81,10 +81,10 @@ endif
all: chibi-scheme$(EXE) libs
COMPILED_LIBS := lib/srfi/27/rand$(SO) lib/srfi/33/bit$(SO) \
lib/srfi/69/hash$(SO) lib/srfi/98/env$(SO) lib/chibi/ast$(SO) \
lib/chibi/net$(SO) lib/chibi/filesystem$(SO) lib/chibi/process$(SO) \
lib/chibi/time$(SO) lib/chibi/system$(SO) lib/chibi/heap-stats$(SO) \
lib/chibi/disasm$(SO)
lib/srfi/69/hash$(SO) lib/srfi/98/env$(SO) \
lib/chibi/ast$(SO) lib/chibi/net$(SO) lib/chibi/filesystem$(SO) \
lib/chibi/process$(SO) lib/chibi/time$(SO) lib/chibi/system$(SO) \
lib/chibi/heap-stats$(SO) lib/chibi/disasm$(SO)
libs: $(COMPILED_LIBS)
@ -114,7 +114,7 @@ chibi-scheme-static$(EXE): main.o eval.o sexp.o
$(CC) $(XCFLAGS) $(STATICFLAGS) -o $@ $^ $(XLDFLAGS)
%.c: %.stub $(GENSTUBS)
LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) $(GENSTUBS) $<
LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) PATH=.:$(PATH) $(GENSTUBS) $<
lib/%$(SO): lib/%.c $(INCLUDES)
-$(CC) $(CLIBFLAGS) $(XCPPFLAGS) $(XCFLAGS) -o $@ $< -L. -lchibi-scheme
@ -141,19 +141,19 @@ test-basic: chibi-scheme$(EXE)
test-build:
./tests/build/build-tests.sh
test-numbers: all
test-numbers: chibi-scheme$(EXE)
LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ./chibi-scheme$(EXE) tests/numeric-tests.scm
test-hash: all
test-hash: chibi-scheme$(EXE)
LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ./chibi-scheme$(EXE) tests/hash-tests.scm
test-match: all
test-match: chibi-scheme$(EXE)
LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ./chibi-scheme$(EXE) tests/match-tests.scm
test-loop: all
test-loop: chibi-scheme$(EXE)
LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ./chibi-scheme$(EXE) tests/loop-tests.scm
test: all
test: chibi-scheme$(EXE)
LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ./chibi-scheme$(EXE) tests/r5rs-tests.scm
install: chibi-scheme$(EXE)

6
README
View file

@ -72,10 +72,10 @@ The essential functions to remember are:
A minimal module system is provided by default. Currently you can
load the following SRFIs with (import (srfi N)):
0, 1, 2, 6, 8, 9, 11, 16, 26, 27, 33, 46, 62, 69, 98
0, 1, 2, 6, 8, 9, 11, 16, 22, 23, 26, 27, 33, 46, 62, 69, 98
although 0, 46 and 62 are built into the default environment so
there's no need to import them.
although 0, 22, 23, 46 and 62 are built into the default environment
so there's no need to import them.
LOAD is extended to accept an optional environment argument, like
EVAL. You can also LOAD shared libraries in addition to Scheme source

84
main.c
View file

@ -13,7 +13,7 @@
#ifdef PLAN9
#define exit_failure() exits("ERROR")
#else
#define exit_failure() exit(1)
#define exit_failure() exit(70)
#endif
static void repl (sexp ctx) {
@ -66,21 +66,23 @@ static sexp check_exception (sexp ctx, sexp res) {
return res;
}
#define sexp_load_init() if (! init_loaded++) do { \
#define init_context() if (! ctx) do { \
ctx = sexp_make_eval_context(NULL, NULL, NULL, heap_size); \
env = sexp_context_env(ctx); \
sexp_gc_preserve2(ctx, tmp, args); \
} while (0)
#define load_init() if (! init_loaded++) do { \
init_context(); \
check_exception(ctx, sexp_load_standard_env(ctx, env, SEXP_FIVE)); \
sexp_gc_preserve2(ctx, str, args); \
} while (0)
void run_main (int argc, char **argv) {
char *arg, *impmod, *p;
sexp env, out=NULL, res=SEXP_VOID, ctx=NULL;
sexp_sint_t i, len, quit=0, print=0, init_loaded=0;
sexp env, out=SEXP_FALSE, res=SEXP_VOID, ctx=NULL;
sexp_sint_t i, j, len, quit=0, print=0, init_loaded=0;
sexp_uint_t heap_size=0;
sexp_gc_var2(str, args);
out = SEXP_FALSE;
sexp_gc_var2(tmp, args);
args = SEXP_NULL;
/* parse options */
@ -88,9 +90,9 @@ void run_main (int argc, char **argv) {
switch (argv[i][1]) {
case 'e':
case 'p':
load_init();
print = (argv[i][1] == 'p');
arg = ((argv[i][2] == '\0') ? argv[++i] : argv[i]+2);
sexp_load_init();
res = check_exception(ctx, sexp_read_from_string(ctx, arg));
res = check_exception(ctx, sexp_eval(ctx, res, env));
if (print) {
@ -103,13 +105,13 @@ void run_main (int argc, char **argv) {
i++;
break;
case 'l':
load_init();
arg = ((argv[i][2] == '\0') ? argv[++i] : argv[i]+2);
sexp_load_init();
check_exception(ctx, sexp_load_module_file(ctx, argv[++i], env));
break;
case 'u':
case 'm':
load_init();
arg = ((argv[i][2] == '\0') ? argv[++i] : argv[i]+2);
sexp_load_init();
len = strlen(arg)+strlen(sexp_import_prefix)+strlen(sexp_import_suffix);
impmod = (char*) malloc(len+1);
strcpy(impmod, sexp_import_prefix);
@ -122,52 +124,63 @@ void run_main (int argc, char **argv) {
free(impmod);
break;
case 'q':
if (! ctx) {
ctx = sexp_make_eval_context(NULL, NULL, NULL, heap_size);
env = sexp_context_env(ctx);
sexp_gc_preserve2(ctx, str, args);
}
if (! init_loaded++)
sexp_load_standard_parameters(ctx, env);
init_context();
if (! init_loaded++) sexp_load_standard_parameters(ctx, env);
break;
case 'A':
init_context();
arg = ((argv[i][2] == '\0') ? argv[++i] : argv[i]+2);
sexp_add_module_directory(ctx, str=sexp_c_string(ctx,arg,-1), SEXP_TRUE);
sexp_add_module_directory(ctx, tmp=sexp_c_string(ctx,arg,-1), SEXP_TRUE);
break;
case 'I':
init_context();
arg = ((argv[i][2] == '\0') ? argv[++i] : argv[i]+2);
sexp_add_module_directory(ctx, str=sexp_c_string(ctx,arg,-1), SEXP_FALSE);
break;
case 's':
for (argc=argc-1; argc>i+1; argc--)
args = sexp_cons(ctx, str=sexp_c_string(ctx,argv[argc],-1), args);
argc++;
sexp_add_module_directory(ctx, tmp=sexp_c_string(ctx,arg,-1), SEXP_FALSE);
break;
case '-':
i++;
goto done_options;
case 'h':
heap_size = atol(argv[++i]);
len = strlen(argv[i]);
if (heap_size && isalpha(argv[i][len-1])) {
switch (tolower(argv[i][len-1])) {
arg = ((argv[i][2] == '\0') ? argv[++i] : argv[i]+2);
heap_size = atol(arg);
len = strlen(arg);
if (heap_size && isalpha(arg[len-1])) {
switch (tolower(arg[len-1])) {
case 'k': heap_size *= 1024; break;
case 'm': heap_size *= (1024*1024); break;
}
}
break;
case 'V':
printf("chibi-scheme 0.3\n");
exit(0);
default:
fprintf(stderr, "unknown option: %s\n", argv[i]);
exit_failure();
}
}
done_options:
if (! quit) {
sexp_load_init();
load_init();
if (i < argc)
for (j=argc-1; j>i; j--)
args = sexp_cons(ctx, tmp=sexp_c_string(ctx,argv[j],-1), args);
else
args = sexp_cons(ctx, tmp=sexp_c_string(ctx,argv[0],-1), args);
sexp_env_define(ctx, env, sexp_intern(ctx, sexp_argv_symbol), args);
sexp_eval_string(ctx, sexp_argv_proc, env);
if (i < argc)
for ( ; i < argc; i++)
check_exception(ctx, sexp_load(ctx, str=sexp_c_string(ctx, argv[i], -1), env));
else
if (i < argc) { /* script usage */
check_exception(ctx, sexp_load(ctx, tmp=sexp_c_string(ctx, argv[i], -1), env));
tmp = sexp_intern(ctx, "main");
tmp = sexp_env_ref(env, tmp, SEXP_FALSE);
if (sexp_procedurep(tmp)) {
args = sexp_list1(ctx, args);
check_exception(ctx, sexp_apply(ctx, tmp, args));
}
} else {
repl(ctx);
}
}
sexp_gc_release2(ctx);
@ -178,4 +191,3 @@ int main (int argc, char **argv) {
run_main(argc, argv);
return 0;
}

View file

@ -15,7 +15,7 @@ i=0
for opts in `cat ${BUILDDIR}/build-opts.txt`; do
make cleaner 2>&1 >/dev/null
if make $opts 2>&1 >${BUILDDIR}/build${i}-make.out; then
if make $opts chibi-scheme 2>&1 >${BUILDDIR}/build${i}-make.out; then
if make test 2>&1 | tee ${BUILDDIR}/build${i}-test.out | grep -q -E 'FAIL|ERROR'; then
echo "[FAIL] ${i}: tests failed with $opts"
FAILURES=$((FAILURES + 1))

View file

@ -1,4 +1,4 @@
#! chibi-scheme -s
#! /usr/bin/env chibi-scheme
;; Note: this evolved as a throw-away script to provide certain core
;; modules, and so is a mess. Tread carefully.
@ -1152,5 +1152,3 @@
(with-output-to-file (cadr args) (lambda () (generate (car args))))))
(else
(error "usage: genstubs <file.stub> [<output.c>]"))))
(main (command-line-arguments))