MCPcopy Create free account
hub / github.com/SeaOfNodes/Simple

github.com/SeaOfNodes/Simple @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
43,065 symbols 138,679 edges 2,652 files ⚖ Apache-2.0 3,287 documented · 8% ● updated 4d agolinear-chapter20 · 2025-02-25★ 9454 open issues

Browse by type

⨍ Functions 39,685◇ Types & classes 3,380
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Simple

English | 日本語

A Simple showcase for the Sea-of-Nodes compiler IR

This repo is intended to demonstrate the Sea-of-Nodes compiler IR.

The Sea-of-Nodes is the core IR inside of HotSpot's C2 compiler and Google's V8 compiler and Sun/Oracle's Graal compiler.

Since we are showcasing the SoN IR, the language being implemented is less important. We're using a very simple language similar to C or Java, but with far fewer features. Simple is strongly typed, object-oriented, with first-class functions not closures. Object references are pointers, and null pointer exceptions are disallowed by the typing system. Arrays will probably be range-checked at some point, making Simple a fully safe language. Simple has a minimal syntax that can be parsed with a recursive descent parser.

The Sea-of-Nodes is used for machine code generation in these industrial strength systems - but for this demonstration the backend is both difficult and less important. This repo targets x86-64, RISC-V and ARM64 with ahead-of-time compilation - but with an eye towards JIT compilation.

This repo also is not intended to be a complete language in any sense, and so the backend starts with a Java evaluator (first introduced in Chapter 8) that directly interprets the SoN IR. Code generation first appears in Chapter 19.

Chapters

Download dependencies once with make libs (or make init; make lib remains an alias). Other Make targets use the local lib/ caches and never download. For Chapter 31's graphics and audio, use make -C chapter31 libs while online; those cached sources survive make clean for later offline builds.

The following is a rough plan, subject to change.

Each chapter will be self-sufficient and complete; in the sense that each chapter will fully implement a subset of the Simple language, and include everything that was created in the previous chapter. Each chapter will also include a detailed commentary on relevant aspects of the Sea Of Nodes intermediate representation.

The Simple language is styled after a subset of C or Java.

  • Chapter 1: Script that returns an integer literal, i.e., an empty function that takes no arguments and returns a single integer value. The return statement.
  • Chapter 2: Simple binary arithmetic such as addition, subtraction, multiplication, division with constants. Peephole optimization / simple constant folding.
  • Chapter 3: Local variables, and assignment statements. Read on RHS, SSA, more peephole optimization if local is a constant.
  • Chapter 4: A non-constant external variable input named arg. Binary and Comparison operators involving constants and arg. Non-zero values will be truthy. Peephole optimizations involving algebraic simplifications.
  • Chapter 5: if statement. CFG construction.
  • Chapter 6: Peephole optimization around dead control flow.
  • Chapter 7: while statement; looping constructs - eager phi approach.
  • Chapter 8: Looping constructs continued, lazy phi creation, break and continue statements.
  • Chapter 9: Global Value Numbering. Iterative peepholes to fixpoint. Worklists.
  • Chapter 10: User defined structs, pointers and null analysis. One memory value in SSA. Loads, stores, and an executable evaluator.
  • Chapter 11: Equivalence class aliasing. Lazy memory partitioning with MemMerge, MemPhi, and BulkMemPhi.
  • Chapter 12: Reference fields, forward references and recursive structs.
  • Chapter 13: Global Code Motion - Scheduling.
  • Chapter 14: Numeric types: floats, narrow integers, ranges and rounding to f32.
  • Chapter 15: One dimensional static length array type, with array loads and stores.
  • Chapter 16: Constructors
  • Chapter 17a: Binding mutability, reference permissions, and deep read-only views.
  • Chapter 17b: Syntax sugar: var, val, x+=y, for(init; test; next) body
  • Chapter 18: Functions and calls.
  • Chapter 19: Instruction selection and portable compilation
  • Chapter 20: Graph Coloring Register Allocation
  • Chapter 21: Instruction Encodings & ELF
  • Chapter 22: A Simple Hello, World!
  • Chapter 23: Methods and Types Revisited
  • Chapter 24a: SCCP Within a Function
  • Chapter 24b: SCCP Across Functions
  • Chapter 25: SSA Before Types Are Known
  • Chapter 26: Construction and Private Memory
  • Chapter 27: Escape Analysis and Unknown Callers
  • Chapter 28a: Modules and Lazy Class Initialization
  • Chapter 28b: Separate Compilation
  • Chapter 29: Tech Debt Cleanup, Partial Objects
  • Chapter 30: Text Formatting and Diagnostics
  • Chapter 31: Software Drawing and Graphical Games (work in progress)

Appendices: Native libraries, optimizer and backend tuning. Future compiler and language work is collected in the roadmap.

Building across chapters

The optional interactive graph viewer is shared in graph/. All chapters launch it with make view from the chapter directory.

The debug printers are shared in print/; Chapter 2 needs only a one-line expression format. A shared BaseNode supplies identity and edge access to both printers and the viewer; chapter adapters add semantic details as the IR grows.

The instruction encoders share x86-64, ARM, and RISC-V byte emission for Chapters 21–31, along with ARM/RISC-V test evaluators. Machine-node selection, register allocation, and code layout remain in each chapter; the shared layer takes concrete operands and writes bytes.

The top-level Makefile runs each chapter's tests, tags (also tag), release, or lib target. Start with make lib on a fresh checkout, then make tests.

All chapter Makefiles share Java build rules and offline dependency rules. Missing JUnit JARs are copied from another chapter's local cache when available; otherwise the build stops with make libs instructions before compiling. Chapter-specific Makefile additions introduce allocation statistics (20), shared instruction encoders (21), the native entry shim (28a), separate compilation and sys (28b), the terminal game (30), and graphics/audio (31).

CI runs make lib tests on Linux with JDK 21. The Make targets also build the native runtime and sys library in Chapter 28b and later before running the tests that use them; Maven's Java build alone does not produce those prerequisites.

Chapters 10-14 cover whole memory, lazy alias splitting, references, GCM, and numeric types in that order. Later chapters build on this memory representation.

To build and test just the memory chapters:

make lib tests release CHAPTERS="chapter10 chapter11 chapter12"

Every chapter has an IntelliJ module with its own compiler and test classpath. See the IntelliJ setup to open and debug any chapter's tests. The root Maven reactor also includes every chapter. Make and the linear-history workflow discover the numbered chapter directories.

Extension points exported contracts — how you extend this code

browse all types & interfaces →

Core symbols most depended-on inside this repo

browse all functions →

Shape

Method 30,390
Function 9,295
Class 3,282
Enum 50
Interface 48

Languages

Java75%
TypeScript25%
C1%

Modules by API surface

chapter24/docs/d3.v7.min.js839 symbols
chapter23/docs/d3.v7.min.js839 symbols
chapter22/docs/d3.v7.min.js839 symbols
chapter21/docs/d3.v7.min.js839 symbols
chapter20/docs/d3.v7.min.js839 symbols
chapter19/docs/d3.v7.min.js839 symbols
chapter18/docs/d3.v7.min.js839 symbols
chapter24/docs/d3-graphviz.js393 symbols
chapter23/docs/d3-graphviz.js393 symbols
chapter22/docs/d3-graphviz.js393 symbols
chapter21/docs/d3-graphviz.js393 symbols
chapter20/docs/d3-graphviz.js393 symbols

For agents

$ claude mcp add Simple \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page