mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-21 14:49:18 +02:00
The big switch to (scheme base) as the default interaction-environment.
This commit is contained in:
parent
7a3f0a7362
commit
a54c6c4e98
7 changed files with 52 additions and 57 deletions
2
Makefile
2
Makefile
|
@ -3,7 +3,7 @@
|
||||||
.PHONY: dist mips-dist cleaner test test-all test-dist checkdefs
|
.PHONY: dist mips-dist cleaner test test-all test-dist checkdefs
|
||||||
.DEFAULT_GOAL := all
|
.DEFAULT_GOAL := all
|
||||||
|
|
||||||
CHIBI_FFI ?= $(CHIBI) tools/chibi-ffi
|
CHIBI_FFI ?= $(CHIBI) -q tools/chibi-ffi
|
||||||
CHIBI_FFI_DEPENDENCIES ?= $(CHIBI_DEPENDENCIES) tools/chibi-ffi
|
CHIBI_FFI_DEPENDENCIES ?= $(CHIBI_DEPENDENCIES) tools/chibi-ffi
|
||||||
|
|
||||||
CHIBI_DOC ?= $(CHIBI) tools/chibi-doc
|
CHIBI_DOC ?= $(CHIBI) tools/chibi-doc
|
||||||
|
|
|
@ -32,10 +32,6 @@ MANDIR ?= $(PREFIX)/share/man/man1
|
||||||
|
|
||||||
DESTDIR ?=
|
DESTDIR ?=
|
||||||
|
|
||||||
CHIBI ?= chibi-scheme$(EXE)
|
|
||||||
CHIBI_FFI ?= chibi-ffi
|
|
||||||
CHIBI_DOC ?= chibi-doc
|
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
# System configuration - if not using GNU make, set PLATFORM and the
|
# System configuration - if not using GNU make, set PLATFORM and the
|
||||||
# flags from Makefile.detect (at least SO, EXE, CLIBFLAGS) as necessary.
|
# flags from Makefile.detect (at least SO, EXE, CLIBFLAGS) as necessary.
|
||||||
|
|
8
README
8
README
|
@ -11,13 +11,7 @@ and scripting language in C programs. In addition to support for
|
||||||
lightweight VM-based threads, each VM itself runs in an isolated heap
|
lightweight VM-based threads, each VM itself runs in an isolated heap
|
||||||
allowing multiple VMs to run simultaneously in different OS threads.
|
allowing multiple VMs to run simultaneously in different OS threads.
|
||||||
|
|
||||||
The default language is based on an extended subset of the current
|
The default language is the R7RS (scheme base) library.
|
||||||
draft R7RS Scheme, with support for all libraries. To get a pure R7RS
|
|
||||||
repl you can run
|
|
||||||
|
|
||||||
chibi-scheme -xscheme.base
|
|
||||||
|
|
||||||
or see the (chibi repl) library for more options.
|
|
||||||
|
|
||||||
Support for additional languages such as JavaScript, Go, Lua and Bash
|
Support for additional languages such as JavaScript, Go, Lua and Bash
|
||||||
are planned for future releases. Scheme is chosen as a substrate
|
are planned for future releases. Scheme is chosen as a substrate
|
||||||
|
|
|
@ -6,7 +6,7 @@ chibi-scheme \- a tiny Scheme interpreter
|
||||||
|
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B chibi-scheme
|
.B chibi-scheme
|
||||||
[-qrfV]
|
[-qQrfV]
|
||||||
[-I
|
[-I
|
||||||
.I path
|
.I path
|
||||||
]
|
]
|
||||||
|
@ -72,9 +72,13 @@ management and smarter read/write you may want to use the (chibi repl)
|
||||||
module. For example,
|
module. For example,
|
||||||
.I chibi-scheme -mchibi.repl -e'(repl)'
|
.I chibi-scheme -mchibi.repl -e'(repl)'
|
||||||
|
|
||||||
The default language is an extended subset of the draft R7RS
|
The default language the R7RS
|
||||||
(scheme base) module. To get exactly the base module, use
|
(scheme base) module. To get a mostly R5RS-compatible language, use
|
||||||
.I chibi-scheme -xscheme.base
|
.I chibi-scheme -xscheme.r5rs
|
||||||
|
or to get just the core language used for bootstrapping, use
|
||||||
|
.I chibi-scheme -xchibi
|
||||||
|
or its shortcut
|
||||||
|
.I chibi-scheme -q
|
||||||
|
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
|
|
||||||
|
@ -86,9 +90,18 @@ Options without arguments may not be chained together.
|
||||||
Prints the version information and exits.
|
Prints the version information and exits.
|
||||||
.TP
|
.TP
|
||||||
.BI -q
|
.BI -q
|
||||||
Don't load the initialization file. The resulting
|
"Quick" load, shortcut for
|
||||||
environment will only contain the core syntactic forms
|
.I chibi-scheme -xchibi
|
||||||
and primitives coded in C.
|
This is a slightly different language from (scheme base),
|
||||||
|
which may load faster, and is guaranteed not to load any
|
||||||
|
additional shared libraries.
|
||||||
|
.TP
|
||||||
|
.BI -Q
|
||||||
|
Extra "quick" load, shortcut for
|
||||||
|
.I chibi-scheme -xchibi.primitive
|
||||||
|
The resulting environment will only contain the core syntactic
|
||||||
|
forms and primitives coded in C. This is very fast and guaranteed
|
||||||
|
not to load any external files, but is also very limited.
|
||||||
.TP
|
.TP
|
||||||
.BI -r
|
.BI -r
|
||||||
Run the "main" procedure when the script finishes loading as in SRFI-22.
|
Run the "main" procedure when the script finishes loading as in SRFI-22.
|
||||||
|
|
|
@ -13,8 +13,8 @@ and scripting language in C programs. In addition to support for
|
||||||
lightweight VM-based threads, each VM itself runs in an isolated heap
|
lightweight VM-based threads, each VM itself runs in an isolated heap
|
||||||
allowing multiple VMs to run simultaneously in different OS threads.
|
allowing multiple VMs to run simultaneously in different OS threads.
|
||||||
|
|
||||||
The default language is an extended subset of the current draft R7RS
|
The default language is the R7RS (scheme base) library, with support
|
||||||
Scheme, with support for all libraries. Support for additional
|
for all libraries from the small language. Support for additional
|
||||||
languages such as JavaScript, Go, Lua and Bash are planned for future
|
languages such as JavaScript, Go, Lua and Bash are planned for future
|
||||||
releases. Scheme is chosen as a substrate because its first class
|
releases. Scheme is chosen as a substrate because its first class
|
||||||
continuations and guaranteed tail-call optimization makes implementing
|
continuations and guaranteed tail-call optimization makes implementing
|
||||||
|
@ -122,24 +122,15 @@ C libraries, described in the FFI section below.
|
||||||
|
|
||||||
\subsection{Scheme Standard}
|
\subsection{Scheme Standard}
|
||||||
|
|
||||||
The default language is based on the latest draft of
|
The default language is the \scheme{(scheme base)} library from
|
||||||
\hyperlink["http://scheme-reports.org/"]{R7RS}, which is mostly a
|
\hyperlink["http://scheme-reports.org/"]{R7RS}, which is mostly a
|
||||||
superset of
|
superset of
|
||||||
\hyperlink["http://www.schemers.org/Documents/Standards/R5RS/HTML/"]{R5RS}.
|
\hyperlink["http://www.schemers.org/Documents/Standards/R5RS/HTML/"]{R5RS}.
|
||||||
Some of the more expensive bindings are not included in the interest
|
|
||||||
of size and quick startup, and some extra low-level utilities are
|
|
||||||
included for convenience and bootstrapping. Note the builtin
|
|
||||||
\scheme{equal?} does not support cyclic structures (you need the R7RS
|
|
||||||
\scheme{(scheme base)} or \scheme{(chibi equiv)}), nor do the default
|
|
||||||
reader and writer (you need \scheme{(srfi 38)} or the R7RS
|
|
||||||
\scheme{(scheme read)} and \scheme{(scheme write)}).
|
|
||||||
|
|
||||||
To get the exact R7RS language, you can \scheme{(import (scheme base))},
|
|
||||||
and likewise for the other R7RS libraries.
|
|
||||||
|
|
||||||
The reader defaults to case-sensitive, like R6RS and R7RS but unlike
|
The reader defaults to case-sensitive, like R6RS and R7RS but unlike
|
||||||
R5RS. The default configuration includes the full numeric tower:
|
R5RS. The default configuration includes the full numeric tower:
|
||||||
fixnums, flonums, bignums, exact rationals and complex numbers.
|
fixnums, flonums, bignums, exact rationals and complex numbers, though
|
||||||
|
this can be customized at compile time.
|
||||||
|
|
||||||
Full continuations are supported, but currently continuations don't
|
Full continuations are supported, but currently continuations don't
|
||||||
take C code into account. This means that you can call from Scheme to
|
take C code into account. This means that you can call from Scheme to
|
||||||
|
@ -171,16 +162,6 @@ automatically called with the following signature:
|
||||||
const char* version, sexp_abi_identifier_t abi);
|
const char* version, sexp_abi_identifier_t abi);
|
||||||
}
|
}
|
||||||
|
|
||||||
The following additional procedures are available in the default
|
|
||||||
environment:
|
|
||||||
|
|
||||||
\itemlist[
|
|
||||||
\item{\scheme{(print-exception exn out)} - prints a human-readable description of \var{exn} to the output port \var{out}}
|
|
||||||
\item{\scheme{(port-fold-case? port)} - returns \scheme{#t} iff the given input port folds case on \scheme{read}}
|
|
||||||
\item{\scheme{(set-port-fold-case! port bool)} - set the case-folding behavior of \var{port}}
|
|
||||||
\item{\scheme{(string-concatenate list-of-strings [sep])} - append the strings joined by \var{sep}}
|
|
||||||
]
|
|
||||||
|
|
||||||
\subsection{Module System}
|
\subsection{Module System}
|
||||||
|
|
||||||
Chibi uses the R7RS module system natively, which is a simple static
|
Chibi uses the R7RS module system natively, which is a simple static
|
||||||
|
|
37
main.c
37
main.c
|
@ -10,6 +10,7 @@
|
||||||
#define sexp_import_suffix "))"
|
#define sexp_import_suffix "))"
|
||||||
#define sexp_environment_prefix "(environment '("
|
#define sexp_environment_prefix "(environment '("
|
||||||
#define sexp_environment_suffix "))"
|
#define sexp_environment_suffix "))"
|
||||||
|
#define sexp_default_environment "(environment '(scheme base))"
|
||||||
|
|
||||||
#define sexp_version_string "chibi-scheme "sexp_version" \""sexp_release_name"\" "
|
#define sexp_version_string "chibi-scheme "sexp_version" \""sexp_release_name"\" "
|
||||||
|
|
||||||
|
@ -27,7 +28,8 @@ void sexp_usage(int err) {
|
||||||
#if SEXP_USE_FOLD_CASE_SYMS
|
#if SEXP_USE_FOLD_CASE_SYMS
|
||||||
" -f - case-fold symbols\n"
|
" -f - case-fold symbols\n"
|
||||||
#endif
|
#endif
|
||||||
" -q - don't load the initialization file\n"
|
" -q - \"quick\" load, use the core -xchibi language\n"
|
||||||
|
" -Q - extra \"quick\" load, -xchibi.primitive\n"
|
||||||
" -V - print version information\n"
|
" -V - print version information\n"
|
||||||
#if ! SEXP_USE_BOEHM
|
#if ! SEXP_USE_BOEHM
|
||||||
" -h <size> - specify the initial heap size\n"
|
" -h <size> - specify the initial heap size\n"
|
||||||
|
@ -198,7 +200,7 @@ static sexp sexp_load_standard_params (sexp ctx, sexp e) {
|
||||||
#endif
|
#endif
|
||||||
res = sexp_make_env(ctx);
|
res = sexp_make_env(ctx);
|
||||||
sexp_env_parent(res) = e;
|
sexp_env_parent(res) = e;
|
||||||
sexp_set_parameter(ctx, res, sexp_global(ctx, SEXP_G_INTERACTION_ENV_SYMBOL), res);
|
sexp_set_parameter(ctx, sexp_global(ctx, SEXP_G_META_ENV), sexp_global(ctx, SEXP_G_INTERACTION_ENV_SYMBOL), res);
|
||||||
sexp_gc_release3(ctx);
|
sexp_gc_release3(ctx);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -277,11 +279,17 @@ static sexp check_exception (sexp ctx, sexp res) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static sexp sexp_load_standard_repl_env (sexp ctx, sexp env, sexp k) {
|
static sexp sexp_load_standard_repl_env (sexp ctx, sexp env, sexp k, int bootp) {
|
||||||
sexp_gc_var1(e);
|
sexp_gc_var1(e);
|
||||||
sexp_gc_preserve1(ctx, e);
|
sexp_gc_preserve1(ctx, e);
|
||||||
e = sexp_load_standard_env(ctx, env, k);
|
e = sexp_load_standard_env(ctx, env, k);
|
||||||
if (sexp_exceptionp(e)) return e;
|
if (sexp_exceptionp(e)) return e;
|
||||||
|
#if SEXP_USE_MODULES
|
||||||
|
if (!bootp) {
|
||||||
|
e = sexp_eval_string(ctx, sexp_default_environment, -1, sexp_global(ctx, SEXP_G_META_ENV));
|
||||||
|
if (sexp_exceptionp(e)) return e;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
e = sexp_load_standard_params(ctx, e);
|
e = sexp_load_standard_params(ctx, e);
|
||||||
sexp_gc_release1(ctx);
|
sexp_gc_release1(ctx);
|
||||||
return e;
|
return e;
|
||||||
|
@ -305,9 +313,9 @@ static void do_init_context (sexp* ctx, sexp* env, sexp_uint_t heap_size,
|
||||||
sexp_gc_preserve3(ctx, tmp, sym, args); \
|
sexp_gc_preserve3(ctx, tmp, sym, args); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define load_init() if (! init_loaded++) do { \
|
#define load_init(bootp) if (! init_loaded++) do { \
|
||||||
init_context(); \
|
init_context(); \
|
||||||
check_exception(ctx, env=sexp_load_standard_repl_env(ctx, env, SEXP_SEVEN)); \
|
check_exception(ctx, env=sexp_load_standard_repl_env(ctx, env, SEXP_SEVEN, bootp)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
void run_main (int argc, char **argv) {
|
void run_main (int argc, char **argv) {
|
||||||
|
@ -329,7 +337,7 @@ void run_main (int argc, char **argv) {
|
||||||
case 'e':
|
case 'e':
|
||||||
case 'p':
|
case 'p':
|
||||||
mods_loaded = 1;
|
mods_loaded = 1;
|
||||||
load_init();
|
load_init(0);
|
||||||
print = (argv[i][1] == 'p');
|
print = (argv[i][1] == 'p');
|
||||||
arg = ((argv[i][2] == '\0') ? argv[++i] : argv[i]+2);
|
arg = ((argv[i][2] == '\0') ? argv[++i] : argv[i]+2);
|
||||||
check_nonull_arg('e', arg);
|
check_nonull_arg('e', arg);
|
||||||
|
@ -344,7 +352,7 @@ void run_main (int argc, char **argv) {
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
mods_loaded = 1;
|
mods_loaded = 1;
|
||||||
load_init();
|
load_init(0);
|
||||||
arg = ((argv[i][2] == '\0') ? argv[++i] : argv[i]+2);
|
arg = ((argv[i][2] == '\0') ? argv[++i] : argv[i]+2);
|
||||||
check_nonull_arg('l', arg);
|
check_nonull_arg('l', arg);
|
||||||
check_exception(ctx, sexp_load_module_file(ctx, arg, env));
|
check_exception(ctx, sexp_load_module_file(ctx, arg, env));
|
||||||
|
@ -358,7 +366,7 @@ void run_main (int argc, char **argv) {
|
||||||
goto load_primitive;
|
goto load_primitive;
|
||||||
if (c != 'x') {prefix = sexp_import_prefix; suffix = sexp_import_suffix;}
|
if (c != 'x') {prefix = sexp_import_prefix; suffix = sexp_import_suffix;}
|
||||||
mods_loaded = 1;
|
mods_loaded = 1;
|
||||||
load_init();
|
load_init(1);
|
||||||
#if SEXP_USE_MODULES
|
#if SEXP_USE_MODULES
|
||||||
check_nonull_arg(c, arg);
|
check_nonull_arg(c, arg);
|
||||||
len = strlen(arg)+strlen(prefix)+strlen(suffix);
|
len = strlen(arg)+strlen(prefix)+strlen(suffix);
|
||||||
|
@ -372,7 +380,7 @@ void run_main (int argc, char **argv) {
|
||||||
tmp = check_exception(ctx, sexp_eval_string(ctx, impmod, -1, (c=='x' ? sexp_global(ctx, SEXP_G_META_ENV) : env)));
|
tmp = check_exception(ctx, sexp_eval_string(ctx, impmod, -1, (c=='x' ? sexp_global(ctx, SEXP_G_META_ENV) : env)));
|
||||||
free(impmod);
|
free(impmod);
|
||||||
if (c == 'x') {
|
if (c == 'x') {
|
||||||
sexp_set_parameter(ctx, env, sexp_global(ctx, SEXP_G_INTERACTION_ENV_SYMBOL), tmp);
|
sexp_set_parameter(ctx, sexp_global(ctx, SEXP_G_META_ENV), sexp_global(ctx, SEXP_G_INTERACTION_ENV_SYMBOL), env);
|
||||||
sexp_context_env(ctx) = env = tmp;
|
sexp_context_env(ctx) = env = tmp;
|
||||||
tmp = sexp_param_ref(ctx, env, sexp_global(ctx, SEXP_G_CUR_OUT_SYMBOL));
|
tmp = sexp_param_ref(ctx, env, sexp_global(ctx, SEXP_G_CUR_OUT_SYMBOL));
|
||||||
if (tmp != NULL && !sexp_oportp(tmp))
|
if (tmp != NULL && !sexp_oportp(tmp))
|
||||||
|
@ -381,12 +389,15 @@ void run_main (int argc, char **argv) {
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
load_primitive:
|
load_primitive:
|
||||||
case 'q':
|
case 'Q':
|
||||||
init_context();
|
init_context();
|
||||||
mods_loaded = 1;
|
mods_loaded = 1;
|
||||||
if (! init_loaded++)
|
if (! init_loaded++)
|
||||||
sexp_load_standard_ports(ctx, env, stdin, stdout, stderr, 0);
|
sexp_load_standard_ports(ctx, env, stdin, stdout, stderr, 0);
|
||||||
break;
|
break;
|
||||||
|
case 'q':
|
||||||
|
argv[i--] = "-xchibi";
|
||||||
|
break;
|
||||||
case 'A':
|
case 'A':
|
||||||
init_context();
|
init_context();
|
||||||
arg = ((argv[i][2] == '\0') ? argv[++i] : argv[i]+2);
|
arg = ((argv[i][2] == '\0') ? argv[++i] : argv[i]+2);
|
||||||
|
@ -445,7 +456,7 @@ void run_main (int argc, char **argv) {
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 'V':
|
case 'V':
|
||||||
load_init();
|
load_init(0);
|
||||||
if (! sexp_oportp(out))
|
if (! sexp_oportp(out))
|
||||||
out = sexp_eval_string(ctx, "(current-output-port)", -1, env);
|
out = sexp_eval_string(ctx, "(current-output-port)", -1, env);
|
||||||
sexp_write_string(ctx, sexp_version_string, out);
|
sexp_write_string(ctx, sexp_version_string, out);
|
||||||
|
@ -476,7 +487,7 @@ void run_main (int argc, char **argv) {
|
||||||
|
|
||||||
done_options:
|
done_options:
|
||||||
if (!quit || main_symbol != NULL) {
|
if (!quit || main_symbol != NULL) {
|
||||||
load_init();
|
load_init(0);
|
||||||
/* build argument list */
|
/* build argument list */
|
||||||
if (i < argc)
|
if (i < argc)
|
||||||
for (j=argc-1; j>=i; j--)
|
for (j=argc-1; j>=i; j--)
|
||||||
|
@ -494,7 +505,7 @@ void run_main (int argc, char **argv) {
|
||||||
/* `cond-expand' bindings */
|
/* `cond-expand' bindings */
|
||||||
if (!mods_loaded) {
|
if (!mods_loaded) {
|
||||||
env = sexp_make_env(ctx);
|
env = sexp_make_env(ctx);
|
||||||
sexp_set_parameter(ctx, sexp_context_env(ctx),
|
sexp_set_parameter(ctx, sexp_global(ctx, SEXP_G_META_ENV),
|
||||||
sexp_global(ctx, SEXP_G_INTERACTION_ENV_SYMBOL), env);
|
sexp_global(ctx, SEXP_G_INTERACTION_ENV_SYMBOL), env);
|
||||||
sexp_context_env(ctx) = env;
|
sexp_context_env(ctx) = env;
|
||||||
sym = sexp_intern(ctx, "repl-import", -1);
|
sym = sexp_intern(ctx, "repl-import", -1);
|
||||||
|
|
|
@ -1730,7 +1730,7 @@
|
||||||
(cat "/* Automatically generated by chibi-ffi; version: "
|
(cat "/* Automatically generated by chibi-ffi; version: "
|
||||||
*ffi-version* " */\n")
|
*ffi-version* " */\n")
|
||||||
(c-system-include "chibi/eval.h")
|
(c-system-include "chibi/eval.h")
|
||||||
(load file)
|
(load file (current-environment))
|
||||||
(write-init))
|
(write-init))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
Loading…
Add table
Reference in a new issue