red-swift

Stopgap Red interpreter for 64-bit Mac

View on GitHub

red-swift

A stopgap interpreter for the Red programming language on 64-bit Macs, written in Swift.

It runs Red scripts, command-line and GUI, straight from source, and has an interactive console. It exists because the official Red toolchain is 32-bit only and no longer runs on a current Mac. It is not a replacement for Red: there is no compiler and no Red/System. The aim is that you can write and test Red code on a Mac and then run the same code under real Red elsewhere.

This is an unofficial, personal project, not affiliated with or endorsed by the Red Foundation.

Why this exists

Red was started by Nenad Rakočević in 2011 as an open-source descendant of Rebol, Carl Sassenrath’s language from the late 1990s. It keeps Rebol’s ideas (code is data, small embedded dialects such as parse, VID for user interfaces and Draw for graphics) and adds a native-code compiler and a low-level companion language, Red/System.

Red’s toolchain is bootstrapped in Rebol 2 and generates 32-bit code. Its own README still describes the downloads as “32-bit only for now”. On the Mac that stopped being enough:

A 64-bit Red has been on the project’s roadmap for a long time. Until it arrives, a common workaround on a Mac is a Windows or Linux virtual machine. red-swift is a lighter stopgap for developing and testing scripts natively in the meantime.

What it does

How it works

Wherever Red implements something in Red, red-swift loads that source instead of rewriting it.

The copies come from red/red at commit f4e9d17f1 (0.6.6 plus later work on master). Because the GUI layer is Red’s own code, layout and behaviour follow real Red closely.

Status

Measured against Red’s own test suites at that commit:

Suite Result
Unit tests (tests/source/units, 65 files) 95.1% of 16,721 assertions
Headless View tests (tests/source/view) 278 of 279 assertions

docs/PROGRESS.md lists what still fails and why, along with every judgement call made during the build. docs/design.md is the original plan.

Known differences worth knowing about:

Not included

Red/System, #system and user-defined routines, compiling and encapping (-c, -r), libRed, the GUI console, the camera style, and the non-macOS backends.

Building

Requirements: macOS 15 or later and a Swift 6.2 or later toolchain (Xcode or swift.org). Developed and tested on Apple Silicon.

git clone https://github.com/jonathanhuston/red-swift.git
cd red-swift
swift build -c release

The interpreter is then at .build/release/red. Copy or link it onto your PATH if you like.

Using it

red script.red arg1 arg2      # run a script
red                           # start the console
red -e "print 1 + 2"          # evaluate one expression

A first GUI script:

Red [needs: view]

view [
    title "Hello"
    name: field "world"
    button "Greet" [alert rejoin ["Hello, " name/text "!"]]
]

Other options:

Option Effect
--appearance MODE Force light or dark windows; MODE is light, dark or auto (the default: follow the system). Setting RED_APPEARANCE to light or dark does the same.
--headless --snapshot out.png [--after seconds] Run a GUI script without showing its window and save a picture of it.
--events "click 170,210; wait 0.5" Send scripted mouse clicks to the window (coordinates in points).
--conform [--notes] file... Run Red quick-test files and report pass rates.
--boot-report List problems found while loading the embedded Red source.

The console colours what you type and the == result line: strings, numbers, set-words, comments and so on, and words by what they are bound to at that moment, so your own functions are coloured as functions once defined. It uses the terminal’s own colour palette, so it follows your terminal theme. Set the NO_COLOR environment variable to turn colour off; there is none when input or output is not a terminal.

Two complete programs that run unmodified: tictactoe-red and othello.

Testing

swift build && swift test

The suite takes about two and a half minutes. Some tests are skipped unless the things they need sit next to this folder:

To move to a newer Red commit, run scripts/sync-red.sh <checkout>, which refreshes Vendor/red and the embedded copy, then red --boot-report.

Licence

red-swift is released under the Boost Software License 1.0, the licence of the Red runtime it derives from. The files in Vendor/red remain under their original licences: Boost 1.0 for the runtime sources and BSD 3-Clause for utils/preprocessor.r. See NOTICE.md for the details.

Acknowledgements

All credit for the language, its design and the Red source this project loads goes to Nenad Rakočević and the Red team and contributors. If you want real Red, start at red-lang.org and github.com/red/red.