cd /news/developer-tools/show-hn-ruscal-a-turbo-pascal-to-rus… · home › topics › developer-tools › article
[ARTICLE · art-172189] src=github.com ↗ pub= topic=developer-tools verified=true sentiment=↑ positive

Show HN: Ruscal: A Turbo Pascal to Rust Transpiler

JJ Behrens released Ruscal, a Turbo Pascal to Rust transpiler written by Claude Code Opus with help from Claude Code Fable, installable via `cargo install ruscal` at version 0.7.0. Ruscal emits a small Cargo project for each Pascal program so old Turbo Pascal code, including graphics and Turbo Pascal 3.0 turtle graphics programs, builds and runs natively on modern computers, and it supports bidirectional calls between Pascal and Rust plus reading and converting legacy binary data files to and from JSON. The tool matters because it lets developers keep editing Pascal and re-transpile, or transpile once and continue in Rust, while preserving Turbo Pascal's wrapping integer arithmetic via `overflow-checks = false`.

key takeaway

Ruscal 0.7.0 transpiles Turbo Pascal to Rust via `cargo install ruscal`, with `ruscal run hello.pas` building a Cargo project in out/hello/ and `ruscal emit` printing the generated Rust; Pascal `external` routines link to Rust files named with `{$L ...}`, and Rust projects embed Pascal units through

read19 min views5 publishedNov 18, 2026
Show HN: Ruscal: A Turbo Pascal to Rust Transpiler
Image: Michielbdejong (auto-discovered)

Ruscal is a fairly-complete and well-tested Turbo Pascal to Rust transpiler, so that you can more easily run your old Turbo Pascal programs on modern computers.

Ruscal writes a small Cargo project for each program so you can build and run your old Turbo Pascal code natively.

  • You can continue editing the Turbo Pascal code and transpile it every time.
  • You can transpile your Turbo Pascal code to Rust once and then edit the Rust going forward.
  • You can run your old Turbo Pascal programs even if they use graphics, and port older Turbo Pascal 3.0 turtle graphics programs with a couple of small changes.
  • You can call out to Rust from a Turbo Pascal program.
  • You can call into Turbo Pascal from a Rust program.
  • You can read old binary data files written by Turbo Pascal.
  • You can also translate those files to and from JSON.
  • There's even a pretty printer for reformatting your Turbo Pascal code.

Ruscal was written by Claude Code Opus with help from Claude Code Fable and JJ Behrens.

By the way, Ruscal is pronounced "rust-CAL", with the stress on "CAL", as in "Pascal".

You need a Rust toolchain (see Requirements).

Install Ruscal from crates.io; you don't need this repository:

cargo install ruscal

Then, next to your program (hello.pas here):

program Hello;
var
   Name: string;
begin
   Write('What is your name? ');
   ReadLn(Name);
   WriteLn('Hello, ', Name, '!');
end.
ruscal run hello.pas       # translate it to Rust, build it and run it
ruscal emit hello.pas      # just print the Rust

run puts a small Cargo project in out/hello/ and runs it (see Usage). A program finds its units' source files next to it.

Declare the routine external, and name the Rust file that has it with {$L ...}, as Turbo Pascal linked assembly. greet.pas:

program Greet;
{$L greet.rs}

procedure SayHello(const Name: string); external;

begin
   SayHello('Turbo Pascal');
end.

and greet.rs, next to it:

use ruscal_runtime::prelude::*;

pub fn say_hello(name: &PString) {
    pwriteln!("Hello, ", name, ", from Rust!");
}

ruscal run greet.pas prints Hello, Turbo Pascal, from Rust!. A Pascal string is a PString in Rust; ruscal emit greet.pas shows the signature each external routine needs. Calling Rust from Turbo Pascal has the rest.

In your Rust project, add Ruscal's runtime, and Ruscal itself to translate the Pascal when it builds (both the same version):

cargo add ruscal_runtime@=0.7.0
cargo add --build ruscal@=0.7.0 --no-default-features

and in Cargo.toml, let Pascal's integer arithmetic wrap around, as it did in Turbo Pascal:

[profile.dev]
overflow-checks = false

Write the Pascal as a unit, pascal/greeter.pas:

unit Greeter;

interface

   procedure SayHello(const Name: string);
   function Square(N: Integer): Integer;

