skint/README.md

98 lines
5 KiB
Markdown
Raw Normal View History

2024-07-26 08:54:27 +02:00
![](https://raw.githubusercontent.com/false-schemers/skint/master/misc/skint-252x100.png)
2024-07-26 05:20:45 +02:00
2024-07-26 09:07:44 +02:00
# Cheap and fast R7RS Scheme Interpreter
2024-07-23 08:41:59 +02:00
SKINT is a portable interpreter for the R7RS Scheme programming language.
2024-07-29 07:05:32 +02:00
It can be built from five C source files (10K lines of code) with a single command. There is no distributives or packages;
2024-07-29 02:50:57 +02:00
just compile the source files with your favorite C compiler, link them with the standard C runtime libraries,
and you're done. For some platforms, precompiled binaries are available (please see [releases](https://github.com/false-schemers/skint/releases)).
2024-07-23 08:41:59 +02:00
## Installation
Here's how you can compile SKINT on a unix box using GCC:
```
gcc -o skint [skint].c -lm
```
Some compilers link `<math.h>` library automatically, some require explicit option like `-lm` above. It can be built on 32-bit
2024-07-29 07:15:44 +02:00
and 64-bit systems.
2024-07-23 08:41:59 +02:00
2024-08-05 20:59:21 +02:00
For *much* better performance (especially in floating-point calculations) you may pick another compiler, add optimization flags
2024-08-05 20:49:54 +02:00
and some SKINT-specific options, e.g.:
2024-07-23 08:41:59 +02:00
```
2024-07-26 05:03:22 +02:00
clang -o skint -O3 -D NDEBUG -D NAN_BOXING [skint].c -lm
2024-07-23 08:41:59 +02:00
```
2024-07-29 02:50:57 +02:00
The NAN_BOXING option assumes that the upper 16 bits of heap pointers are zero (48-bit address space). It is recommended to use this
option on 64-bit systems that guarantee this.
2024-07-23 08:41:59 +02:00
2024-07-23 21:39:11 +02:00
The resulting interpreter has no dependencies (except for C runtime and standard -lm math library) and can be run from any location.
2024-07-26 05:03:22 +02:00
If linked statically, it can be easily moved between systems with the same ABI.
2024-07-23 08:41:59 +02:00
2024-07-29 02:50:57 +02:00
For a more traditional install, please follow the instructions below. Skint will be
2024-07-27 23:26:43 +02:00
installed as `/usr/local/bin/skint` command.
```
2024-08-05 20:59:21 +02:00
git clone https://github.com/false-schemers/skint.git
cd skint
make
make test
sudo make install
2024-07-27 23:26:43 +02:00
```
2024-07-23 08:41:59 +02:00
## Scheme Compatibility
2024-07-29 02:50:57 +02:00
SKINT is true to basic Scheme principles -- it features a precise garbage collector, supports proper tail recursion, `call/cc`,
`dynamic-wind`, multiple return values, has a hygienic macro system, and a library system. It is almost fully compatible
with R7RS-small, but has the following known limitations and deviations from the standard:
2024-07-23 08:41:59 +02:00
* fixnums are 30 bit long, flonums are doubles
* no support for bignums/rational/complex numbers
* no support for Unicode; strings are 8-bit clean, use system locale
* source code literals cannot be circular (R7RS allows this)
Some features of the R7RS-Small standard are not yet implemented or implemented in a simplified or non-conforming way:
* `read` procedure is always case-sensitive (all ports operate in no-fold-case mode)
* `#!fold-case` and `#!no-fold-case` directives have no effect
* `include` and `include-ci` forms work in case-sensitive mode
* `current-jiffy` and `jiffies-per-second` return inexact integers
* `current-second` is defined as C `difftime(time(0), 0)+37`
Here are some details on SKINT's interactive Read-Eval-Print-Loop (REPL) and evaluation/libraries support:
* `read` supports R7RS notation for circular structures, but both `eval` and `load` reject them
2024-07-26 05:03:22 +02:00
* all R7RS-small forms are available in the built-in `(skint)` library and REPL environment
2024-07-23 08:41:59 +02:00
* `-I` and `-A` command-line options extend library search path; initial path is `./`
* `cond-expand` checks against `(features)` and available libraries
2024-07-26 05:03:22 +02:00
* `environment` may dynamically fetch external library definitions from `.sld` files
2024-07-23 08:41:59 +02:00
* both `eval` and `load` accept optional environment argument
* command-line options can be shown by running `skint --help`
* both `import` and `define-library` forms can be entered interactively into REPL
2024-07-26 05:03:22 +02:00
* REPL supports single-line “comma-commands” — type `,help` for a full list
2024-07-23 09:22:53 +02:00
* on Un*x-like systems, interactive use of skint with line exiting requires external readline wrapper
such as [rlwrap](https://github.com/hanslub42/rlwrap)
2024-07-23 08:41:59 +02:00
2024-07-26 05:03:22 +02:00
Please note that SKINT's interaction environment exposes bindings for all R7RS-small procedures
2024-07-23 08:41:59 +02:00
and syntax forms directly, so there is no need to use `import`. All R7RS-small libraries are built-in and
do not rely on any external .sld files.
## Origins
Parts of SKINT's run-time system and startup code are written in [#F](https://github.com/false-schemers/sharpF),
a language for building Scheme-like systems. Its #F source code can be found there in `precursors` directory:
2024-07-23 09:05:24 +02:00
[skint/pre](https://github.com/false-schemers/skint/tree/main/pre)
2024-07-23 08:41:59 +02:00
2024-07-26 05:03:22 +02:00
SKINT's hygienic macroexpander is derived from Al Petrofsky's EIOD 1.17 (please see the t.scm file for the original copyright info).
SKINT's VM and compiler follow the stack machine approach described in “Three Implementation Models for Scheme” thesis by R. Kent Dybvig
2024-07-23 08:41:59 +02:00
([TR87-011](https://www.cs.unc.edu/techreports/87-011.pdf), 1987).
Supporting library code comes from #F's [LibL library](https://raw.githubusercontent.com/false-schemers/sharpF/master/lib/libl.sf).
## Family
Please see [SIOF](https://github.com/false-schemers/siof) repository for a single-file R7RS-small interpreter. It is
2024-07-26 05:03:22 +02:00
more portable and easier to build, but is less complete and runs significantly slower.