🌀 A brand-new compiler that allows practical application development using R7RS Scheme. We provide modern features and a stable system capable of generating fast native binaries.
Find a file
yorickhardy 71e5aa2dd6
Improve garbage collection for terminated threads (#550)
* gc: add a function to force the collector to run

This requires adding a "forced" stage for the collector,
which is the initial stage for a forced collection.
Thereafter, the collector continues to the usual stages
of collection.

* runtime: force the garbage collector to run when a thread exits

This is a first attempt to improve the memory usage reported in
issue #534.

* srfi-18: call Cyc_end_thread on thread exits

This ensures that the collector has a chance to run whenever
a thread exits. Attempts to partially address issue #534.

* gc: free unused parts of the heap before merging

When a thread exits, the heap is merged into the main thread.
Before doing so, free any unused parts of the heap to reduce
memory usage. Attempts to partially address issue #534.

* srfi-18: thread-terminate! takes a thread as argument

* gc: revert adding STAGE_FORCING

Use gc_start_major_collection() instead. Partial work towards
addressing issue #534.

* gc: free empty pages in gc_heap_merge()

Moving the code from gc_merge_all_heaps to gc_heap_merge removes
special handling of the start of the list and is (hopefully)
easier to read.

Partial work towards addressing issue #534.

* gc: oops, forgot the "freed" count

Partial work towards addressing issue #534.

* gc: oops, forgot the "freed" count (again)

Partial work towards addressing issue #534.

* types: update forward declaration of gc_heap_merge()

Partial work towards addressing issue #534.

* gc: remove accidental double counting

* runtime: small (cosmetic) simplification

* srfi-18: add a slot for thread context in the thread object

Partial work towards addressing issue #534.

* srfi-18: do a minor gc when terminating a thread

This ensures that any objects which are part of the
thread context are transferred to the heap.

Partial work towards addressing issue #534.

* types.h: make gc_alloc_pair public

This will be used to create the thread context.
Partial work towards addressing issue #534.

* gc: prepare heap objects for sweeping

Also introduce a global variable to track whether merged
heaps need to be swept.

Partial work towards addressing issue #534.

* gc: create a context for terminated thread objects

The context ensures that parametrised objects, continuations
and exception handlers can still be traced but are no longer
root objects (after thread terminations) and can be GCd eventually.

Partial work towards addressing issue #534.

* gc: sweep and free empty heaps for the primordial thread

The primordial thread may not have an opportunity to sweep
heap pages which have been merged from terminated threads.
So sweep any unswept pages during the cooperation phase.

Partial work towards addressing issue #534.

* srfi-18: revert thread-terminate! changes

These changes need to be revisited, and are not suitable for
the threads garbage collection pull request.
2025-01-20 21:10:49 -05:00
.github Remove gcc 14 job for now since its not in ubuntu yet 2024-09-25 19:38:38 -07:00
docs Documentation for thread-terminate changes 2025-01-20 07:59:05 -08:00
examples Issue #370 - Added thread-data type specifier 2021-01-27 22:36:32 -05:00
include/cyclone Improve garbage collection for terminated threads (#550) 2025-01-20 21:10:49 -05:00
libs Add API documentation 2022-06-26 10:17:04 -04:00
scheme Issue #552 - Add 'else' clause for cond-expands 2025-01-18 10:38:35 -08:00
scripts Use temporary file 2024-01-11 19:57:54 -08:00
srfi Improve garbage collection for terminated threads (#550) 2025-01-20 21:10:49 -05:00
tests 552 cond expand no match (#554) 2025-01-16 22:31:08 -05:00
third-party/libtommath-1.2.0 Remove unused file 2019-10-23 09:43:22 -04:00
.gitignore Fixing .gitignore so that test.txt doesn't get added to git tree 2017-02-03 17:29:10 +13:00
.travis.yml Avoid syntax errors 2020-11-18 17:41:39 -05:00
Architecture.md Code formatting for module headers 2023-03-04 07:43:01 -08:00
AUTHORS Add credit for latest symbol fix 2021-03-04 22:15:54 -05:00
CHANGELOG.md Documentation for thread-terminate changes 2025-01-20 07:59:05 -08:00
ck-polyfill.c Re-format code 2024-01-17 19:43:47 -08:00
ck-polyfill.h Re-format code 2024-01-17 19:43:47 -08:00
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md 2017-07-01 22:49:01 -04:00
cyclone.scm Merge #497 2022-12-09 13:29:56 -08:00
Dockerfile Increment revision number 2024-02-13 18:29:04 -08:00
Doxyfile Bump doxygen version 2021-04-06 20:00:22 -07:00
DoxygenLayout.xml New file 2017-02-24 13:48:47 -05:00
ffi.c Re-format code 2024-01-17 19:43:47 -08:00
FUTURE Removed all traces of array-list from core 2020-05-26 21:09:14 -03:00
gc.c Improve garbage collection for terminated threads (#550) 2025-01-20 21:10:49 -05:00
generate-c.scm Added header comment block. 2016-02-14 22:35:04 -05:00
hashset.c Re-format code 2024-01-17 19:43:47 -08:00
icyc.scm Missing parenthesis in let* 2020-05-30 00:16:54 -03:00
LICENSE Updated year 2015-07-22 21:30:15 -04:00
Makefile Issue 522 - Add unit test framework for C runtime (#545) 2024-09-24 21:57:33 -04:00
Makefile.config Fix open_memstream/fmemopen feature detection with GCC >= 14 (#544) 2024-09-25 22:27:14 -04:00
Makefile.config.raspberry-pi-2 Don't use conditional assignment operator for CFLAGS/LDFLAGS 2021-08-03 06:04:11 +02:00
mstreams.c Re-format code 2024-01-17 19:43:47 -08:00
README.md Remove travis CI link 2024-01-08 19:44:00 -08:00
runtime.c Improve garbage collection for terminated threads (#550) 2025-01-20 21:10:49 -05:00
sync.sh Successfuly installed and tested Cyclone on FreeBSD 12.0 with clang 6.0.1. Updated docs, adaptaed sync.sh and corrected Makefile 2019-07-29 06:58:52 -03:00
test-lib-dep.scm Build out recompilation logic 2020-01-03 18:02:38 -05:00
test-lib.c Issue 522 - Add unit test framework for C runtime (#545) 2024-09-24 21:57:33 -04:00

Cyclone Scheme

Github CI - Linux

Github CI - MacOS

Github CI - MacOS Homebrew

Github CI - Windows

Cyclone Scheme is a brand-new compiler that allows real-world application development using the R7RS Scheme Language standard. We provide modern features and a stable system capable of generating fast native binaries.

Cheney on the MTA is used by Cyclone's runtime to implement full tail recursion, continuations, and generational garbage collection. In addition, the Cheney on the MTA concept has been extended to allow execution of multiple native threads. An on-the-fly garbage collector is used to manage the second-generation heap and perform major collections without "stopping the world".

Features

  • Support for the majority of the Scheme language as specified by the latest R7RS standard.
  • New features from R7RS including libraries, exceptions, and record types.
  • Built-in support for Unicode strings and characters.
  • Hygienic macros based on syntax-rules
  • Low-level explicit renaming macros
  • Guaranteed tail call optimizations
  • Native multithreading support
  • A foreign function interface that allows easy integration with C
  • A concurrent, generational garbage collector based on Cheney on the MTA
  • Includes an optimizing Scheme-to-C compiler,
  • ... as well as an interpreter for debugging
  • A Package Manager and a growing list of packages.
  • Support for many popular SRFI's
  • Online user manual and API documentation
  • Support for Linux, Windows, FreeBSD, and Mac platforms.
  • Known to run on x86-64, x86, and Arm (Raspberry Pi) architectures.

Try in your Browser

You can run the Cyclone interpreter right in your browser. No installation required.

Installation

For the full user experience - compiling files, installing packages, running native code, etc - it is necessary to install a copy of Cyclone.

There are several installation options available:

Docker

Docker

Cyclone can be run from a Docker Image:

docker run -it cyclonescm/cyclone bash

Homebrew

Homebrew

Mac (and Linux!) users wanting to use Homebrew can do the following.

Note if Homebrew is not already installed: follow the instructions at https://brew.sh/ to install the homebrew package manager.

brew tap cyclone-scheme/cyclone
brew install cyclone-scheme/cyclone/cyclone-bootstrap

Arch Linux

Arch Linux

Arch Linux users can install using the AUR:

git clone https://aur.archlinux.org/cyclone-scheme.git
cd cyclone-scheme
makepkg -si

Gentoo Linux

Gentoo Linux

Cyclone is available from the official Gentoo package repository.

Build from Source

Build from Source

To install Cyclone on your machine for the first time on Linux, Windows, FreeBSD, and for Mac users wanting to install without using Homebrew, use cyclone-bootstrap to build a set of binaries. Instructions are provided for Linux, Mac, Windows (via MSYS), and FreeBSD 12.

Getting Started

After installing you can run the cyclone command to compile a single Scheme file:

$ cyclone examples/fac.scm
$ examples/fac
3628800

And the icyc command to start an interactive interpreter. Note you can use rlwrap to make the interpreter more friendly, EG: rlwrap icyc:

$ icyc

              :@
            @@@
          @@@@:
        `@@@@@+
       .@@@+@@@      
       @@     @@     Cyclone Scheme->C compiler
      ,@             http://justinethier.github.io/cyclone/
      '@
      .@
       @@     #@     (c) 2014-2019 Justin Ethier
       `@@@#@@@.     Version 0.11
        #@@@@@
        +@@@+
        @@#
      `@.
   
cyclone> (write 'hello-world)
hello-world

Read the documentation below for more information on how to use Cyclone.

Package Manager

Cyclone Winds

The winds package manager provides the ability to install packaged libraries and programs for Cyclone. See the winds site for more information.

The Winds wiki contains a full list of packages with documentation.

Documentation

Example Programs

Cyclone provides several example programs, including:

  • Tail Call Optimization - A simple example of Scheme tail call optimization; this program runs forever, calling into two mutually recursive functions.

  • Threading - Various examples of multi-threaded programs.

  • Game of Life - The Conway's game of life example program and libraries from R7RS.

  • Game of Life PNG Image Generator - A modified version of game of life that uses libpng to create an image of each iteration instead of writing it to console. This example also demonstrates basic usage of the C Foreign Function Interface (FFI).

  • Finally, the largest program is the compiler itself. Most of the code is contained in a series of libraries which are used by cyclone.scm and icyc.scm to create executables for Cyclone's compiler and interpreter.

Compiler Internals

  • Writing the Cyclone Scheme Compiler provides high-level details on how the compiler was written and how it works.

  • There is a Development Guide with instructions for common tasks when hacking on the compiler itself.

  • Cyclone's Garbage Collector is documented at a high-level. This document includes details on extending Cheney on the MTA to support multiple stacks and fusing that approach with a tri-color marking collector.

License

Copyright (C) 2014 Justin Ethier.

Cyclone is available under the MIT license.