implementation

   procedure SayHello(const Name: string);
      begin
         WriteLn('Hello, ', Name, ', from Turbo Pascal!');
      end;

   function Square(N: Integer): Integer;
      begin
         Square := N * N;
      end;

end.

translate it in build.rs:

fn main() {
    ruscal::build::library("pascal/greeter.pas").unwrap();
}

and call it from src/main.rs:

ruscal_runtime::include_library!(greeter);

use ruscal_runtime::prelude::PString;
use ruscal_runtime::{RuntimeError, call};

fn main() -> Result<(), RuntimeError> {
    // Runs the units' initialization parts.
    let _units = call(greeter::GreeterContext::new)?;
    // `call` turns a Pascal runtime error into an `Err`.
    call(|| greeter::say_hello(&PString::from("Rust")))?;
    let n = call(|| greeter::square(12))?;
    println!("12 squared is {n}, says Pascal");
    Ok(())
}

cargo run prints Hello, Rust, from Turbo Pascal! and 12 squared is 144, says Pascal. Calling Turbo Pascal from Rust has the rest.

Clone the repository to run its examples:

git clone https://github.com/jjinux/ruscal.git
cd ruscal

If you can open a window (on Linux, that needs the packages under Requirements), try turtle graphics (press a key after each drawing):

cargo run -p ruscal -- run examples/ruscal/turtles.pas

Or, needing only a terminal, try a Game of Life written in Turbo Pascal in 1997 (follow its menu; to quit while it runs, press p, then 5, then Enter):

cargo run -p ruscal -- run examples/life.pas

Examples lists the rest: an airport simulation, a clock, tic-tac-toe and more.

My first programming language was Borland's Turbo Pascal running in DOS or Windows 3.1. I've always thought that Pascal was the Python of its day in that it was a really pleasant language to code in and was great for newbies. I had all these Turbo Pascal programs that I had written as a student, but I had no easy way to run them. I'm really inspired by the idea of creating a native compiler, but there's hardly a point now that LLVM exists. I also wanted a chance to play with Rust a bit more and to use Claude. Hence, my project to transpile Turbo Pascal code to Rust. If you have some old Turbo Pascal code lying around, give it a try!

  • Rust 1.88 or later (the crates use the 2024 edition and its let chains), fromrustup , withrustfmt (rustup component add rustfmt ), which tidies the generated Rust; without it the Rust still works, unformatted.
  • macOS or Linux (developed on macOS; CI runs on Linux). On Linux, Graph programs need the X11 and Wayland development packages for their window:libx11-dev libxcursor-dev libxkbcommon-dev libwayland-dev on Debian or Ubuntu.
  • Graph programs open a 640x480 window (or draw without one: seeRUSCAL_GRAPH=headless underEnvironment variables ).

From the repository root:

cargo run -p ruscal -- run examples/life.pas

cargo run -p ruscal -- run myprog.pas -- first second

cargo run -p ruscal -- emit examples/paper.pas

cargo run -p ruscal -- build examples/magic_square.pas -o /tmp/magic

The Cargo project goes in out/<name>/ under the directory you run the command from (-o picks another), and the executable is out/<name>/target/debug/<name>. A program's own files ( scores.dat, printer.txt) are written in the current directory, as they were in DOS.

Old sources with DOS (\r\n) line endings are fine everywhere: the transpiler, Readln on standard input and text files, and fmt (which writes UNIX line endings, or DOS ones with --crlf).

