{"slug": "show-hn-ruscal-a-turbo-pascal-to-rust-transpiler", "title": "Show HN: Ruscal: A Turbo Pascal to Rust Transpiler", "summary": "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`.", "body_md": "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.\n\nRuscal writes a small Cargo project for each program so you can build and run your old Turbo Pascal code natively.\n\n- You can continue editing the Turbo Pascal code and transpile it every time.\n- You can transpile your Turbo Pascal code to Rust once and then edit the Rust going forward.\n- 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.\n- You can call out to Rust from a Turbo Pascal program.\n- You can call into Turbo Pascal from a Rust program.\n- You can read old binary data files written by Turbo Pascal.\n- You can also translate those files to and from JSON.\n- There's even a pretty printer for reformatting your Turbo Pascal code.\n\nRuscal was written by Claude Code Opus with help from Claude Code Fable and JJ Behrens.\n\nBy the way, Ruscal is pronounced \"rust-CAL\", with the stress on \"CAL\", as in \"Pascal\".\n\nYou need a Rust toolchain (see [Requirements](#requirements)).\n\nInstall Ruscal from crates.io; you don't need this repository:\n\n```\ncargo install ruscal\n```\n\nThen, next to your program (`hello.pas` here):\n\n``` js\nprogram Hello;\nvar\n   Name: string;\nbegin\n   Write('What is your name? ');\n   ReadLn(Name);\n   WriteLn('Hello, ', Name, '!');\nend.\nruscal run hello.pas       # translate it to Rust, build it and run it\nruscal emit hello.pas      # just print the Rust\n```\n\n`run` puts a small Cargo project in `out/hello/` and runs it (see\n[Usage](#usage)). A program finds its units' source files next to it.\n\nDeclare the routine `external`, and name the Rust file that has it with\n`{$L ...}`, as Turbo Pascal linked assembly. `greet.pas`:\n\n``` js\nprogram Greet;\n{$L greet.rs}\n\nprocedure SayHello(const Name: string); external;\n\nbegin\n   SayHello('Turbo Pascal');\nend.\n```\n\nand `greet.rs`, next to it:\n\n```\nuse ruscal_runtime::prelude::*;\n\npub fn say_hello(name: &PString) {\n    pwriteln!(\"Hello, \", name, \", from Rust!\");\n}\n```\n\n`ruscal run greet.pas` prints `Hello, Turbo Pascal, from Rust!`. A\nPascal `string` is a `PString` in Rust; `ruscal emit greet.pas` shows\nthe signature each `external` routine needs.\n[Calling Rust from Turbo Pascal](https://github.com/jjinux/ruscal/blob/main/docs/calling_rust.md) has the rest.\n\nIn your Rust project, add Ruscal's runtime, and Ruscal itself to translate the Pascal when it builds (both the same version):\n\n```\ncargo add ruscal_runtime@=0.7.0\ncargo add --build ruscal@=0.7.0 --no-default-features\n```\n\nand in `Cargo.toml`, let Pascal's integer arithmetic wrap around, as it\ndid in Turbo Pascal:\n\n```\n[profile.dev]\noverflow-checks = false\n```\n\nWrite the Pascal as a unit, `pascal/greeter.pas`:\n\n``` js\nunit Greeter;\n\ninterface\n\n   procedure SayHello(const Name: string);\n   function Square(N: Integer): Integer;\n\nimplementation\n\n   procedure SayHello(const Name: string);\n      begin\n         WriteLn('Hello, ', Name, ', from Turbo Pascal!');\n      end;\n\n   function Square(N: Integer): Integer;\n      begin\n         Square := N * N;\n      end;\n\nend.\n```\n\ntranslate it in `build.rs`:\n\n```\nfn main() {\n    ruscal::build::library(\"pascal/greeter.pas\").unwrap();\n}\n```\n\nand call it from `src/main.rs`:\n\n```\nruscal_runtime::include_library!(greeter);\n\nuse ruscal_runtime::prelude::PString;\nuse ruscal_runtime::{RuntimeError, call};\n\nfn main() -> Result<(), RuntimeError> {\n    // Runs the units' initialization parts.\n    let _units = call(greeter::GreeterContext::new)?;\n    // `call` turns a Pascal runtime error into an `Err`.\n    call(|| greeter::say_hello(&PString::from(\"Rust\")))?;\n    let n = call(|| greeter::square(12))?;\n    println!(\"12 squared is {n}, says Pascal\");\n    Ok(())\n}\n```\n\n`cargo run` prints `Hello, Rust, from Turbo Pascal!` and `12 squared is 144, says Pascal`. [Calling Turbo Pascal from Rust](https://github.com/jjinux/ruscal/blob/main/docs/embedding.md)\nhas the rest.\n\nClone the repository to run its examples:\n\n```\ngit clone https://github.com/jjinux/ruscal.git\ncd ruscal\n```\n\nIf you can open a window (on Linux, that needs the packages under\n[Requirements](#requirements)), try turtle graphics (press a key after\neach drawing):\n\n```\ncargo run -p ruscal -- run examples/ruscal/turtles.pas\n```\n\nOr, needing only a terminal, try a Game of Life written in Turbo Pascal\nin 1997 (follow its menu; to quit while it runs, press `p`, then `5`,\nthen Enter):\n\n```\ncargo run -p ruscal -- run examples/life.pas\n```\n\n[Examples](#examples) lists the rest: an airport simulation, a clock,\ntic-tac-toe and more.\n\nMy 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!\n\n- Rust 1.88 or later (the crates use the 2024 edition and its `let` chains), from[rustup](https://rustup.rs/) , with`rustfmt` (`rustup component add rustfmt` ), which tidies the generated Rust; without it the Rust still\nworks, unformatted.\n- macOS or Linux (developed on macOS; CI runs on Linux). On Linux, `Graph` programs need the\nX11 and Wayland development packages for their window:`libx11-dev libxcursor-dev libxkbcommon-dev libwayland-dev` on Debian or\nUbuntu.\n- `Graph` programs open a 640x480 window (or draw without one: see`RUSCAL_GRAPH=headless` under[Environment variables](#environment-variables) ).\n\nFrom the repository root:\n\n```\n# Transpile, build and run a program. The Cargo project goes in out/<name>/.\ncargo run -p ruscal -- run examples/life.pas\n\n# Arguments after `--` go to the Pascal program (ParamStr / ParamCount).\ncargo run -p ruscal -- run myprog.pas -- first second\n\n# Just print the generated Rust.\ncargo run -p ruscal -- emit examples/paper.pas\n\n# Transpile and build, without running. `-o` picks the project directory\n# (for `run` too).\ncargo run -p ruscal -- build examples/magic_square.pas -o /tmp/magic\n```\n\nThe Cargo project goes in `out/<name>/` under the directory you run the\ncommand from (`-o` picks another), and the executable is\n`out/<name>/target/debug/<name>`. A program's own files (` scores.dat`,\n`printer.txt`) are written in the current directory, as they were in DOS.\n\nOld sources with DOS (`\\r\\n`) line endings are fine everywhere: the\ntranspiler, `Readln` on standard input and text files, and `fmt` (which\nwrites UNIX line endings, or DOS ones with `--crlf`).\n\nOr install the tools once, which puts `ruscal` and `tpc` (below) in\n`~/.cargo/bin` (put it on your `PATH` if it isn't already), and use\n`ruscal run foo.pas`:\n\n```\n# To use Ruscal: from crates.io. Generated projects depend on the\n# `ruscal_runtime` of the same version, from crates.io too, so building\n# one needs the network unless Cargo has it already. Run it again to\n# update; `ruscal run` then moves a project to the new version.\ncargo install ruscal\n\n# To work on Ruscal itself: from your clone, so the installed `ruscal` has\n# your changes. Each generated project depends on the clone's\n# `crates/ruscal_runtime` by path, so keep the clone where it is.\ncargo install --path crates/ruscal\n```\n\n`RUSCAL_RUNTIME` can point generated projects at another\n`crates/ruscal_runtime` instead (in a checkout, the crate takes its\nedition and version from the workspace around it).\n\n`examples/` holds the Turbo Pascal programs this project was built to run,\nwritten in 1996-97.\nRun them from the repository root:\n\n```\n# Text-mode programs (Crt)\ncargo run -p ruscal -- run examples/blkjack.pas        # Blackjack\ncargo run -p ruscal -- run examples/paper.pas          # Paper, scissors, rock\ncargo run -p ruscal -- run examples/life.pas           # The Game of Life\ncargo run -p ruscal -- run examples/magic_square.pas   # Solves a 4x4 magic square puzzle\ncargo run -p ruscal -- run examples/gmscode.pas        # Encodes what you type as you type it\n# A DOS menu, whose games ran from A:\\SHANNON: build them there with tpc\n# (see `tpc` below), then map drive A: to out/a. (Exec of GAME.EXE runs\n# the program `game`.)\ncargo run -p ruscal --bin tpc -- -Eout/a/shannon examples/life.pas\ncargo run -p ruscal --bin tpc -- -Eout/a/shannon examples/gmscode.pas\ncargo run -p ruscal --bin tpc -- -Eout/a/shannon examples/paper.pas\ncargo run -p ruscal --bin tpc -- -Eout/a/shannon examples/blkjack.pas\ncargo run -p ruscal --bin tpc -- -Eout/a/shannon examples/airport/airport4.pas\nRUSCAL_DRIVE_A=out/a cargo run -p ruscal -- run examples/menu.pas\n\n# Multi-file programs: run the main file, and its units come along\ncargo run -p ruscal -- run examples/airport/airport4.pas   # An airport runway simulation\n\n# A record filing system. Drive C: is mapped to its directory, so when it\n# asks which file to open, type `mark` to load the sample data (mark.dat, mark.key).\nRUSCAL_DRIVE_C=examples/database cargo run -p ruscal -- run examples/database/filesys.pas\n\n# Graphics (Graph): these open a window\ncargo run -p ruscal -- run examples/clock/tester.pas   # A clock whose hands run backwards\n# Tic-tac-toe expects to live in A:\\TICTAC, so map drive A: to examples/.\nRUSCAL_DRIVE_A=examples cargo run -p ruscal -- run examples/tictac/tictac.pas\n```\n\nThe environment variable goes before `cargo`, so it applies to the whole\ncommand (and to the program it runs).\n\n`examples/ruscal/` holds examples written for Ruscal:\n\n```\n# Turtle graphics with RscTurtle: a Koch snowflake, a tree and a spiral,\n# each waiting for a key. Without a window, feed it the three keys and save\n# the last screen:\n#   printf 'xxx' | RUSCAL_GRAPH=headless RUSCAL_GRAPH_SAVE=screen.bmp \\\n#     cargo run -p ruscal -- run examples/ruscal/turtles.pas\n# It prints nothing; open screen.bmp to see the spiral.\ncargo run -p ruscal -- run examples/ruscal/turtles.pas\n\n# Turbo Pascal calling Rust: calls_rust.pas links calls_rust.rs with {$L},\n# and the Rust calls a Pascal function back to sort\ncargo run -p ruscal -- run examples/ruscal/calls_rust.pas\n\n# Rust calling Turbo Pascal: a Rust project whose build.rs translates\n# pascal/bstunit.pas (from 1997) as part of `cargo build`, then\n# uses its binary search tree: it inserts four IDs, searches for one and\n# deletes one, printing each result (src/main.rs is the Rust side)\ncargo run --manifest-path examples/ruscal/rust_calls_pascal/Cargo.toml\n```\n\nTo start a project of your own from one of them, copy it out of a clone\n(for the two `.pas` examples, install `ruscal` first, as above):\n\n- `turtles.pas` on its own, run with`ruscal run turtles.pas` : units whose\nnames start with`Rsc` are built into Ruscal, so there's nothing else\nto copy.\n- `calls_rust.pas` with`calls_rust.rs` beside it, run with`ruscal run calls_rust.pas` .\n- The whole `rust_calls_pascal` directory (without`target/` , if you've\nbuilt it), run with`cargo run` , changing the two`path` dependencies\nin its`Cargo.toml` to crates.io ones, as the comment at its top shows\n(`ruscal_runtime = \"=0.7.0\"` ; see[Calling Turbo Pascal from Rust](https://github.com/jjinux/ruscal/blob/main/docs/embedding.md) ).\n\n`ruscal run` and `build` put the Cargo project in `out/` in the directory\nyou run them from, so add `out/` to your `.gitignore` (and `target/` for\na Rust project like `rust_calls_pascal`).\n\nRuscal reads Turbo Pascal 7.0 syntax and covers most of Turbo Pascal 5.5\nto 7.0 as students used it. It runs every program in `examples/`. The\n[language spec](https://github.com/jjinux/ruscal/blob/main/docs/language_spec.md) has the details, and\n[`TODO.md`](https://github.com/jjinux/ruscal/blob/main/TODO.md), the development plan, says what's next.\n\nThe standard units, for a reader who knows Rust but not Turbo Pascal:\n`Crt` is the text screen and keyboard (colors, cursor, `ReadKey`), `Dos`\nis dates, times, files and directories, and `Graph` is Borland's BGI\ngraphics. Ruscal provides all three in its runtime.\n\n- **The language:** the usual types (`Integer` ,`LongInt` ,`Real` ,`Char` ,`Boolean` and the rest), strings, arrays, records (variant records too),\nenums, subranges, sets, typed constants,`with` ,`case` ,`Break` and`Continue` , nested and recursive procedures,`var` and`const` parameters, open array parameters (`a: array of Integer` ), and\nprocedural types.\n- **Units:** a program pulls in its units' source files, which are\ntranslated with it.\n- **Objects:** inheritance, virtual methods, constructors and destructors,`inherited` , polymorphic pointers and`TypeOf` .\n- **Pointers:**`New` /`Dispose` , linked lists and trees, the untyped`Pointer` ,`GetMem` /`FreeMem` , and`PChar` strings with their pointer\narithmetic.\n- **`goto`:** a jump forward or back within a statement list, translated\nas Rust's labeled blocks and loops.\n- **Files:** text files, typed files (`file of T` ) and untyped files.\nTyped files use Turbo Pascal's own byte layout (6-byte`Real` s, and`Single` ,`Double` and`Extended` as the 8087 stored them,`string[n]` as n+1 bytes, unpadded records), so a program can read the\ndata files it wrote decades ago.`{$I-}` and`IOResult` work.\n- **Standard units:**`Crt` ,`Dos` ,`Graph` (in a window),`Printer` ,`Overlay` ,`Strings` and`WinDos` .\n- **Ruscal's own units:**[`RscJson`](https://github.com/jjinux/ruscal/blob/main/docs/rsc_json.md) for reading and\nwriting JSON, and[`RscTurtle`](https://github.com/jjinux/ruscal/blob/main/docs/rsc_turtle.md) for turtle graphics,\nwith Turbo Pascal 3.0's turtle routines on top of`Graph` .\n- **Turbo Pascal's behavior:** runtime errors print Turbo Pascal's message\nand exit code (`Runtime error 201: Range check error ...` ),`{$Q+}` checks for overflow,`Random` gives the same numbers as Turbo Pascal,\nand DOS file names like`C:\\DATA\\X.DAT` go to directories you choose\n(see[Environment variables](#environment-variables) ).\n- **Calling Rust:** Turbo Pascal code can call`external` routines written\nin Rust, linked with`{$L file.rs}` (see[Calling Rust](https://github.com/jjinux/ruscal/blob/main/docs/calling_rust.md) ).\n- **Calling Turbo Pascal from Rust:** a Rust project's`build.rs` translates a unit while`cargo build` runs, or`ruscal build --lib` makes a library of one (see[Calling Turbo Pascal from Rust](https://github.com/jjinux/ruscal/blob/main/docs/embedding.md) ). There's an\nexample of each way in`examples/ruscal/` .\n- **Faked, so old programs still run:**`Lst` prints to a file or a\ncommand (see[Printing](https://github.com/jjinux/ruscal/blob/main/docs/printing.md) ), overlays need no`.OVR` file,`MemAvail` reports plenty of memory, and interrupt vectors keep\nthe handlers set in them (which never run).\n\nNot supported yet:\n\n- A `goto` into a statement it isn't in, or two jumps whose blocks would\ncross.\n- Pointer arithmetic other than on `PChar` ,`@` on a variable, and`absolute` variables.\n- Keeping a `PChar` into a`Char` array (`P := A` ). A`PChar` from`StrNew` or`GetMem` works.\n- Include files (`{$I name}` ).\n- `{$R+}` range checks on subranges: it's ignored, with a warning. Array\nindexes are always checked.\n\nNever supported, since they need a real DOS PC:\n\n- `asm` and`inline` ,`Mem` (with`MemW` and`MemL` ) and`Port` (with`PortW` ),`Intr` and`MsDos` . Each gives an error saying why.\n- Interrupts: `SetIntVec` keeps a handler, with a warning, but never\ncalls it.[Timer interrupts](https://github.com/jjinux/ruscal/blob/main/docs/timer_interrupts.md) shows how to\nrewrite a program that uses one.\n- `Exec` of a real DOS program.`Exec('GAME.EXE')` runs`game` , a\nprogram built with`tpc` .\n- The `Graph3` and`Turbo3` units, kept for Turbo Pascal 3.0 programs.`RscTurtle` has`Graph3` 's turtle routines.\n\n`fmt` tidies up old sources without changing what they mean. It re-indents\nby the block structure (3 spaces a level, with a routine's `var` section,\nnested routines and `begin ... end` one level in from its heading),\nnormalizes spacing (`x := y`, `a, b`, `name: string`), lowercases keywords,\nand spells each identifier the way it's spelled most often. Line breaks,\nstrings and comments stay as they are, columns you lined up by hand stay\nlined up, and DOS line endings become UNIX ones (unless you give `--crlf`,\nfor files going back to DOS).\n\n```\n# Format files in place, printing the ones that changed. Give a program and\n# its units together, so each name is spelled the same in all of them.\ncargo run -p ruscal -- fmt examples/database/*.pas\n\n# Only check: list the files that would change, and fail if there are any\n# (handy in CI; this repository's tests check the user's examples this way,\n# leaving out examples/ruscal, whose programs are formatted on their own).\ncargo run -p ruscal -- fmt --check $(find examples -name '*.pas' -not -path '*/ruscal/*')\n\n# Keep DOS line endings, for files that Turbo Pascal in DOS will read.\ncargo run -p ruscal -- fmt --crlf GAME.PAS\n```\n\nA typed file (`file of T`) written by a Turbo Pascal program is just its\nrecords' bytes. `to-json` reads them as a type the Pascal source declares,\nand prints them as JSON; `from-json` writes JSON back as the binary file\n(see [Data files as JSON](https://github.com/jjinux/ruscal/blob/main/docs/data_files.md)):\n\n```\n# The user's 1997 database file: founit.pas declares its record type.\ncargo run -p ruscal -- to-json examples/database/founit.pas examples/database/mark.dat\n# Say which type when the source has several; -o writes to a file.\ncargo run -p ruscal -- to-json examples/database/founit.pas examples/database/mark.dat --type People -o people.json\n# And back, after editing people.json (-o is required here).\ncargo run -p ruscal -- from-json examples/database/founit.pas people.json --type People -o people.dat\n```\n\n`tpc` takes the command line of Turbo Pascal's `TPC.EXE`, so old build\nscripts and habits carry over. `tpc game` compiles `game.pas` (the extension\nis optional, and names match ignoring case, as in DOS) and writes the\nexecutable `game` next to it, as `TPC GAME` wrote `GAME.EXE`. The Cargo\nproject is built in a cache directory (`~/.cache/ruscal/tpc/`, on macOS\ntoo, or under `$XDG_CACHE_HOME`), so only the program appears beside the\nsource.\n\n```\ncargo install ruscal                    # once (or --path crates/ruscal in a clone)\n\ntpc life                                  # life.pas -> ./life\ntpc -Ebin '-Uunits;lib' game              # executable in bin/, units also in units/ and lib/\ntpc -Q '-$I-' backup                      # quiet, and I/O errors go to IOResult\n```\n\n| Option | Meaning | \n|---|---|\n| `'-$<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. | \n| `-E<dir>` | Where to write the executable (the directory is made if it's missing). | \n| `-U<dirs>` | More directories to find units in, separated by `;` (quote the argument in a Unix shell). | \n| `-Q` | Quiet: no messages unless something goes wrong. | \n| `-B` ,`-M` | Build all / make: accepted; units are always compiled with the program. | \n| `-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. | \n\nOptions start with `-`. TP also took `/`, but on Unix a `/` starts a path.\n\nUnits named in a `uses` clause are looked up (case-insensitively) as\n`<unit>.pas` next to the program, so a multi-file program runs from its main\nfile. The standard units `Crt`, `Dos` and `Graph` are built into the runtime.\n`Graph` programs open a 640x480 window, and keys typed into it go to\n`ReadKey`.\n\n| Variable | Effect | \n|---|---|\n| `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` . | \n| `RUSCAL_FAST=1` | Skip `Delay` . | \n| `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; with`RUSCAL_GRAPH_SAVE` you still get the picture. | \n| `RUSCAL_GRAPH_SAVE=screen.bmp` | Save the graphics screen to a BMP file at `CloseGraph` or`Halt` . | \n| `RUSCAL_DRIVE_C=/some/dir` | Where the DOS drive `C:` lives for file names like`C:\\DATA\\X.DAT` . Without it,`C:` is the file system's root,`/` , so`C:\\DATA\\X.DAT` is`/DATA/X.DAT` and`GetDir` 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 when`ChDir` 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. | \n| `RUSCAL_RUNTIME=/some/dir` | Where generated projects find the `ruscal_runtime` crate (empty counts as unset). By default it's`crates/ruscal_runtime` in the checkout`ruscal` was built from, or, for a`ruscal` installed from crates.io,`ruscal_runtime` from crates.io at the same version. | \n| `RUSCAL_PRINTER=...` | Where the `Printer` unit's`Lst` prints: a file name (default`printer.txt` ), or`\\|command` to pipe to a command such as`\\|lp` . See[Printing](https://github.com/jjinux/ruscal/blob/main/docs/printing.md) . | \n\n- [Language spec](https://github.com/jjinux/ruscal/blob/main/docs/language_spec.md) : exactly which Turbo Pascal\nconstructs are supported, and how closely.\n- [Architecture](https://github.com/jjinux/ruscal/blob/main/docs/architecture.md) : how Ruscal works, and why it was\ndesigned that way.\n- [Rewriting code that Rust can't express](https://github.com/jjinux/ruscal/blob/main/docs/rust_limits.md) : the few\nthings that are fine in Pascal but break a rule of Rust (two`var` arguments into one array, ...), and how to rewrite them. Those errors\nlink there.\n- [Printing](https://github.com/jjinux/ruscal/blob/main/docs/printing.md) : where the`Printer` unit's`Lst` output goes.\n- [Data files as JSON](https://github.com/jjinux/ruscal/blob/main/docs/data_files.md) :`ruscal to-json` reads a`file of T` written by a Turbo Pascal program, and`from-json` writes\none back.\n- [Timer interrupts](https://github.com/jjinux/ruscal/blob/main/docs/timer_interrupts.md) : getting a steady tick in a\ngame without the timer interrupt, which Ruscal doesn't have.\n- [Calling Rust from Turbo Pascal](https://github.com/jjinux/ruscal/blob/main/docs/calling_rust.md) :`external` routines written in Rust, linked with`{$L file.rs}` as TP linked\nassembly, and crates from crates.io.\n- [Calling Turbo Pascal from Rust](https://github.com/jjinux/ruscal/blob/main/docs/embedding.md) : a Rust project's`build.rs` translates a unit as part of`cargo build` (or`ruscal build --lib unit.pas` makes a library of it), and`ruscal_runtime::call` turns its runtime errors into`Err` s.\n- Ruscal's own units, whose names start with `Rsc` , written in Turbo\nPascal, built into Ruscal (nothing to copy) and translated with the\nprogram that uses them:[RscJson](https://github.com/jjinux/ruscal/blob/main/docs/rsc_json.md) , reading and writing JSON, and[RscTurtle](https://github.com/jjinux/ruscal/blob/main/docs/rsc_turtle.md) , turtle graphics on top of`Graph` , with\nTurbo Pascal 3.0's turtle routines ([an example](https://github.com/jjinux/ruscal/blob/main/examples/ruscal/turtles.pas) ).\n\nRuscal is version 0.7: it runs every program it was built for and has\na large test suite, but it's young. If a program doesn't translate, or\nruns differently than it did in Turbo Pascal, please\n[open an issue](https://github.com/jjinux/ruscal/issues) with the `.pas`\nfile (and its units) and what you expected; the error message's file,\nline and column help.\n\nTo work on Ruscal itself, see [`CLAUDE.md`](https://github.com/jjinux/ruscal/blob/main/CLAUDE.md) for the layout and\ncommands, the [architecture](https://github.com/jjinux/ruscal/blob/main/docs/architecture.md) for the design, and run\n`cargo test` for the whole test suite.\n\nRuscal is MIT licensed (see [`LICENSE`](https://github.com/jjinux/ruscal/blob/main/LICENSE)).\n\nRuscal's code is its own, but we leaned on a lot of other people's work while writing it. Thank you to:\n\n- [Free Pascal](https://www.freepascal.org/) . Running`fpc -Mtp` on our\ntest programs gives us most of their expected output, so we can check\nthat a translated program behaves as Turbo Pascal would.\n- [DOSBox](https://www.dosbox.com/) , which runs Turbo Pascal 7 for us.\nWhere Free Pascal and Turbo Pascal differ, the real thing settles what a\nprogram should do.\n- Borland, for their copy of Turbo Pascal 7 on the\n[Internet Archive](https://archive.org/details/tp_20240418) .\n- [daelsepara/turbo-pascal-assembly](https://github.com/daelsepara/turbo-pascal-assembly) ,\nan annotated disassembly of Turbo Pascal's System unit. It's how we know\nexactly how`Random` works.\n- J R Stockton's\n[Borland Pascal/Delphi Random](https://people.cs.nycu.edu.tw/~tsaiwn/sisc/runtime_error_200_div_by_0/www.merlyn.demon.co.uk/pas-rand.htm) page, and his other Pascal notes.\n- Borland, for the Turbo Pascal 7.0 manuals, which are still the best\ndescription of the language (see the References in the\n[language spec](https://github.com/jjinux/ruscal/blob/main/docs/language_spec.md) ).\n- Dave Gillespie's p2c, the classic Pascal to C translator, for design\nideas (`notes/p2c.md` ).\n- [font8x8](https://github.com/dhepper/font8x8) (public domain), the 8x8\nfont`Graph` draws text with.\n- The Rust crates we build on: [clap](https://crates.io/crates/clap) ,[crossterm](https://crates.io/crates/crossterm) ,[minifb](https://crates.io/crates/minifb) ,[chrono](https://crates.io/crates/chrono) and[insta](https://crates.io/crates/insta) .\n- Claude Fable, for the code and design reviews.", "url": "https://wpnews.pro/news/show-hn-ruscal-a-turbo-pascal-to-rust-transpiler", "canonical_source": "https://github.com/jjinux/ruscal/", "published_at": "2026-11-18 22:58:55+00:00", "updated_at": "2026-11-18 23:15:28.454630+00:00", "lang": "en", "topics": ["developer-tools"], "entities": ["Ruscal", "Turbo Pascal", "Rust", "Claude Code Opus", "Claude Code Fable", "JJ Behrens", "crates.io", "Cargo"], "also_reported_by": [], "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", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/show-hn-ruscal-a-turbo-pascal-to-rust-transpiler", "markdown": "https://wpnews.pro/news/show-hn-ruscal-a-turbo-pascal-to-rust-transpiler.md", "text": "https://wpnews.pro/news/show-hn-ruscal-a-turbo-pascal-to-rust-transpiler.txt", "jsonld": "https://wpnews.pro/news/show-hn-ruscal-a-turbo-pascal-to-rust-transpiler.jsonld"}}