explaingit

canadahonk/porffor

4,645JavaScriptAudience · developerComplexity · 5/5Setup · moderate

TLDR

An experimental ahead-of-time compiler that turns JavaScript and TypeScript into WebAssembly or native C binaries before running, no interpreter or JIT involved at runtime. A research project, not production-ready.

Mindmap

mindmap
  root((Porffor))
    What it does
      Ahead-of-time compilation
      JS to WebAssembly
      JS to native binary
    How it works
      Acorn JS parser
      Custom Wasm bytecode
      No JIT at runtime
    CLI capabilities
      Run JS files
      Compile to Wasm file
      Compile to native binary
    Status
      Research project
      Partial JS spec support
      Test262 pass rate metric
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Compile a JavaScript file to a standalone WebAssembly binary that runs without a JavaScript runtime.

USE CASE 2

Compile TypeScript or JavaScript to a native executable using Porffor's C backend and Clang or GCC.

USE CASE 3

Experiment with ahead-of-time JavaScript compilation to understand how JS engines work under the hood.

Tech stack

JavaScriptTypeScriptWebAssemblyCnpmAcornClangGCC

Getting it running

Difficulty · moderate Time to first run · 30min

Research project, many JavaScript features are not yet supported, check the bench directory for currently working examples.

In plain English

Porffor is an experimental JavaScript and TypeScript compiler that converts code to WebAssembly or native C binaries before it runs, rather than interpreting or compiling it at the moment of execution. This approach is called ahead-of-time compilation. The project describes itself as a research project, not intended for production use yet. Most JavaScript engines work by interpreting code on the fly or compiling it just in time while it runs. Porffor does all the compilation work upfront, so there is no interpreter or just-in-time compiler involved when the output actually executes. The generated WebAssembly includes no boilerplate runtime code and requires as few external imports as possible. Only input and output operations are pulled from the host environment. The compiler is built almost entirely from scratch in JavaScript. It uses the Acorn parser to read JavaScript source code into a syntax tree, then generates WebAssembly bytecode directly without relying on tools like Binaryen. The codebase includes its own WebAssembly optimizer, a partial constant evaluator, a WebAssembly disassembler, and a custom WebAssembly-to-C compiler called 2c. The command-line tool is available through npm. It can run JavaScript files directly, open a REPL, compile code to WebAssembly files, compile to native executables using a C compiler like Clang or GCC, or print C source code to standard output. The README is upfront that many JavaScript features are not yet supported, and it points to the bench directory for examples of what currently works. Versioning encodes the Test262 pass percentage in the minor version number, providing a public measure of how much of the JavaScript specification the compiler supports at any given point in time. The name comes from the Welsh word for purple. The project is released publicly on GitHub.

Copy-paste prompts

Prompt 1
Using Porffor, compile my JavaScript function to a WebAssembly file and show me the command to run it outside a browser.
Prompt 2
How do I use Porffor's CLI to compile a TypeScript file to a native binary with Clang? Walk me through the steps.
Prompt 3
What JavaScript features does Porffor currently support? Point me to the bench directory examples so I can see what works today.
Prompt 4
Help me install Porffor from npm and write a simple script it can compile to WebAssembly without hitting unsupported features.
Open on GitHub → Explain another repo

← canadahonk on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.