ribbit

A portable, compact and extensible Scheme implementation that is fully R4RS compliant. This includes closures, I/O, tail calls, first-class continuations and a Read Eval Print Loop (REPL). The R4RS Scheme REPL fits inside 6.5Kb !

https://github.com/udem-dlteam/ribbit

Science Score: 54.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.6%) to scientific vocabulary
Last synced: 6 months ago · JSON representation ·

Repository

A portable, compact and extensible Scheme implementation that is fully R4RS compliant. This includes closures, I/O, tail calls, first-class continuations and a Read Eval Print Loop (REPL). The R4RS Scheme REPL fits inside 6.5Kb !

Basic Info
  • Host: GitHub
  • Owner: udem-dlteam
  • License: bsd-3-clause
  • Language: Scheme
  • Default Branch: main
  • Homepage:
  • Size: 40.5 MB
Statistics
  • Stars: 535
  • Watchers: 20
  • Forks: 60
  • Open Issues: 20
  • Releases: 0
Created about 5 years ago · Last pushed 7 months ago
Metadata Files
Readme License Citation Authors

README.md

Ribbit :frog:

A portable, compact and extensible Scheme implementation that is fully R4RS compliant. This includes closures, I/O, tail calls, first-class continuations and a Read Eval Print Loop (REPL).

For more information about Ribbit, you can look at our papers in the paper section or try the R4RS repl below !

🐸 Try the R4RS REPL here 🐸

Development

Ribbit is a research project currently under development. A lot of enhancements have been made since the first paper (R4RS compliance, I/O primitives, define-primitive/define-feature, bignum/flonums etc.) and a new release is planned for the end of 2024. If you do encounter bugs, please report them in the issue section of Github.

Like all systems, Ribbit has some quirks. If you encounter problems that are not documented or if you have any questions, please reach out in the issues section of Github.

Usage

Currently, Ribbit has only been tested with Gambit v4.7.5, and may not work with other Scheme implementations.

The Ribbit AOT compiler is written in Scheme and can be executed with Gambit v4.7.5. The compiler's source code is in a single file: src/rsc.scm.

Ribbit currently compiles Scheme code to more than 15 different host languages. To select a language, use the -t compiler option followed by the extension of the target language. For example, the option can be followed by js (JavaScript), asm (x86 Assembly), c (C), py (Python), hs (Haskell), pro (Prolog) or any of the supported targets.

The -m option causes a minification of the generated program. This requires a recent version of Gambit and may need aditionnal dependencies depending on the target under minification. See the host/<host>/minify script of a specific host for details.

The -l option allows selecting the Scheme runtime library (located in the lib subdirectory). Here is a list of libraries : - r4rs : Adds all essential R4RS procedures. Includes a REPL that is fully R4RS compliant. - r4rs/tc : Like r4rs but with run time type checking. - min, max : Minimal library for small scheme implementations, including a minimal REPL. - max-tc : Like min and max but with run time type checking. - define-macro : Necessary for using the define-macro construct.

To compile an executable of the Ribbit Scheme Compiler (rsc.exe) with Gambit, you can use :

cd src make rsc.exe

Usage Examples

Here are a few examples, all assume that a cd src and make rsc.exe has been done first :

Use RSC to compile an R4RS compliant REPL to Python

``` $ ./rsc.exe -t py -l r4rs lib/r4rs/repl.scm -o repl.py $ python3 repl.py

(+ 1 2) 3 (define handle (open-output-file "test.txt")) 0 (display "Hello Ribbit!" handle) 0 ^D (Ctrl-D) $ cat test.txt Hello Ribbit! ```

Do the same but generating a JavaScript R4RS REPL:

``` $ ./rsc.exe -t js -l r4rs lib/r4rs/repl.scm -o repl.js $ node repl.js

(+ 1 2) 3 ```

Try it with different hosts (make sure they support R4RS in the supported target list) :

$ ./rsc.exe -t asm -l r4rs lib/r4rs/repl.scm -o repl.s (x86 assembly, need linux as it generates an ELF file) $ ./rsc.exe -t c -l r4rs lib/r4rs/repl.scm -o repl.c $ ./rsc.exe -t hs -l r4rs lib/r4rs/repl.scm -o repl.hs

