Go to file
retropikzel 1e75b8ecf4 Making the build work 2025-04-18 08:40:36 +03:00
libs Added support for many more implementations. Moved much more towards SRFI-138 conformity. 2025-04-18 05:53:48 +03:00
snow Added support for many more implementations. Moved much more towards SRFI-138 conformity. 2025-04-18 05:53:48 +03:00
.gitignore Added support for many more implementations. Moved much more towards SRFI-138 conformity. 2025-04-18 05:53:48 +03:00
Dockerfile Added support for many more implementations. Moved much more towards SRFI-138 conformity. 2025-04-18 05:53:48 +03:00
Dockerfile.jenkins Making the build work 2025-04-18 07:54:36 +03:00
Jenkinsfile Making the build work 2025-04-18 08:40:36 +03:00
LICENSE Added license 2025-01-13 17:20:58 +02:00
Makefile Added support for many more implementations. Moved much more towards SRFI-138 conformity. 2025-04-18 05:53:48 +03:00
README.md Updated readme 2025-04-18 07:50:10 +03:00
compile-r7rs.bat Added support for many more implementations. Moved much more towards SRFI-138 conformity. 2025-04-18 05:53:48 +03:00
compile-r7rs.scm Added support for many more implementations. Moved much more towards SRFI-138 conformity. 2025-04-18 05:53:48 +03:00
configure Made this 2024-12-23 22:01:08 +02:00
installer.iss Added support for many more implementations. Moved much more towards SRFI-138 conformity. 2025-04-18 05:53:48 +03:00

README.md

compile-r7rs is a tool to compile Scheme programs, it aims for compability with SRFI-138.

Despite it's name it also supports R6RS. Schemers, unite! <3

Project

Mailing lists

Issue tracker

Jenkins

Notes

  • No support for -D flag yet.
  • Not all implementations support adding to beginning or end o load path so -I and -A might work the same

Supported implementations

Some implementations support both compiling and interpreting, in that case only the compiler functionality is used and the implementation is marked as compiler.

  • chezscheme
    • interpreter
    • r6rs
  • chibi
    • interpreter
    • r7rs
  • chicken
    • compiler
    • r7rs
  • cyclone
    • compiler
    • r7rs
  • gambit
    • compiler
    • r7rs
  • foment
    • interpreter
    • r7rs
  • gauche
    • interpreter
    • r7rs
  • guile
  • ikarus
    • interpreter
    • r6rs
  • ironscheme
    • interpreter
    • r6rs
  • kawa
    • interpreter
    • r7rs
  • larceny
    • interpreter
    • r6rs
    • r7rs
  • loko
    • compiler
    • r6rs
    • r7rs
  • mit-scheme
    • interpreter
    • r7rs
  • mosh
    • interpreter
    • r6rs
    • r7rs
  • sagittarius
    • interpreter
    • r6rs
    • r7rs
  • skint
    • interpreter
    • r7rs
  • stklos
    • interpreter
    • r7rs
  • tr7
    • interpreter
    • r7rs
  • ypsilon
    • interpreter
    • r6rs
    • r7rs

Roadmap

  • Support for more implementations
    • Gerbil
      • Dont know how to run this thing yet :D
    • Husk
      • Dont know how to add directories to load path yet, might not be implemented
    • Meevax
    • Picrin
      • Might not be possible, seems to not have (include...) that works like others
    • Stak
    • Vicare
      • So old that I have problems compiling it in Docker, so testing is hard but I expect it to work once I get it to compile as it is R6RS implementation
  • Better and tested support for Windows
    • Right now there is support for running this but I can not quarantee it works on all if any cases
  • Support for -D
    • Most implementations dont have this or equivalent flag, but it would be really nice feature to have so filing issues and implementing it myself is something I would like to do
  • Ask implementations to support adding to the front and back of load path, or implement this onto implementations myself
    • This might not be as important, but it would be nice to go towards SRFI-138 conformaty

Dependencies

Linux

Sagittarius Scheme

On Debian/Ubuntu/Mint:

apt-get install -y build-essential cmake libgc-dev zlib1g-dev libffi-dev libssl-dev
wget https://bitbucket.org/ktakashi/sagittarius-scheme/downloads/sagittarius-0.9.12.tar.gz
tar -xf sagittarius-0.9.12.tar.gz
cd sagittarius-0.9.12.tar.gz
mkdir build
cd build
cmake ..
make
make install

libuv

On Debian/Ubuntu/Mint run:

apt install libuv1

Windows

Sagittarius Scheme

Download the installer from https://bitbucket.org/ktakashi/sagittarius-scheme/downloads/ and install it into default location.

libuv

Libuv is distributed with compile-r7rs on Windows.

Installation

Linux

./configure
make
make install

Windows

Donwload the setup-compile-r7rs.exe from dist directory from this repository.

If you want to compile the installer yourself look into the makefile and installer.iss, it is made with innosetup.

Usage

You need to install each Scheme implementation yourself.

The environment variable COMPILE_R7RS must be set to the name of the implementation as specified in the support list. This differs from the SRFI as the SRFI excepts a path.

To get the list of supported implementations run:

compile-r7rs --list-schemes

Then run it with the .scm file for r7rs, or .sps file for r6rs.

COMPILE_R7RS=<implementation name> compile-r7rs -I . -o main main.scm

