Island REPL

July 27, 2015

The Planck OS X ClojureScript REPL is designed to be an easy-to-use command-line app. Previously, the binary required access to an on-disk directory tree containing the ClojureScript compiler output. But, I wanted it to just be a simple monolithic binary with no external dependencies.




It turns out that, with bootstrapped ClojureScript, things are nicely abstracted so that the runtime can execute without any knowledge of the specifics of how it is being hosted. This manifests itself, for example, by cljs.js/*load-fn* which can be defined in an arbitrary fashion by client code to load the source for any given path.

Planck has been updated so that the primary runtime support (think cljs.core and other files that make things tick), is no longer read from disk, but is included in the binary itself.

Planck is not an OS X application bundle (an .app directory that can carry additional resources)—it's a command-line app. So, I simply encoded all of the ClojureScript runtime into the binary itself: There is a cool tool that ships with OS X, xxd, which can be used to convert any file into data that can be included in a C-based program. Here is an example of its output.

unsigned char foo_txt[] = {
  0x68, 0x69, 0x0a
};
unsigned int foo_txt_len = 3;

So, with a little scripting, the entirety of Planck's :output-dir can be included as an additional (gigantic) translation unit that provides the ability to retrieve the bytes for files that would have previously been on disk. The resulting binary is self-contained and can be run anywhere!

Having said that, the plan for Planck still includes the ability to let you write source files in a conventional source tree and make use of them in the Planck REPL via the normal mechanisms—(require 'foo.bar) to load a foo.bar namespace defined in foo/bar.cljs, for example.

Planck is being developed on GitHub, where the updated standalone binary can be downloaded if you are interested in trying it.

Tags: Planck ClojureScript Bootstrap