Generate the world's smallest R4RS compliant REPL (takes 1 minute)

``` $ make repl-asm.exe $ ls -la repl-asm.exe -rwxr-xr-x 1 leonard staff 6639 5 Aug 13:36 repl.exe !!! 6.5KB !!! $ echo '(+ 1 2)' | ./repl-asm.exe

3

```

Generate a simple 'hello world' program in 16 different languages

$ echo '(display "Hello from Ribbit!")' > hello.scm $ ./rsc.exe -t pro -l max hello.scm -o hello.pro # compile it with prolog $ swipl hello.pro # run it with swi-prolog Hello from Ribbit!

Then, choose among 16 host languages :

$ ./rsc.exe -t asm -l max hello.scm -o hello.asm $ ./rsc.exe -t c -l max hello.scm -o hello.c $ ./rsc.exe -t hs -l max hello.scm -o hello.hs $ ./rsc.exe -t js -l max hello.scm -o hello.js $ ./rsc.exe -t py -l max hello.scm -o hello.py $ ./rsc.exe -t clj -l max hello.scm -o hello.clj $ ./rsc.exe -t lisp -l max hello.scm -o hello.lisp $ ./rsc.exe -t pro -l max hello.scm -o hello.pro $ ./rsc.exe -t scm -l max hello.scm -o hello.scm $ ./rsc.exe -t sh -l max hello.scm -o hello.sh $ ./rsc.exe -t go -l max hello.scm -o hello.go $ ./rsc.exe -t lua -l max hello.scm -o hello.lua $ ./rsc.exe -t ml -l max hello.scm -o hello.ml $ ./rsc.exe -t idr -l max hello.scm -o hello.idr $ ./rsc.exe -t scala -l max hello.scm -o hello.scala $ ./rsc.exe -t zig -l max hello.scm -o hello.zig

Interact with the host language (js and C here):

``` $ cat examples/square.scm (cond-expand ((host py) ;; Python host (define-primitive (square x) "lambda: push(pop()*2),")) ((host c) ;; C host (define-primitive (square x) "{ int x = NUM(pop()); push2(TAG_NUM(xx), PAIR_TAG); }")))

(##putchar (square 8)) ;; prints '@' as 64 is the ASCII value of '@' (##putchar 10) ;; prints a newline

$ ./rsc.exe -t py examples/square.scm -o square.py $ python3 square.py @ $ ./rsc.exe -t c examples/square.scm -o square.c $ gcc square.c -o square $ ./square @ ```

Generate a simple typed-checked max REPL in any of the hosts

Note that the incremental compiler used by the repl-max.scm only supports a subset of the Scheme special forms. In particular procedure definitions should use (define f (lambda (x) ...)) instead of (define (f x) ...).

``` $ ./rsc.exe -t pro -l max-tc examples/repl-max.scm -o repl-max.pro $ swipl repl-max.pro

(+ 1 2) 3 ^D ```

Choose any language that supports the core features in the supported targets table and compile it by replacing pro with the target language.

Other examples and tests

For other examples and tests, you can look at the examples and tests directories.

The makefile in the src directory has these make targets:

  $ make check                     # Run all tests for all hosts (very long)

  $ HOST=c make check              # Run tests for the C host

  $ HOST=py PY_HOST_INTERPRETER=pypy make check  # Run tests for specific host and interpreter

Supported targets

Here : - core means a traditional RVM implementation. These support minimal I/O (putchar, getchar only), and min/max/max-tc repls. - variadics means that the target supports functions with any numbers of parameters, for example, the (define (f . rest) ...) form. - I/O means that the target supports the full I/O primitives defined by R4RS (open-input-file, open-output-file, etc.). - r4rs means that the target supports the full R4RS essential standard. This relies on all the above features.