Which produces file called main, which you can run. Note that when given Scheme is interpreter the file contains commands that run the script, and even when the file is combiled binary it might need the compiled libraries.

No other file suffixes are supported at the moment.

Setting value of COMPILE_R7RS to implementation name that supports only r7rs and input file to .sps file and other way around is undefined behaviour.

Environment variables

  • COMPILE_R7RS
    • Name of the implementation you want to compile with
    • This differs from the SRFI as it excepts a path
  • COMPILE_R7RS_SCHEME_NAME
    • Additional string to insert right after the command and it's arguments can be used for example to pass C compiler flags on implementations that compile to C
    • For example for Chicken to link with libcurl you would set COMPILE_R7RS_CHICKEN="-L -lcurl"
    • If implementation has - it is changed to _, for example mit-scheme -> MIT_SCHEME
    • This differs from the SRFI as it's not in there

Usage with Docker

Here is a sample Dockerfile to get you started.

ARG COMPILE_R7RS=chibi
FROM debian:bookworm AS build
RUN apt-get update && apt-get install -y build-essential wget make cmake libgc-dev zlib1g-dev libffi-dev libssl-dev
RUN wget https://bitbucket.org/ktakashi/sagittarius-scheme/downloads/sagittarius-0.9.12.tar.gz && tar -xf sagittarius-0.9.12.tar.gz
RUN cd sagittarius-0.9.12 && mkdir build && cd build && cmake -DCMAKE_INSTALL_PREFIX=/usr/local-other .. && make && make install

FROM schemers/${COMPILE_R7RS}
RUN apt-get update && apt-get install -y make libffi8 libgc1 libssl3 libuv1 git
COPY --from=build /usr/local-other/ /usr/local-other/
ENV PATH=${PATH}:/usr/local-other/bin
ENV COMPILE_R7RS=${COMPILE_R7RS}
RUN git clone https://git.sr.ht/~retropikzel/compile-r7rs && cd compile-r7rs && make && make install

To use this run:

export COMPILE_R7RS=<your scheme>
docker build --build-arg COMPILE_R7RS=${COMPILE_R7RS} --tag=compile-r7rs-${COMPILE_R7RS} .
docker run -v "${PWD}":/workdir -w /workdir -t compile-r7rs-${COMPILE_R7RS} sh -c "compile-r7rs -I -o main ./snow main.scm"

Usual RnRS projects

The reports do not say much, if anything, about the file structure of your project. However in practice certain patterns will repeat a lot. Here we use R7RS .sld and .scm files as example but for R6RS .sld = .sld and .scm = .sps.

File structure

The implementations most often expect library named (foo bar) to be in file foo/bar.sld. Some implementations add the current directory to the load path implicitly, some do not. If you store your libraries directly in your projects root it's propably best to always pass . as load path to compile-r7rs.

For example if your projects file structure is:

foo/bar.sld
main.scm

The command to compile and run this project is:

compile-r7rs -I . -o myproject main.scm
./myproject

If your project has more than one library then you propably want to store the libraries in one directory. For example:

snow/foo/bar.sld
main.scm

This is the case the compile-r7rs is tested against, main.scm imports (foo bar). The command to compile and run this project is:

compile-r7rs -I ./snow -o myproject main.scm
./myproject

Installation of your project

compile-r7rs (that is, this project) does not install your project files anywhere, that is left for you to do. I will update this section as I use this project more but here are some ideas. Basically each implementation might need it's own specific way and is outside of scope of this project.

Interpreters

The interpreters, that is for example Sagittarius, Gauche, Chibi and STklos, produce an executable that contains the command to run the main .scm file and add given paths to the implementations load paths. So if you run this:

compile-r7rs -I ./snow -o main main.scm

the resulting main file will only work in this directory, as the load path is relative. For system wide installation the paths would need to be more like this:

compile-r7rs -I /usr/local/lib/myproject/snow -o myproject main.scm

and then in makefile you would have:

install:
    mkdir -p /usr/local/lib/myproject
    cp -r snow /usr/local/lib/myproject/
    install myproject /usr/local/bin/

Compilers

Compilers, that is for example Chicken, Gambit, Cyclone either produce static executable or shared libraries. Cyclone produces static executable so if you run this:

compile-r7rs -I /usr/local/lib/myproject/snow -o myproject main.scm

and then in makefile you would have:

install:
    install myproject /usr/local/bin/

Chicken compiles shared object files and is different from that, like I said I hope to update this section when I get more experience with installing stuff compiled by using this project. :)

Development

The program relies on two projects, r7rs-pffi and pffi-srfi-170. They both are stil work in progress so best way to help this project is to help on those projects. That said bug fixes for this projects are also welcome. Pull requests that add more SRFI-138 support are also welcome, but lets keep the scope on that.

The program itself is a quite straighforward transformer of SRFI-138 inputs to implementation specific inputs. It stands on the shoulders of giants and relies on the implementations to have all the needed features, then unifies the interface to use them.

Adding new implementations

The main program reads the flags and other inputs and passes them to a transformer functions. So to add support for new implementations you need to add the transformer functions and other data for it in libs/data.scm. You should be able to deduct how they work from other transformers. If you need to make utility functions add them into libs/util.scm and export them in libs/util.sld.

Misc notes

When developing and testing, run:

make && sudo make uninstall install

without the uninstall the changes to libraries dont seem to update.