mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 05:39:18 +02:00
Official chibi-scheme repository
Naturally, fixed-width integer arithmetics can overflow. Chibi handles it pretty well in general, but one case was missing: it is negation of the minimal negative number that can be represented as a fixnum. That is, sexp_fx_neg() must not be applied to sexp_make_fixnum(SEXP_MIN_FIXNUM) because it overflows and returns an identical fixnum back. sexp_fx_neg() itself seems to be used right in the current code, but sexp_fx_abs()--which is defined in terms of sexp_fx_neg()--could be applied to the forbidden number when used to retrieve an unboxed value via the sexp_unbox_fixnum(sexp_fx_abs(x)) pattern. So I have added a separate macro that safely calculates unboxed absolute value of a fixnum, and replaced sexp_unbox_fixnum(sexp_fx_abs(x)) usages with it. Current implementation uses two-bit tag for fixnums, plus we need one bit for the sign, so fixnums have (machine word - 3) significant bits. Regression tests cover word sizes of 16, 32, 64, and 128 bits (for the sake of past- and future-proofness). sexp_bignum_expt() does not have a regression test because we need to check it with negative exponents like -2^29, so the base must be over at least 2^(2^29) for the differences to be visible. Fun fact: bignum representation of such number takes around 1/32 of the available user- space memory, which makes testing on anything except 32-bit systems unreasonable (4 TB of RAM anyone?) |
||
---|---|---|
benchmarks | ||
build-lib/chibi/char-set | ||
contrib | ||
data | ||
doc | ||
examples | ||
include/chibi | ||
lib | ||
opt | ||
tests | ||
tools | ||
.gitignore | ||
.gitmodules | ||
.hgignore | ||
AUTHORS | ||
bignum.c | ||
chibi-scheme.pc.in | ||
chibi-scheme.vcproj | ||
COPYING | ||
eval.c | ||
fedora.spec | ||
gc.c | ||
main.c | ||
Makefile | ||
Makefile.detect | ||
Makefile.libs | ||
mkfile | ||
opcodes.c | ||
plan9.c | ||
README | ||
README.libs | ||
RELEASE | ||
sexp.c | ||
simplify.c | ||
TODO | ||
VERSION | ||
vm.c |
Chibi-Scheme -------------- 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. 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 because its first class continuations and guaranteed tail-call optimization makes implementing other languages easy. To build on most platforms just run "make && make test". 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. For more detailed documentation, run "make doc" and see the generated "doc/chibi.html".