| Language | Core | variadics | I/O | R4RS | |----------------------|------|-----------|------|------| | x86 Assembly (asm) | ✅ | ✅ | ✅ | ✅ | | C (c) | ✅ | ✅ | ✅ | ✅ | | Haskell (hs) | ✅ | ✅ | ✅ | ✅ | | JavaScript (js) | ✅ | ✅ | ✅ | ✅ | | Python (py) | ✅ | ✅ | ✅ | ✅ | | Clojure (clj) | ✅ | ✅ | ❌ | ❌ | | Common Lisp (lisp) | ✅ | ✅ | ❌ | ❌ | | Prolog (pro) | ✅ | ✅ | ❌ | ❌ | | Scheme (scm) | ✅ | ✅ | ❌ | ❌ | | Posix-Shell (sh) | ✅ | ✅ | ❌ | ❌ | | Go (go) | ✅ | ❌ | ❌ | ❌ | | Lua (lua) | ✅ | ❌ | ❌ | ❌ | | OCaml (ml) | ✅ | ❌ | ❌ | ❌ | | Idris 2 (idr) | ✅ | ❌ | ❌ | ❌ | | Scala (scala) | ✅ | ❌ | ❌ | ❌ | | Zig (zig) | ✅ | ❌ | ❌ | ❌ | | Ruby (rb) | 🚧 | ❌ | ❌ | ❌ | | Java (java) | 🚧 | ❌ | ❌ | ❌ | | Rust (rs) | 🚧 | ❌ | ❌ | ❌ |

Research and Papers

We are actively developing Ribbit. If you have an idea, you can reach out to leo-ard or feeley. All papers concerning Ribbit are available here :

If you want to cite our work, all BibTeX entries are available in the CITATION.bib file.

Owner

  • Name: udem-dlteam
  • Login: udem-dlteam
  • Kind: organization

Citation (CITATION.md)

To cite this software, please cite the following publications:

- **Léonard Oest O’Leary, Mathis Laroche, and Marc Feeley. 2023. A R4RS Compliant REPL in 7 KB. (2023). https://doi.org/10.48550/ARXIV.2310.13589 arXiv:2310.13589 [cs.PL] This paper was presented at the Scheme and Functional Programming Workshop (SFPW’23), part of ICFP’23.**
```bibtex
@article{
  OestOlearyLarocheFeeley2023,
  author       = {L{\'{e}}onard Oest O'Leary and Mathis Laroche and Marc Feeley},
  title        = {A R4RS Compliant REPL in 7 KB},
  year         = {2023},
  location     = {Seattle, WA, USA},
  eprint       = {2310.13589},
  series       = {SFPW'23},
  doi          = {10.48550/ARXIV.2310.13589},
  url          = {https://arxiv.org/abs/2310.13589},
  keywords     = {Virtual Machines, Compiler, Dynamic Languages, Scheme, Compactness},
  primaryclass = {cs.PL},
  note         = {This paper was presented at the Scheme and Functional Programming Workshop (SFPW'23), part of ICFP'23}
}
```

- **Léonard Oest O'Leary and Marc Feeley. 2023. A Compact and Extensible Portable Scheme VM. In Companion Proceedings of the 7th International Conference on the Art, Science, and Engineering of Programming (Programming '23). Association for Computing Machinery, New York, NY, USA, 3–6. https://doi.org/10.1145/3594671.3594672**
```bibtex
@inproceedings{
    OestOlearyFeeley2023,
    author = {O'Leary, L\'{e}onard Oest and Feeley, Marc},
    title = {A Compact and Extensible Portable Scheme VM},
    year = {2023},
    isbn = {9798400707551},
    publisher = {Association for Computing Machinery},
    address = {New York, NY, USA},
    url = {https://doi.org/10.1145/3594671.3594672},
    doi = {10.1145/3594671.3594672},
    abstract = {Virtual Machines (VM) tend to evolve over their life cycle with features being added regularly and a growing footprint. In a VM designed for resource constrained environments this trend deteriorates the VM’s primary quality. We present how extensibility is implemented in the Ribbit Scheme VM that is both compact and portable to multiple languages. Our approach adds annotations to the VM’s source code allowing the compiler to generate the source code of a specialized VM extended with user-defined primitives and with needless ones removed. This gives the best of both worlds: an extensible VM packed with all and only the features needed by the source code, while maintaining a small code footprint.},
    booktitle = {Companion Proceedings of the 7th International Conference on the Art, Science, and Engineering of Programming},
    pages = {3–6},
    numpages = {4},
    keywords = {Compactness, Compiler, Dynamic Languages, Scheme, Virtual Machines},
    location = {Tokyo, Japan},
    series = {Programming '23}
}
```

