deniz.in

Markets

Weather

Loading weather

· via Hacker News – Front Page (native)

zipc compiles Prolog to Clocksin's ZIP machine as a possible trilog backend

A work-in-progress project called zipc compiles Prolog programs to Clocksin's 1984 ZIP abstract machine and runs them on a C virtual machine, aiming to become the backend of the trilog runtime.

zipc compiles Prolog to Clocksin's ZIP machine as a possible trilog backend

What zipc is

A project called zipc recently reached the front page of Hacker News. According to its GitHub page, it is a work-in-progress pairing of two components: a compiler that translates Prolog into instructions for the ZIP abstract machine, and a virtual machine written in C that executes the result. The author's immediate goal, as described on the repository, is to get the VM working well enough to measure it against the runtime that trilog — the Prolog system the project may eventually serve — uses today.

The ZIP machine itself is a relic of the era when researchers were working out how to run Prolog efficiently on conventional hardware. Per the repository, it is the abstract machine from Clocksin's 1984 paper "Design and Simulation of a Sequential Prolog Machine", and copies of the relevant papers are included in the project's documentation directory for anyone who wants to follow along.

How the pipeline works

zipc's two halves are built in different languages, which is part of what makes the setup tidy. The compiler is written in Prolog and runs on Scryer Prolog, a contemporary Prolog implementation; it emits a binary image of the compiled program. The C virtual machine in the project's source directory then loads that image and executes it. In effect it is a classic ahead-of-time arrangement: compile once to abstract-machine code, then run on a small native runtime.

Why compile instead of interpret

The motivation comes from trilog's current design. As the GitHub page explains, trilog treats program clauses as data and interprets them directly via the ABC algorithm rather than compiling them ahead of time. Compiling those same clauses down to ZIP instructions should let identical programs execute with fewer instructions and a smaller memory footprint, which the author expects to benefit the kind of work trilog is mainly intended for. The repository does not detail what that target workload actually is.

An uncommon machine choice

For background, most widely used Prolog implementations have compiled to the Warren Abstract Machine — the design David H. D. Warren described in 1983 — or its descendants since the mid-1980s. ZIP, from roughly the same period, never became the default target. That makes zipc an unusual experiment: rather than reaching for the standard compilation model, it revives a road-not-taken design and sets out to test whether it still pays off in practice on modern hardware.

What happens next

The author is explicit that the plan is unsettled. If the minimum viable version of the VM succeeds, zipc could become trilog's backend; if not, it may simply continue as a separate, faster Prolog runtime that compiles programs instead of interpreting them.

Why it matters

For people who follow language runtimes, the project is interesting on three counts. It revives a largely historical abstract machine rather than defaulting to the WAM, giving a modern data point on a 1980s alternative. It uses Prolog itself to build the compiler, running on Scryer and keeping the whole stack close to the language it serves. And it is framed from the start as a comparison exercise against trilog's existing interpreter, which promises actual numbers rather than claims: the same programs run under two execution models, with instruction counts and memory use on the line. If the compiled route wins, trilog gains a faster backend; even if it does not, the results will still say something useful about where Prolog performance actually comes from — the machine model, or the engineering around it.

  • #prolog
  • #compilers
  • #virtual-machines
  • #c
  • #open-source

Related posts