Repository Layout
Compiler Directory
Thecompiler/ directory contains the core compiler implementation:
Built-ins (compiler/builtins/)
Built-in APIs written in TypeScript that get precompiled. Key files:
string.ts- String and ByteString methodsarray.ts- Array methodsnumber.ts- Number methodsdate.ts- Date implementationmath.ts- Math functionsconsole.ts- Console methodsregexp.ts- Regular expression supportobject.ts- Object methodsjson.ts- JSON parsing/stringificationpromise.ts- Promise implementation- And many more…
Compiler Implementation Files
index.js- Main entry point, orchestrates all compiler steps (code in → wasm out)codegen.js- Code generation, AST → Wasm bytecode (the bulk of the work)builtins.js- Manually written built-ins (spec, custom vars, funcs)builtins_precompiled.js- Generated fromcompiler/builtins/folderprecompile.js- Tool to generatebuiltins_precompiled.jsassemble.js- Assembles Wasm ops and metadata into spec-compliant Wasm moduleopt.js- Self-made Wasm bytecode optimizercyclone.js- Wasm partial constant evaluator (fast and dangerous)havoc.js- Wasm rewrite library (wreaks havoc upon Wasm bytecode)2c.js- Custom Wasm-to-C compilerparse.js- Parser wrapper (uses Acorn or alternatives)disassemble.js- Wasm disassembler using internal debug infotypes.js- Definitions for builtin typeswasmSpec.js- “Enums” and info from Wasm specexpression.js- Maps operators to opcodesencoding.js- Utils for encoding as bytes for Wasmwrap.js- Wrapper that instantiates and produces nice exportsprefs.js- Command line argument readerpgo.js- Profile guided optimizerprototype.js- Some builtin prototype functions (legacy)
Runtime Directory
Utilities for running JS with the compiler:index.js- Main runtime entry point (this is what you want to use)repl.js- Basic REPL implementation (usesnode:repl)
Test262 Directory
Test262 runner and utilities for testing ECMAScript compliance:index.js- Main test runner with multi-threading supportread.js- Test262 test file readerharness.js- Test262 harness implementationscompare.js- Compare test resultshistory.json- Historical test resultstest262/- Cloned Test262 repository (you need to clone this)
Bench Directory
Contains example JavaScript files that work with Porffor. Good for:- Testing features
- Performance benchmarking
- Seeing what’s supported
Key File Relationships
Built-in Development Flow
- You edit files in
compiler/builtins/*.ts - Run
./porf precompileto compile them - This generates
compiler/builtins_precompiled.js - The compiler uses this when compiling user code
Compilation Flow
Where to Contribute
For most contributors, the best place to start is:compiler/builtins/
This is the most accessible area for contributions:
- Easier to understand than compiler internals
- Clear scope (implementing specific APIs)
- Direct impact on JavaScript compatibility
- Examples to learn from in existing files
Other Areas
More advanced contributions can be made to:- Compiler (
codegen.js) - Core compilation logic - Optimizer (
opt.js) - Wasm optimization passes - Test262 - Test infrastructure improvements
Next Steps
- Start Writing Built-ins
- Learn about Testing
- Review Commit Style