C standard defines signbit() as a macro returning "non-zero value" for negative arguments (see 7.12.3.6 of C11 standard). SRFI 144's flsign-bit is defined to return exactly 1. Make sure to convert the result of signbit() call into "boolean int" which is either 0 or 1. This is not a theoretical issue. This causes SRFI 144 test suite to fail on many architectures that are not x86_64. GCC on x86_64 compiles signbit() as movmskpd %xmm0, %eax andl $1, %eax which indeed returns either 0 or 1. movmskpd extracts 2-bit sign mask from the FP value in src register and stores that in low-order bits of the dst register. Then the unneded extra bit is masked out, leaving only the lowest bit set or unset. However, other architectures don't have such conveniences and go with more direct approach. For example, GCC on ARMv7 produces this: sub sp, sp, #8 vstr.64 d0, [sp] ldr r0, [sp, #4] and r0, r0, #0x80000000 add sp, sp, #8 bx lr which effectively returns either 0 or -1. Generated code masks out everything but the sign bit and returns the result as is. The value 0x80000000 is the representation of -1. Even on i386 signbit() is compiled as fldl 4(%esp) fxam fnstsw %ax fstp %st(0) andl $512, %eax ret which effectively returns either 0 or 512: fxam sets C1 bit FPU status word to the sign of FP value, then the status word is extracted, the "sign bit" is masked out, and left as is. |
||
---|---|---|
.githooks | ||
.github/workflows | ||
benchmarks | ||
build-lib/chibi/char-set | ||
contrib | ||
data | ||
doc | ||
examples | ||
include/chibi | ||
js | ||
lib | ||
opt | ||
tests | ||
tools | ||
.gitignore | ||
.hgignore | ||
.travis.yml | ||
appveyor.yml | ||
AUTHORS | ||
bignum.c | ||
chibi-scheme.pc.in | ||
CMakeLists.txt | ||
configure | ||
COPYING | ||
eval.c | ||
fedora.spec | ||
gc.c | ||
gc_heap.c | ||
main.c | ||
Makefile | ||
Makefile.detect | ||
Makefile.libs | ||
mkfile | ||
opcodes.c | ||
plan9.c | ||
README-win32.md | ||
README.libs | ||
README.md | ||
RELEASE | ||
sexp.c | ||
simplify.c | ||
TODO | ||
VERSION | ||
vm.c |
Minimal Scheme Implementation for use as an Extension Language
http://synthcode.com/wiki/chibi-scheme
Chibi-Scheme is a very small library intended for use as an extension 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.
There are no external dependencies so is relatively easy to drop into any project.
Despite the small size, Chibi-Scheme attempts to do The Right Thing. The default settings include:
- a full numeric tower, with rational and complex numbers
- full and seamless Unicode support
- low-level and high-level hygienic macros
- an extensible module system
Specifically, the default repl language contains all bindings from
R7RS small, available explicitly as the
(scheme small)
library. The language is built in layers, however -
see the manual for instructions on compiling with fewer features or
requesting a smaller language on startup.
Chibi-Scheme is known to work on 32 and 64-bit Linux, FreeBSD, NetBSD, OpenBSD and OS X, Plan 9, Windows, iOS, Android, ARM and Emscripten. Basic support for native Windows desktop also exists. See README-win32.md for details and build instructions.
To build on most platforms just run make && make test
. This has a
few conditionals assuming GNU make. If using another make, there are
a few parameters in Makefile.detect you need to set by hand.
This will provide a shared library libchibi-scheme, as well as a sample chibi-scheme command-line repl. You can then run
sudo make install
to install the binaries and libraries. You can optionally specify a PREFIX for the installation directory:
make PREFIX=/path/to/install/
sudo make PREFIX=/path/to/install/ install
By default files are installed in /usr/local.
If you want to try out chibi-scheme without installing, be sure to set
LD_LIBRARY_PATH
so it can find the shared libraries.
To make the emscripten build run make js
(not emmake make js
).
For more detailed documentation, run make doc
and see the generated
doc/chibi.html.