mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-21 06:39:17 +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
|
||||
.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_DOC ?= $(CHIBI) tools/chibi-doc
|
||||
|
|
|
@ -32,10 +32,6 @@ MANDIR ?= $(PREFIX)/share/man/man1
|
|||
|
||||
DESTDIR ?=
|
||||
|
||||
CHIBI ?= chibi-scheme$(EXE)
|
||||
CHIBI_FFI ?= chibi-ffi
|
||||
CHIBI_DOC ?= chibi-doc
|
||||
|
||||
########################################################################
|
||||
# System configuration - if not using GNU make, set PLATFORM and the
|
||||
# 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
|
||||
allowing multiple VMs to run simultaneously in different OS threads.
|
||||
|
||||
The default language is based on an extended subset of the current
|
||||
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.
|
||||
The default language is the R7RS (scheme base) library.
|
||||
|
||||
Support for additional languages such as JavaScript, Go, Lua and Bash
|
||||
are planned for future releases. Scheme is chosen as a substrate
|
||||
|
|
|
@ -6,7 +6,7 @@ chibi-scheme \- a tiny Scheme interpreter
|
|||
|
||||
.SH SYNOPSIS
|
||||
.B chibi-scheme
|
||||
[-qrfV]
|
||||
[-qQrfV]
|
||||
[-I
|
||||
.I path
|
||||
]
|
||||
|
@ -72,9 +72,13 @@ management and smarter read/write you may want to use the (chibi repl)
|
|||
module. For example,
|
||||
.I chibi-scheme -mchibi.repl -e'(repl)'
|
||||
|
||||
The default language is an extended subset of the draft R7RS
|
||||
(scheme base) module. To get exactly the base module, use
|
||||
.I chibi-scheme -xscheme.base
|
||||
The default language the R7RS
|
||||
(scheme base) module. To get a mostly R5RS-compatible language, use
|
||||
.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
|
||||
|
||||
|
@ -86,9 +90,18 @@ Options without arguments may not be chained together.
|
|||
Prints the version information and exits.
|
||||
.TP
|
||||
.BI -q
|
||||
Don't load the initialization file. The resulting
|
||||
environment will only contain the core syntactic forms
|
||||
and primitives coded in C.
|
||||
"Quick" load, shortcut for
|
||||
.I chibi-scheme -xchibi
|
||||
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
|
||||
.BI -r
|
||||
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
|
||||
allowing multiple VMs to run simultaneously in different OS threads.
|
||||
|
||||
The default language is an extended subset of the current draft R7RS
|
||||
Scheme, with support for all libraries. Support for additional
|
||||
The default language is the R7RS (scheme base) library, with support
|
||||
for all libraries from the small language. Support for additional
|
||||
languages such as JavaScript, Go, Lua and Bash are planned for future
|
||||
releases. Scheme is chosen as a substrate because its first class
|
||||
continuations and guaranteed tail-call optimization makes implementing
|
||||
|
@ -122,24 +122,15 @@ C libraries, described in the FFI section below.
|
|||
|
||||
\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
|
||||
superset of
|
||||
\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
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
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}
|
||||
|
||||
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_environment_prefix "(environment '("
|
||||
#define sexp_environment_suffix "))"
|
||||
#define sexp_default_environment "(environment '(scheme base))"
|
||||
|
||||
#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
|
||||
" -f - case-fold symbols\n"
|
||||
#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"
|
||||
#if ! SEXP_USE_BOEHM
|
||||
" -h <size> - specify the initial heap size\n"
|
||||
|
@ -198,7 +200,7 @@ static sexp sexp_load_standard_params (sexp ctx, sexp e) {
|
|||
#endif
|
||||
res = sexp_make_env(ctx);
|
||||
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);
|
||||
return res;
|
||||
}
|
||||
|
@ -277,11 +279,17 @@ static sexp check_exception (sexp ctx, sexp 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_preserve1(ctx, e);
|
||||
e = sexp_load_standard_env(ctx, env, k);
|
||||
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);
|
||||
sexp_gc_release1(ctx);
|
||||
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); \
|
||||
} while (0)
|
||||
|
||||
#define load_init() if (! init_loaded++) do { \
|
||||
#define load_init(bootp) if (! init_loaded++) do { \
|
||||
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)
|
||||
|
||||
void run_main (int argc, char **argv) {
|
||||
|
@ -329,7 +337,7 @@ void run_main (int argc, char **argv) {
|
|||
case 'e':
|
||||
case 'p':
|
||||
mods_loaded = 1;
|
||||
load_init();
|
||||
load_init(0);
|
||||
print = (argv[i][1] == 'p');
|
||||
arg = ((argv[i][2] == '\0') ? argv[++i] : argv[i]+2);
|
||||
check_nonull_arg('e', arg);
|
||||
|
@ -344,7 +352,7 @@ void run_main (int argc, char **argv) {
|
|||
break;
|
||||
case 'l':
|
||||
mods_loaded = 1;
|
||||
load_init();
|
||||
load_init(0);
|
||||
arg = ((argv[i][2] == '\0') ? argv[++i] : argv[i]+2);
|
||||
check_nonull_arg('l', arg);
|
||||
check_exception(ctx, sexp_load_module_file(ctx, arg, env));
|
||||
|
@ -358,7 +366,7 @@ void run_main (int argc, char **argv) {
|
|||
goto load_primitive;
|
||||
if (c != 'x') {prefix = sexp_import_prefix; suffix = sexp_import_suffix;}
|
||||
mods_loaded = 1;
|
||||
load_init();
|
||||
load_init(1);
|
||||
#if SEXP_USE_MODULES
|
||||
check_nonull_arg(c, arg);
|
||||
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)));
|
||||
free(impmod);
|
||||
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;
|
||||
tmp = sexp_param_ref(ctx, env, sexp_global(ctx, SEXP_G_CUR_OUT_SYMBOL));
|
||||
if (tmp != NULL && !sexp_oportp(tmp))
|
||||
|
@ -381,12 +389,15 @@ void run_main (int argc, char **argv) {
|
|||
#endif
|
||||
break;
|
||||
load_primitive:
|
||||
case 'q':
|
||||
case 'Q':
|
||||
init_context();
|
||||
mods_loaded = 1;
|
||||
if (! init_loaded++)
|
||||
sexp_load_standard_ports(ctx, env, stdin, stdout, stderr, 0);
|
||||
break;
|
||||
case 'q':
|
||||
argv[i--] = "-xchibi";
|
||||
break;
|
||||
case 'A':
|
||||
init_context();
|
||||
arg = ((argv[i][2] == '\0') ? argv[++i] : argv[i]+2);
|
||||
|
@ -445,7 +456,7 @@ void run_main (int argc, char **argv) {
|
|||
break;
|
||||
#endif
|
||||
case 'V':
|
||||
load_init();
|
||||
load_init(0);
|
||||
if (! sexp_oportp(out))
|
||||
out = sexp_eval_string(ctx, "(current-output-port)", -1, env);
|
||||
sexp_write_string(ctx, sexp_version_string, out);
|
||||
|
@ -476,7 +487,7 @@ void run_main (int argc, char **argv) {
|
|||
|
||||
done_options:
|
||||
if (!quit || main_symbol != NULL) {
|
||||
load_init();
|
||||
load_init(0);
|
||||
/* build argument list */
|
||||
if (i < argc)
|
||||
for (j=argc-1; j>=i; j--)
|
||||
|
@ -494,7 +505,7 @@ void run_main (int argc, char **argv) {
|
|||
/* `cond-expand' bindings */
|
||||
if (!mods_loaded) {
|
||||
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_context_env(ctx) = env;
|
||||
sym = sexp_intern(ctx, "repl-import", -1);
|
||||
|
|
|
@ -1730,7 +1730,7 @@
|
|||
(cat "/* Automatically generated by chibi-ffi; version: "
|
||||
*ffi-version* " */\n")
|
||||
(c-system-include "chibi/eval.h")
|
||||
(load file)
|
||||
(load file (current-environment))
|
||||
(write-init))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
|
Loading…
Add table
Reference in a new issue