- **Samuel Yvon and Marc Feeley. 2021. A small scheme VM, compiler, and REPL in 4k. In Proceedings of the 13th ACM SIGPLAN International Workshop on Virtual Machines and Intermediate Languages (VMIL 2021). Association for Computing Machinery, New York, NY, USA, 14–24. https://doi.org/10.1145/3486606.3486783**
```bibtex
@inproceedings{
  YvonFeeley2021,
  author = {Yvon, Samuel and Feeley, Marc},
  title = {A small scheme VM, compiler, and REPL in 4k},
  year = {2021},
  isbn = {9781450391092},
  publisher = {Association for Computing Machinery},
  address = {New York, NY, USA},
  url = {https://doi.org/10.1145/3486606.3486783},
  doi = {10.1145/3486606.3486783},
  abstract = {Compact language implementations are increasingly popular for use in resource constrained environments. For embedded applications such as robotics and home automation, it is useful to support a Read-Eval-Print-Loop (REPL) so that a basic level of interactive development is possible directly on the device. Due to its minimalistic design, the Scheme language is particularly well suited for such applications and several implementations are available with different tradeoffs. In this paper we explain the design and implementation of Ribbit, a compact Scheme system that supports a REPL, is extensible and has a 4 KB executable code footprint.},
  booktitle = {Proceedings of the 13th ACM SIGPLAN International Workshop on Virtual Machines and Intermediate Languages},
  pages = {14–24},
  numpages = {11},
  keywords = {Virtual Machines, Small Footprint, Scheme, Read-Eval-Print-Loop, Dynamic Languages, Compiler},
  location = {Chicago, IL, USA},
  series = {VMIL 2021}
}
```

GitHub Events

Total
  • Create event: 25
  • Issues event: 13
  • Watch event: 55
  • Delete event: 3
  • Member event: 1
  • Issue comment event: 31
  • Push event: 239
  • Pull request review comment event: 33
  • Pull request review event: 32
  • Pull request event: 83
  • Fork event: 16
Last Year
  • Create event: 25
  • Issues event: 13
  • Watch event: 55
  • Delete event: 3
  • Member event: 1
  • Issue comment event: 31
  • Push event: 239
  • Pull request review comment event: 33
  • Pull request review event: 32
  • Pull request event: 83
  • Fork event: 16

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 3
  • Total pull requests: 36
  • Average time to close issues: 10 days
  • Average time to close pull requests: about 1 month
  • Total issue authors: 3
  • Total pull request authors: 13
  • Average comments per issue: 0.33
  • Average comments per pull request: 0.19
  • Merged pull requests: 27
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 3
  • Pull requests: 35
  • Average time to close issues: 10 days
  • Average time to close pull requests: 4 days
  • Issue authors: 3
  • Pull request authors: 12
  • Average comments per issue: 0.33
  • Average comments per pull request: 0.2
  • Merged pull requests: 27
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • bentxt (5)
  • leo-ard (3)
  • ShalokShalom (1)
  • joelmccracken (1)
  • ec1oud (1)
  • benkb (1)
  • kakafarm (1)
Pull Request Authors
  • leo-ard (22)
  • omelancon (6)
  • l4haie (5)
  • Ecoral360 (3)
  • FaraDuMatin (3)
  • DubeJeanFrancois (2)
  • Zabieru111 (2)
  • kakafarm (2)
  • alxcar (1)
  • simonl (1)
  • Minick-M (1)
  • LouisPierre (1)
  • Mahdi267 (1)
  • EnzoDaval (1)
  • BSlug (1)
Top Labels
Issue Labels
bug (2) good first issue (1)
Pull Request Labels