hotfpc

Hot reloading for Free Pascal. Save a unit while your program runs, and the program carries on with the new code and everything it had: its variables, objects, open files and threads. If an edit changes something the running program depends on, hotfpc names the declaration in the way and starts the program over.

A real run of the raylib example on macOS: five saves to scene.pas. The first four are each swapped into the running game about 100 ms after hotfpc sees the save; the fifth grows a variable, and the game starts over with it by itself. With raylib →

Install

brew install fpc frostney/tap/hotfpc

That command is for macOS on Apple silicon and for Linux. On an Intel Mac, Homebrew installs hotfpc but has no prebuilt fpc: the platforms page gives the steps there, says which systems have a release archive, and from which release, and hotfpc builds from source with nothing but fpc. Platforms →

Run, edit, save

$ hotfpc demo.pas
[hot] v1: built in 228.0 ms, started in 5.0 ms, 2 units of its own, watching 2 files
score   19  ####################
[hot] v2 swapped: scene: 2 functions redirected (1 with other code, 0 new), ...
score   20  *
...
[hot] restart needed: scene.Score: the declaration changed its layout or type (...)
[hot] v5 restarted: the program starts over; 387.0 ms after the save was seen (...)

Every save is swapped in, or restarts the program, or leaves it running with fpc’s errors. What a save does →

Questions

What is hotfpc?

Hot reloading for Free Pascal. You run your program under hotfpc instead of building and starting it yourself. When you save a unit, hotfpc compiles it and the running program carries on with the new code and everything it had: its variables, objects, open files and threads.

Do I have to change my program?

No. hotfpc builds the program with your fpc and your options, and adds a small unit, the agent, with fpc’s -Fa option. Keep the code you want to change in units: the main program’s block is already running and keeps its old code.

What happens when an edit can’t be swapped in?

Some edits change what the running state is made of, such as a variable’s size, a record’s fields or a class’s virtual methods. hotfpc names the declaration in the way and starts the program over with the new code. With --no-restart, the program keeps running its old code instead.

Which systems and compilers does it support?

Programs for macOS on arm64 and x86-64, Linux on x86-64 and arm64, and Windows on x86-64, natively or under Wine, with Free Pascal 3.2.2 or later. hotfpc compiles its agent with your fpc, so one hotfpc works with every fpc from 3.2.2 on.