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:
- macOS 10.15 Catalina (2019) removed support for 32-bit applications, so the Red binaries no longer start.
- Apple Silicon Macs (from 2020) cannot run 32-bit Intel code at all; Rosetta 2 translates 64-bit code only.
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
- Runs
.redscripts unmodified:red script.red [args...]. - Interactive console (REPL) with syntax colouring as you type, line editing,
history (with Ctrl-R search) and multi-line input. Windows opened with
view/no-waitstay live at the prompt. - GUI through Red’s View engine on AppKit: VID layouts, the standard styles (window, base, button, text, field, area, lists, drop-downs, slider, progress, tab-panel, group-box, calendar, rich-text and more), events, timers, menus, the request dialogs, and reactive programming.
- The Draw dialect on CoreGraphics, including gradients, pattern and bitmap
pens, the
shapesub-dialect, transforms, shadows and clipping. parse, objects withon-change*/on-deep-change*,image!with PNG, JPEG, GIF, BMP and TIFF,vector!,money!, dates, maps and the rest of the everyday datatypes.- Files and directories,
call,ask/input, HTTP(S)readandwrite, JSON and CSV,checksum,enbase/debase,compress, the clipboard, and Red’s preprocessor (#include,#do,#if,#macroand so on). help,source,what, andtrace/profile/debugfrom Red’s own tooling.- Windows follow the system’s light or dark appearance.
How it works
Wherever Red implements something in Red, red-swift loads that source instead of rewriting it.
- Swift (about 17,000 lines) provides the lexer, the evaluator, the natives
and actions,
parse, the AppKit platform layer and the Draw renderer. - Red’s own source (about 12,000 lines, copied unmodified into
Vendor/redand embedded in the binary) provides the mezzanine functions, View, VID and its style table, reactivity,help, the JSON and CSV codecs, the rich-text dialect and the preprocessor.
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:
random/seedis repeatable but does not reproduce Red’s sequences.1.0 / 0.0raises an error instead of returning1.#INF.copy/types, Zstandard compression and Redbin are not implemented.- Recursion is limited to about 1,500 levels of a Red function.
- In dark mode, default text and Draw lines on an uncoloured background are
light rather than black (
--appearance lightgives Red’s look).
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:
../red, a checkout of red/red, for the conformance tests (or setRED_CHECKOUT);../tictactoe-redand../othello, the two sample programs.
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.