Official chibi-scheme repository
Find a file
Alexei Lozovsky 6f35aa75f4
Fix usage of signbit() in SRFI 144
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.
2021-06-06 13:49:44 +09:00
.githooks fixing pre-commit hook when no c or scheme files are changed 2020-07-29 10:29:24 +09:00
.github/workflows CI: Add Github Actions 2020-05-28 03:14:50 +09:00
benchmarks report diff on gc times 2020-05-11 10:28:00 +09:00
build-lib/chibi/char-set adding missing files 2020-06-03 11:33:15 +09:00
contrib cmake: Add CMakeLists.txt 2017-11-18 16:28:31 +09:00
data Adding a gitignore for the temp data dir. 2015-04-09 01:30:06 +09:00
doc use SEXP_USE_STATIC_LIBS_NO_INCLUDE for static build 2021-05-24 22:42:21 +01:00
examples Forgot to install regexp (patch from Lorenzo) 2015-01-26 08:06:59 +09:00
include/chibi remove superfluous + when printing complex numbers with negative ratio imaginary parts 2021-05-26 10:05:40 +09:00
js js/exported_functions.json: make it proper json 2018-11-25 19:10:35 +01:00
lib Fix usage of signbit() in SRFI 144 2021-06-06 13:49:44 +09:00
opt making string-cursors a disjoint type 2016-03-29 22:25:09 +09:00
tests Initialize variables in FFI tests 2021-06-06 11:19:52 +09:00
tools Fix upper bounds checks in u64vectors. 2021-04-30 14:02:29 +09:00
.gitignore replace define-library-alias with define-library + alias-for 2020-06-04 23:55:37 +09:00
.hgignore Emscripten support by default. Patch from Marc Nieper-Wi?kirchen. 2015-02-22 16:10:30 +09:00
.travis.yml wrong filename 2016-06-24 22:51:36 +09:00
appveyor.yml AppVeyor: Add MSVC x64 configuration to CI 2018-06-20 21:22:36 +09:00
AUTHORS attributing lgamma_r 2020-07-31 15:24:24 +09:00
bignum.c fixing scheme bytevector for 32bit arch 2020-07-28 15:09:40 +09:00
chibi-scheme.pc.in Forgot to install regexp (patch from Lorenzo) 2015-01-26 08:06:59 +09:00
CMakeLists.txt (chibi pty): Disable in CMake build 2019-08-24 07:08:47 +09:00
configure adding informational configure script 2016-06-24 22:55:08 +09:00
COPYING adding (srfi 101) 2018-01-15 23:51:16 +09:00
eval.c put system module path in front of user module path 2021-05-10 23:24:18 +09:00
fedora.spec Forgot to install regexp (patch from Lorenzo) 2015-01-26 08:06:59 +09:00
gc.c avoid gc recursion on non-pointers 2020-05-25 18:50:47 +09:00
gc_heap.c pass '() as user exception irritants, not NULL 2020-07-30 18:11:57 +09:00
main.c chibi-scheme.1: document -b 2021-05-04 18:06:06 +07:00
Makefile installing SRFI 179 2021-05-11 00:06:24 +09:00
Makefile.detect Produce a versioned so on FreeBSD 2020-10-16 13:10:58 +00:00
Makefile.libs allow either prefix or PREFIX 2020-08-28 09:58:08 +09:00
mkfile make 9front "work" again by properly handling 64-bit typedefs 2021-02-20 17:10:43 -07:00
opcodes.c move remaining fields to start of types 2020-07-30 00:19:21 +09:00
plan9.c Updating copyright years. 2015-04-09 01:28:02 +09:00
README-win32.md doc: Update README-win32.md to reflect recent changes 2018-06-20 21:22:36 +09:00
README.libs Forgot to install regexp (patch from Lorenzo) 2015-01-26 08:06:59 +09:00
README.md emphasize not to use emmake directly 2021-05-12 08:28:55 +09:00
RELEASE bumping version 2021-05-10 23:30:26 +09:00
sexp.c Fix upper bounds checks in u64vectors. 2021-04-30 14:02:29 +09:00
simplify.c Updating copyright years. 2015-04-09 01:28:02 +09:00
TODO updating note about thread status in TODO 2018-04-03 07:53:36 +09:00
VERSION bumping version 2021-05-10 23:30:26 +09:00
vm.c typo for non-threads build (issue #731) 2021-05-05 21:14:22 +09:00

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.

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.