Or install the tools once, which puts ruscal and tpc (below) in ~/.cargo/bin (put it on your PATH if it isn't already), and use ruscal run foo.pas:

cargo install ruscal

cargo install --path crates/ruscal

RUSCAL_RUNTIME can point generated projects at another crates/ruscal_runtime instead (in a checkout, the crate takes its edition and version from the workspace around it).

examples/ holds the Turbo Pascal programs this project was built to run, written in 1996-97. Run them from the repository root:

cargo run -p ruscal -- run examples/blkjack.pas        # Blackjack
cargo run -p ruscal -- run examples/paper.pas          # Paper, scissors, rock
cargo run -p ruscal -- run examples/life.pas           # The Game of Life
cargo run -p ruscal -- run examples/magic_square.pas   # Solves a 4x4 magic square puzzle
cargo run -p ruscal -- run examples/gmscode.pas        # Encodes what you type as you type it
cargo run -p ruscal --bin tpc -- -Eout/a/shannon examples/life.pas
cargo run -p ruscal --bin tpc -- -Eout/a/shannon examples/gmscode.pas
cargo run -p ruscal --bin tpc -- -Eout/a/shannon examples/paper.pas
cargo run -p ruscal --bin tpc -- -Eout/a/shannon examples/blkjack.pas
cargo run -p ruscal --bin tpc -- -Eout/a/shannon examples/airport/airport4.pas
RUSCAL_DRIVE_A=out/a cargo run -p ruscal -- run examples/menu.pas

cargo run -p ruscal -- run examples/airport/airport4.pas   # An airport runway simulation

RUSCAL_DRIVE_C=examples/database cargo run -p ruscal -- run examples/database/filesys.pas

cargo run -p ruscal -- run examples/clock/tester.pas   # A clock whose hands run backwards
RUSCAL_DRIVE_A=examples cargo run -p ruscal -- run examples/tictac/tictac.pas

The environment variable goes before cargo, so it applies to the whole command (and to the program it runs).

examples/ruscal/ holds examples written for Ruscal:

cargo run -p ruscal -- run examples/ruscal/turtles.pas

cargo run -p ruscal -- run examples/ruscal/calls_rust.pas

cargo run --manifest-path examples/ruscal/rust_calls_pascal/Cargo.toml

To start a project of your own from one of them, copy it out of a clone (for the two .pas examples, install ruscal first, as above):

  • turtles.pas on its own, run withruscal run turtles.pas : units whose names start withRsc are built into Ruscal, so there's nothing else to copy.
  • calls_rust.pas withcalls_rust.rs beside it, run withruscal run calls_rust.pas .
  • The whole rust_calls_pascal directory (withouttarget/ , if you've built it), run withcargo run , changing the twopath dependencies in itsCargo.toml to crates.io ones, as the comment at its top shows (ruscal_runtime = "=0.7.0" ; seeCalling Turbo Pascal from Rust ).

ruscal run and build put the Cargo project in out/ in the directory you run them from, so add out/ to your .gitignore (and target/ for a Rust project like rust_calls_pascal).

Ruscal reads Turbo Pascal 7.0 syntax and covers most of Turbo Pascal 5.5 to 7.0 as students used it. It runs every program in examples/. The language spec has the details, and TODO.md, the development plan, says what's next.

The standard units, for a reader who knows Rust but not Turbo Pascal: Crt is the text screen and keyboard (colors, cursor, ReadKey), Dos is dates, times, files and directories, and Graph is Borland's BGI graphics. Ruscal provides all three in its runtime.

  • The language: the usual types (Integer ,LongInt ,Real ,Char ,Boolean and the rest), strings, arrays, records (variant records too), enums, subranges, sets, typed constants,with ,case ,Break andContinue , nested and recursive procedures,var andconst parameters, open array parameters (a: array of Integer ), and procedural types.
  • Units: a program pulls in its units' source files, which are translated with it.
  • Objects: inheritance, virtual methods, constructors and destructors,inherited , polymorphic pointers andTypeOf .
  • Pointers:New /Dispose , linked lists and trees, the untypedPointer ,GetMem /FreeMem , andPChar strings with their pointer arithmetic.
  • goto: a jump forward or back within a statement list, translated as Rust's labeled blocks and loops.
  • Files: text files, typed files (file of T ) and untyped files. Typed files use Turbo Pascal's own byte layout (6-byteReal s, andSingle ,Double andExtended as the 8087 stored them,string[n] as n+1 bytes, unpadded records), so a program can read the data files it wrote decades ago.{$I-} andIOResult work.
  • Standard units:Crt ,Dos ,Graph (in a window),Printer ,Overlay ,Strings andWinDos .
  • Ruscal's own units:RscJson for reading and writing JSON, andRscTurtle for turtle graphics, with Turbo Pascal 3.0's turtle routines on top ofGraph .
  • Turbo Pascal's behavior: runtime errors print Turbo Pascal's message and exit code (Runtime error 201: Range check error ... ),{$Q+} checks for overflow,Random gives the same numbers as Turbo Pascal, and DOS file names likeC:\DATA\X.DAT go to directories you choose (seeEnvironment variables ).
  • Calling Rust: Turbo Pascal code can callexternal routines written in Rust, linked with{$L file.rs} (seeCalling Rust ).
  • Calling Turbo Pascal from Rust: a Rust project'sbuild.rs translates a unit whilecargo build runs, orruscal build --lib makes a library of one (seeCalling Turbo Pascal from Rust ). There's an example of each way inexamples/ruscal/ .
  • Faked, so old programs still run:Lst prints to a file or a command (seePrinting ), overlays need no.OVR file,MemAvail reports plenty of memory, and interrupt vectors keep the handlers set in them (which never run).

Not supported yet:

  • A goto into a statement it isn't in, or two jumps whose blocks would cross.
  • Pointer arithmetic other than on PChar ,@ on a variable, andabsolute variables.
  • Keeping a PChar into aChar array (P := A ). APChar fromStrNew orGetMem works.
  • Include files ({$I name} ).
  • {$R+} range checks on subranges: it's ignored, with a warning. Array indexes are always checked.

Never supported, since they need a real DOS PC:

  • asm andinline ,Mem (withMemW andMemL ) andPort (withPortW ),Intr andMsDos . Each gives an error saying why.
  • Interrupts: SetIntVec keeps a handler, with a warning, but never calls it.Timer interrupts shows how to rewrite a program that uses one.
  • Exec of a real DOS program.Exec('GAME.EXE') runsgame , a program built withtpc .
  • The Graph3 andTurbo3 units, kept for Turbo Pascal 3.0 programs.RscTurtle hasGraph3 's turtle routines.

fmt tidies up old sources without changing what they mean. It re-indents by the block structure (3 spaces a level, with a routine's var section, nested routines and begin ... end one level in from its heading), normalizes spacing (x := y, a, b, name: string), lowercases keywords, and spells each identifier the way it's spelled most often. Line breaks, strings and comments stay as they are, columns you lined up by hand stay lined up, and DOS line endings become UNIX ones (unless you give --crlf, for files going back to DOS).

cargo run -p ruscal -- fmt examples/database/*.pas

cargo run -p ruscal -- fmt --check $(find examples -name '*.pas' -not -path '*/ruscal/*')

cargo run -p ruscal -- fmt --crlf GAME.PAS

A typed file (file of T) written by a Turbo Pascal program is just its records' bytes. to-json reads them as a type the Pascal source declares, and prints them as JSON; from-json writes JSON back as the binary file (see Data files as JSON):

cargo run -p ruscal -- to-json examples/database/founit.pas examples/database/mark.dat
cargo run -p ruscal -- to-json examples/database/founit.pas examples/database/mark.dat --type People -o people.json
cargo run -p ruscal -- from-json examples/database/founit.pas people.json --type People -o people.dat

tpc takes the command line of Turbo Pascal's TPC.EXE, so old build scripts and habits carry over. tpc game compiles game.pas (the extension is optional, and names match ignoring case, as in DOS) and writes the executable game next to it, as TPC GAME wrote GAME.EXE. The Cargo project is built in a cache directory (~/.cache/ruscal/tpc/, on macOS too, or under $XDG_CACHE_HOME), so only the program appears beside the source.

cargo install ruscal                    # once (or --path crates/ruscal in a clone)

tpc life                                  # life.pas -> ./life
tpc -Ebin '-Uunits;lib' game              # executable in bin/, units also in units/ and lib/
tpc -Q '-$I-' backup                      # quiet, and I/O errors go to IOResult
Option Meaning
'-$<switches>' Compiler switches, as at the top of each file: '-$I-' ,'-$R+,I-' . Quote them in a Unix shell, which would read$I as a variable.
-E<dir> Where to write the executable (the directory is made if it's missing).
-U<dirs> More directories to find units in, separated by ; (quote the argument in a Unix shell).
-Q Quiet: no messages unless something goes wrong.
-B ,-M Build all / make: accepted; units are always compiled with the program.
-D ,-F ,-G… ,-I ,-L ,-O ,-T ,-V Accepted and ignored, with a note. They were about conditional defines, DOS memory, map files and the IDE's debugger.

Options start with -. TP also took /, but on Unix a / starts a path.

Units named in a uses clause are looked up (case-insensitively) as <unit>.pas next to the program, so a multi-file program runs from its main file. The standard units Crt, Dos and Graph are built into the runtime. Graph programs open a 640x480 window, and keys typed into it go to ReadKey.

Variable Effect
RUSCAL_TERM=plain Don't take over the terminal for Crt ;ReadKey reads standard input. This is automatic when stdin or stdout isn't a terminal, so you can script a program:printf 'y\nq' | ruscal run game.pas .
RUSCAL_FAST=1 Skip Delay .
RUSCAL_GRAPH=headless Draw Graph output without opening a window: for a script, a test, or a machine without a display (over SSH).ReadKey then reads standard input; withRUSCAL_GRAPH_SAVE you still get the picture.
RUSCAL_GRAPH_SAVE=screen.bmp Save the graphics screen to a BMP file at CloseGraph orHalt .
RUSCAL_DRIVE_C=/some/dir Where the DOS drive C: lives for file names likeC:\DATA\X.DAT . Without it,C: is the file system's root,/ , soC:\DATA\X.DAT is/DATA/X.DAT andGetDir shows where you really are. Any other drive letter (RUSCAL_DRIVE_A=/Volumes/USB for a stick standing in for a floppy) exists only if you set it; a file name on an unset drive isn't found. Names match files on disk ignoring case,A:X is relative to the current directory whenChDir went somewhere on drive A, and.. stops at the drive's root, as in DOS. A file name without a drive is relative to the current directory.
RUSCAL_RUNTIME=/some/dir Where generated projects find the ruscal_runtime crate (empty counts as unset). By default it'scrates/ruscal_runtime in the checkoutruscal was built from, or, for aruscal installed from crates.io,ruscal_runtime from crates.io at the same version.
RUSCAL_PRINTER=... Where the Printer unit'sLst prints: a file name (defaultprinter.txt ), or|command to pipe to a command such as|lp . SeePrinting .
  • Language spec : exactly which Turbo Pascal constructs are supported, and how closely.
  • Architecture : how Ruscal works, and why it was designed that way.
  • Rewriting code that Rust can't express : the few things that are fine in Pascal but break a rule of Rust (twovar arguments into one array, ...), and how to rewrite them. Those errors link there.
  • Printing : where thePrinter unit'sLst output goes.
  • Data files as JSON :ruscal to-json reads afile of T written by a Turbo Pascal program, andfrom-json writes one back.
  • Timer interrupts : getting a steady tick in a game without the timer interrupt, which Ruscal doesn't have.
  • Calling Rust from Turbo Pascal :external routines written in Rust, linked with{$L file.rs} as TP linked assembly, and crates from crates.io.
  • Calling Turbo Pascal from Rust : a Rust project'sbuild.rs translates a unit as part ofcargo build (orruscal build --lib unit.pas makes a library of it), andruscal_runtime::call turns its runtime errors intoErr s.
  • Ruscal's own units, whose names start with Rsc , written in Turbo Pascal, built into Ruscal (nothing to copy) and translated with the program that uses them:RscJson , reading and writing JSON, andRscTurtle , turtle graphics on top ofGraph , with Turbo Pascal 3.0's turtle routines (an example ).

Ruscal is version 0.7: it runs every program it was built for and has a large test suite, but it's young. If a program doesn't translate, or runs differently than it did in Turbo Pascal, please open an issue with the .pas file (and its units) and what you expected; the error message's file, line and column help.

To work on Ruscal itself, see CLAUDE.md for the layout and commands, the architecture for the design, and run cargo test for the whole test suite.

Ruscal is MIT licensed (see LICENSE).

Ruscal's code is its own, but we leaned on a lot of other people's work while writing it. Thank you to:

  • Free Pascal . Runningfpc -Mtp on our test programs gives us most of their expected output, so we can check that a translated program behaves as Turbo Pascal would.
  • DOSBox , which runs Turbo Pascal 7 for us. Where Free Pascal and Turbo Pascal differ, the real thing settles what a program should do.
  • Borland, for their copy of Turbo Pascal 7 on the Internet Archive .
  • daelsepara/turbo-pascal-assembly , an annotated disassembly of Turbo Pascal's System unit. It's how we know exactly howRandom works.
  • J R Stockton's Borland Pascal/Delphi Random page, and his other Pascal notes.
  • Borland, for the Turbo Pascal 7.0 manuals, which are still the best description of the language (see the References in the language spec ).
  • Dave Gillespie's p2c, the classic Pascal to C translator, for design ideas (notes/p2c.md ).
  • font8x8 (public domain), the 8x8 fontGraph draws text with.
  • The Rust crates we build on: clap ,crossterm ,minifb ,chrono andinsta .
  • Claude Fable, for the code and design reviews.
── more in #developer-tools 4 stories · sorted by recency
── more on @ruscal 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/show-hn-ruscal-a-tur…] indexed:0 read:19min 2026-11-18 · —