├── LICENSE ├── README.md └── siof.c /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2019, false-schemers 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SIOF (Scheme In One File) - A Minimal R7RS Scheme System 2 | 3 | SIOF is a portable interpreter for the R7RS Scheme programming language. 4 | It can be built from a single C source file [siof.c](https://raw.githubusercontent.com/false-schemers/siof/master/siof.c); 5 | there are no OS- or hardware-specific parts, no compiler-specific tricks, no dependency on platform-specific building tools. There is no distributives or packages: just compile the source file with your favorite C compiler, link it with the standard C runtime libraries and be done with it. For some platforms, precompiled binaries are available (please see [releases](https://github.com/false-schemers/siof/releases)). 6 | 7 | ## Installation 8 | 9 | Here's how you can compile SIOF on a unix box using GCC: 10 | 11 | ``` 12 | gcc -o siof siof.c -lm 13 | ``` 14 | 15 | Please note that some compilers may issue hundreds of warnings; we recommend to add `-Wno-parentheses-equality` for 16 | Clang and `-D_CRT_SECURE_NO_WARNINGS` for Windows headers (unless you want to hear that `fopen` 17 | is no longer a reasonable way to open files). Some compilers link `` library automatically, some require explicit 18 | option like `-lm` above. 19 | 20 | For better performance (up to 3x of the baseline) and smaller executable, you may add optimization flags, e.g.: 21 | 22 | ``` 23 | gcc -o siof -O3 -DNDEBUG siof.c -lm 24 | ``` 25 | 26 | If you do that, be ready for long compilation times (actual time varies widely from ~1 minute to more than an hour, depending on the compiler and optimization level). On systems supporting 32-bit applications such as Windows, it may make sense to compile SIOF in 32-bit mode; performance is almost the same, but both the executable and runtime memory footprint are noticeably smaller. 27 | 28 | The resulting interpreter has no dependencies (except C runtime and standard -lm math library) and can be run from any location. 29 | If compiled statically, it can be easily moved between systems with the same ABI. 30 | 31 | 32 | ## Scheme Compatibility 33 | 34 | SIOF is true to basic Scheme principles -- it features precise garbage collector, supports proper tail recursion, `call/cc`, `dynamic-wind`, multiple return values, and has a hygienic macro system and a library system. It is mostly compatible with R7RS-small standard, but it has the following known limitations and deviations from the standard: 35 | 36 | * fixnums are 30 bit long, flonums are doubles 37 | * no support for bignums/rational/complex numbers 38 | * no support for Unicode; strings are 8-bit clean, use system locale 39 | * source code literals cannot be circular (R7RS allows this) 40 | 41 | Some features of the R7RS-Small standard are not yet implemented or implemented in a simplified or non-conforming way: 42 | 43 | * `read` procedure is always case-sensitive (all ports operate in no-fold-case mode) 44 | * `#!fold-case` and `#!no-fold-case` directives are not supported 45 | * `include` and `include-ci` forms are not supported 46 | * `get-environment-variable` is implemented, but `get-environment-variables` is not 47 | * `current-jiffy` and `jiffies-per-second` return inexact integers 48 | * `current-second` is defined as C `difftime(time(0), 0)+37` 49 | * macroexpander treats `_` as a regular identifier, not match-all pattern 50 | * macroexpander does not support `(... escaped)` pattern escapes 51 | * macroexpander does not support patterns with internal ellipsis and improper tail variable 52 | 53 | Here are some details on SIOF's interactive Read-Eval-Print-Loop (REPL) and evaluation/libraries support: 54 | 55 | * `read` supports R7RS notation for circular structures, but both `eval` and `load` reject them 56 | * all supported R7RS-small forms are available in the built-in `(sharpf base)` library 57 | * `-L` command-line option extends library search path; initial path is `./` 58 | * `cond-expand` checks against `(features)` and available libraries 59 | * `environment` dynamically fetches library definitions from `.sld` files 60 | * non-standard `expand` is available (macroexpands the argument) 61 | * `eval`, `load`, and `expand` accept optional environment argument 62 | * command-line file arguments are dynamically loaded 63 | * both `import` and `define-library` forms can be entered interactively into REPL 64 | * `features` procedure returns `(r7rs exact-closed siof siof-1.0.1)` 65 | 66 | Please note that SIOF's interaction environment exposes bindings for all supported R7RS-small procedures and syntax forms directly, so there is no need to use `import`. In order to use `import` forms and `environment` procedure with R7RS-small libraries, you will need to copy the `scheme` folder with .sld files for the libraries from [here](https://github.com/false-schemers/sharpF/tree/master/int/scheme) to your local system and make sure SIOF can locate it (its library search path contains current directory by default and can be extended with the help of `-L` command line option). 67 | 68 | 69 | ## Origins 70 | 71 | SIOF's original code is written in [#F](https://github.com/false-schemers/sharpF), a language for building Scheme-like 72 | systems. Its #F source code can be found there in `examples` directory: 73 | 74 | [siof.sf](https://raw.githubusercontent.com/false-schemers/sharpF/master/examples/siof.sf) 75 | 76 | SIOF's on-the-fly compiler is derived from Marc Feeley's Scheme Interpreter (see `gambit/bench/src/scheme.scm` in the [Gambit Scheme repository](https://github.com/gambit/gambit)). Hygienic macroexpander is derived from Al Petrofsky's alexpander v1.65 (please see the #F source file for the original copyright notice). Supporting library code comes from #F's [LibL library](https://raw.githubusercontent.com/false-schemers/sharpF/master/lib/libl.sf). 77 | 78 | 79 | ## Family 80 | 81 | Please see [S4IOF](https://github.com/false-schemers/s4iof) repository for a smaller system without hygienic macros, and [S5IOF](https://github.com/false-schemers/s5iof) for its R5RS-compatible variant with hygienic macros. 82 | 83 | 84 | --------------------------------------------------------------------------------