r/Compilers • • Jul 30 '25

Errors are finally working in my language!

Post image
1.7k Upvotes

I am currently developing a programming language as my final work for my computer science degree, I was very happy today to see all the errors that my compiler reports working correctly. I'm open to suggestions. Project link: https://github.com/GPPVM-Project/SkyLC


r/Compilers • • Sep 04 '25

How my friend formats his AST output

Post image
639 Upvotes

Fucking beautiful


r/Compilers • • Aug 13 '25

Finally managed to make a compiler

Post image
546 Upvotes

Making a compiler for my own language has been a dream of mine for many years. I finally managed to make one , although bad I am glad to say It works GitHub repo https://www.github.com/realdanvanth/compiler


r/Compilers • • Aug 15 '26 Diamonds are Forever

I created a web framework in my own programming language

Post image
421 Upvotes

I’ve been working on Rivet, a synchronous HTTP(for now) server library for my own programming language Zap

The goal is to create a small, explicit API for building APIs and small web applications.

I spent a lot of time and nerves creating this, but now I know what Zap is really capable of.

I will be grateful for every star you leave because it really encourages me to work

https://github.com/thezaplang/zap


r/Compilers • • Jul 25 '26

After months of hard work, I can do basic string processing, compiled to assembly, only 187x slower than rust.

Post image
380 Upvotes

r/Compilers • • May 07 '26

I built a Custom Language, Compiler, Assembler, and RISC-V VM, all running in real in your browser, using Rust and EGUI.

Post image
377 Upvotes

I've been working on this project (and compilers / vm's in general) for a while now, and I thought it was finally proper enough to showcase. Some of the features:

  • A custom systems language designed for explicit memory control, featuring manual memory management, pointers, (inline) structs, and generics.

  • A full interactive compiler pipeline that you can watch in real-time.

  • A built-in 5-stage pipelined CPU to execute the code.

  • Compiles to actual RISC-V machine code (RV64IMAFD).

  • Visualised live in browser using EGUI.

Github: https://github.com/LPC4/Full-Stack

Check out the live demo website here: lpc4.github.io/Full-Stack/


r/Compilers • • Jul 22 '24

My copy of "Writing a C Compiler" just arrived 😁

Post image
354 Upvotes

r/Compilers • • Oct 11 '26 Bravo

My LLVM contribution w/o using Ai got merged

297 Upvotes

After slowly understanding the reviewer’s suggestions and changes and going through the whole review process, my first good first issue got merged to llvm main. I’ve been trying to get one issue solved for the past couple of months and i couldn’t do it. It felt tough and scary to go through the whole gigantic code base. But feeling proud now for not quitting and backing off.


r/Compilers • • Aug 17 '25

Made code run on my own hardware, using my own compiler and assembler

277 Upvotes

As the title says, about a half a year ago I wrote a RISC-V core in verilog, an assembler and C compiler. Basically made the whole stack of running code, from hardware to a compiler. It's been a really cool, probably my favorite learning project so far, thought I'd share it here despite it being (kinda) old. I've been thinking of reviving the project and writing an operating system in c with my own compiler, would be really cool get an FPGA run my own hardware, my own compiler, my own OS.

Let me know what you think, here's the github if you wanna tinker with it: https://github.com/oxrinz/rv32i


r/Compilers • • Dec 08 '25

Axe - A Programming Language with Parallelism as a Core Construct, with no GC, written 100% in itself, able to compile itself in under 1s.

Thumbnail axelang.org
271 Upvotes

r/Compilers • • Aug 24 '25

Made my first Interpreted Language!

Thumbnail
gallery
271 Upvotes

Ok so admittedly I don't know many terms and things around this space but I just completed my first year of CS at uni and made this "language".

So this was my a major part of making my own Arduino based game-console with a proper old-school cartridge based system. The thing about using Arduino was that I couldn't simply copy or executed 'normal' code externally due to the AVR architecture, which led me to making my own bytecode instruction set to which code could be stored to, and read from small 8-16 kb EEPROM cartridges.

Each opcode and value here mostly corresponds to a byte after assembly. The Arduino interprets the bytes and displays the game without needing to 'execute' the code. Along with the assembler, I also made an emulator for the the entire 'console' so that I can easily debug my code without writing to actual EEPROMs and wasting their write-cycles.

As said before, I don't really know much about stuff here so I apologize if I say something stupid above but this project has really made me interested in pursuing some lower level stuff and maybe compiler design in the future :))))


r/Compilers • • Apr 12 '25

Introduction to Compilers as an Undergraduate Computer Science Student

Post image
264 Upvotes

I'm currently an undergraduate computer science student who has taken the relevant (I think) courses to compilers such as Discrete Math and I'm currently taking Computer Organization/Architecture (let's call this class 122), and an Automata, Languages and Computation class (let's call this class 310) where we're covering Regular Languages/Grammars, Context-Free Languages and Push Down Automata, etc.

My 310 professor has put heavy emphasis on how necessary the topics covered in this course are for compiler design and structures of programming languages and the like. Having just recently learned about the infamous "dragon book," I picked it up from my school's library. I'm currently in the second chapter and am liking what I'm reading so far--the knowledge I've attained over the years from my CS courses are responsible for my understanding (so far) of what I'm reading.

My main concern is that it was published in 1985 and I am aware of the newer second edition published in 2006 but do not have access to it. Should I continue on with this book? Is this a good introductory resource for me to go through on my own? I should clarify that I plan on taking a compilers course in the future and am currently reading this book out of pure interest.

Thank you :)


r/Compilers • • Mar 01 '26

A Rust compiler built in PHP that directly emits x86-64 binaries without an assembler or linker

Thumbnail
github.com
247 Upvotes

r/Compilers • • Nov 10 '25

What’s one thing you learned about compilers that blew your mind?

241 Upvotes

Something weird or unexpected about how they actually work under the hood.


r/Compilers • • Apr 07 '25

Wonderful Guide

Post image
224 Upvotes

Special Reference guide


r/Compilers • • Jul 25 '26

My hobby compiler is now compiling a company's production app

Thumbnail
gallery
220 Upvotes

When I started programming Edge Python more than six months ago, I was looking for a version of Python that weighed less than 200 kb so it could reach any device, sandboxed by design, built with browsers in mind, decoupled from the operating system and very fast.

Today the closest competitor would be MicroPython. However, it did not solve my real problems or the problems of the people who use the project.

  • Managing async and blocking code on the event loop. MicroPython inherits CPython's blocking execution model, designed around the GIL. When I built Edge Python I put the events inside the virtual machine, and that lets you run any operation while handling thousands of connections without blocking the main thread or the worker's thread.

  • MicroPython was not built for the web and neither was its stdlib. I have been working to get regex and every other dependency down to a few clean lines, crash free thanks to directed fuzzing.

  • Edge Python guarantees parsing everything in linear time, in a single pass, while MicroPython does not. This came from avoiding a syntax tree, which makes programs parse faster.

  • MicroPython crosses into JS through PyProxy. Edge Python avoids that entirely with an execution model decoupled from the host, they never have to interact directly.

  • I recently added the ability to serialize entire programs, born from an issue. If a user closes the tab, the whole bytecode state gets serialized, stored in the browser cache, and when the user comes back execution continues from the exact same point.

That said, my intention was never to replace CPython and it never will be. It has a gigantic ecosystem and competing with it is not even a priority for me. What I want to enable is this.

  • Anyone with business logic written in Python being able to run it on the client side.

  • Running lightweight LLM logic on the client side, so you do not need expensive compute just to parse a CSV or do math.

  • Building a framework to run lightweight machine learning models entirely on the user's side.

I am still working on all of this and, to be honest, I do not know how long it will take me to reach a real version to build a product around. I just want to say it has been an incredible process, and it has made me realize that with a compiler of barely under 20,000 lines I spend less and less time writing code and more time automating its stability with fuzzing and determinism.

Thanks! Any feedback or experience is appreciated. If you want to take a look, try the demo in the browser at edgepython.com and edit the code, the compiler is really fast. Try the CLI version too.


r/Compilers • • Nov 20 '24

My C-Compiler can finally compile real-world projects like curl and glfw!

219 Upvotes

I've been hacking on my Headerless-C-Compiler for like 6ish years now. The idea is to make a C-Compiler, that is compliant enough with the C-spec to compile any C-code people would actually write, while trying to get rid of the "need" for header files as much as possible.

I do this by

  1. Allowing declarations within a compilation unit to come in any order.

  2. Sharing all types, enums and external declarations between compilation units compiled at the same time. (e.g.: hlc main.c other.c)

The compiler also implements some cool extensions like a type-inferring print function:

struct v2 {int a, b;} v = {1, 2};  
print("{}", v); // (struct v2){.a = 1, .b = 2}  

And inline assembly.

In this last release I finally got it to compile some real-world projects with (almost) no source-code changes!
Here is exciting footage of it compiling curl, glfw, zlib and libpng:


r/Compilers • • Feb 16 '26

I think Elon is wrong about ‘AI beats compilers’. What’s the actual technical steelman?

Thumbnail
open.substack.com
217 Upvotes

So recently Elon Musk is floating the idea that by 2026 you “won’t even bother coding” because models will “create the binary directly”.

This sounds futuristic until you stare at what compilers actually are. A compiler is already the “idea to binary” machine, except it has a formal language, a spec, deterministic transforms, and a pipeline built around checkability. Same inputs, same output. If it’s wrong, you get an error at a line and a reason.

The “skip the code” pitch is basically saying: let’s remove the one layer that humans can read, diff, review, debug, and audit, and jump straight to the most fragile artifact in the whole stack. Cool. Now when something breaks, you don’t inspect logic, you just reroll the slot machine. Crash? regenerate. Memory corruption? regenerate. Security bug? regenerate harder. Software engineering, now with gacha mechanics. 🤡

Also, binary isn’t forgiving. Source code can be slightly wrong and your compiler screams at you. Binary can be one byte wrong and you get a ghost story: undefined behavior, silent corruption, “works on my machine” but in production it’s haunted.

The real category error here is mixing up two things: compilers are semantics-preserving transformers over formal systems, LLMs are stochastic text generators that need external verification to be trusted. If you add enough verification to make “direct binary generation” safe, congrats, you just reinvented the compiler toolchain, only with extra steps and less visibility.

I wrote a longer breakdown on this because the “LLMs replaces coding” headlines miss what actually matters: verification, maintainability, and accountability.

I am interested in hearing the steelman from anyone who’s actually shipped systems at scale.


r/Compilers • • Nov 09 '25

AST Pretty Printing

Post image
168 Upvotes

Nothing major, I just put in a fair chunk of effort into this and wanted to show it off :)


r/Compilers • • Feb 19 '26

TensaLang: A tensor-first language for LLM inference, lowering through MLIR to CPU/CUDA

Post image
161 Upvotes

Hello,

I've been working on a project called TensaLang and it's finally at a point worth sharing. It's a small language + compiler + runtime for writing LLM forward passes directly in source code, lowering through MLIR to CPU (LLVM JIT) or CUDA (NVVM).

GitHub: https://github.com/BenChaliah/Tensa-Lang
Website/Docs: https://tensa-lang.org
Example weights: https://huggingface.co/DatarusAI/Tensa-Lang

Please STAR the repo if you find it interesting!.

Motivation

Many inference runtimes couple model logic tightly to backend-specific kernels. This creates friction on two fronts:

  • Targeting new hardware means building a new runtime or forking an existing one, because kernel logic, memory management, and scheduling are entangled with backend assumptions.

  • Exploring new architectures (attention variants, cache layouts, sampling strategies) means rewiring ops across abstractions that weren't designed to be rewritten.

When diagnosing throughput, the IR you can inspect is either too low-level or already specialized to one execution model to reason about the algorithm itself.

I wanted a language where tensors are first-class, hardware targets are interchangeable, and tiling lives in the source rather than buried in backend code. MLIR's dialect interoperability makes this viable: express algorithmic structure once (tensor ops, loop nests, reductions, parallel dimensions) and diverge only at final backend-specific lowering.

The .tl language

The source language is intentionally minimal: tensors + loops + reductions, with scheduling hints attached to functions. Index variables become loop induction variables; reductions become accumulator-carrying scf.for loops. The program is the loop structure.

fn attn_scores(q: Tensor<f32, [H, Dh]>, k: Tensor<f16, [T, Dh]>, scale: f32)
    -> Tensor<f32, [H, T]>
    with tile=[8, 64], parallel=[h, t] {
  var s: Tensor<f32, [H, T]>
  s[h, t] = sum(i) q[h, i] * (k[t, i] as f32) * scale
  return s
}

The forward pass and sampling loop live in .tl source, not hidden inside the runtime.

Pipeline

.tl source → tensalang_sugar.py → S-expr IR → codegen.cpp → MLIR → JIT execution

Dialects used: func, memref, scf, arith, math, linalg, gpu/nvvm, llvm. Intentionally "boring upstream MLIR" so the IR stays inspectable.

CPU path: Lower to LLVM dialect, run via mlir::ExecutionEngine. Hot kernels in runtime_cpu.cpp with threading and x86 SIMD fast paths.

CUDA path:

  • linalg → parallel loops → GPU mapping (gpu.launch) + kernel outlining (gpu.module)

  • gpu → nvvm

  • Serialize GPU module to cubin via CUDA driver JIT (small pass in gpu_serialize.cpp)

  • Host-side lowered to LLVM, same JIT mechanism

  • Runtime wrappers + cuBLAS matvec dispatch in runtime_cuda.cpp

What's implemented

  • Pattern-matched dispatch to cuBLAS for matvec

  • Fused attention modes (TENSALANG_FUSED_ATTENTION=0/1/2)

  • Arena allocator for per-token memory reuse

  • Safetensors loading, tokenizer hooks (JSON format or HF tokenizers via subprocess)

  • Custom "glue" passes: malloc → backend allocator rewrite, optional host registration for GPU operands

  • Debug knobs: TENSALANG_DUMP_IR, TENSALANG_DUMP_IR_FILTER, TENSALANG_SKIP_INLINER, TENSALANG_SKIP_CANON, TENSALANG_SKIP_CSE, TENSALANG_ONLY_FN

Status

Still beta, but tested successfully with Llama-2 7B and Qwen2.5-Coder-0.5B on both CPU and CUDA. This is a "readable end-to-end stack" project, not a production runtime, but a complete working pipeline you can understand and modify to explore compilation, scheduling, and runtime boundary questions.

ROCm and MLX are on the roadmap once CUDA lowering is sufficiently optimized.

Dependencies: LLVM 18, C++17, Python 3.x, CUDA Toolkit (optional)

Happy to share IR dumps or minimal reproducers if anyone wants to discuss specific pass sequences or lowering decisions.

  • I appreciate any feedback!


r/Compilers • • Jul 10 '26

My first big compiler project; without a backend!

Post image
156 Upvotes

o7 everybody! This is my first post on Reddit, so sorry for technical issues :)

I'm a self-taught high school student. Last year's October I got motivated to create a compiler in C99.

Here's the link: https://github.com/milcsu09/compiler-x86_64

I highly recommend looking into examples/ and euler/ to see the language in use. The README is extremely sparse, but I think the project is simple enough to be undestood by anyone :)

The motivation mostly came from the GitHub repository "A Compiler Writing Journey" ( https://github.com/DoctorWkt/acwj ). It also was a nice guide to see what features I might want to tackle next.

The compiler compiles a modified Rust-like language with C semantics to x86_64 assembly for Linux. It's around 6.6k lines of code. The assembly generated can be viewed in the GitHub repository.

I tried to preserve the semantics of C as much as I could, like implicit integer conversion, array to pointer decay, function pointer semantics, etc..., and I think I did a good job. But I don't doubt my code doesn't have bugs :P

The language is not complete, and I doubt it'll ever be finished. The purpose of the project was learning.

So, I would really appreciate your opinion, and I'm happy to answer questions you have!

NOTE: (I'm sad that I have to explicitly say this) I didn't use AI. Again, the project was for learning purposes, and in my opinion generating a project with AI won't make you learn anything :P


r/Compilers • • Aug 03 '25

My assembler for my CPU

Thumbnail
gallery
156 Upvotes

An assembler I made for my CPU. Syntax inspired by C and JS. Here's the repo: https://github.com/ablomm/ablomm-cpu


r/Compilers • • Dec 11 '20

CS 6120: Advanced Compilers: The Self-Guided Online Course

Thumbnail cs.cornell.edu
156 Upvotes

r/Compilers • • Dec 24 '24

Free Lecture Notes on Compiler Construction

155 Upvotes

Dear redditors,

I've put together a PDF containing the lecture notes I use for teaching Compiler Construction at UFMG. The PDF has taken the shape of a book, complete with the following table of contents:

  • Introduction

  • Lexical Analysis

  • Tree-Like Program Representation

  • Recursive-Descent Parsing

  • Bottom-Up Parsing

  • Parser Generators and Parser Combinators

  • Variables and Bindings

  • The Visitor Design Pattern

  • Type Systems

  • Type Checking

  • Type Inference

  • Anonymous Functions

  • Recursive Functions

  • Introduction to Code Generation

  • Code Generation for Expressions

  • Code Generation for Statements

  • Code Generation for Functions

  • Memory Allocation

  • Pointers and Aggregate Types

  • Code Generation for Object-Oriented Features

  • Heap Allocation

  • Introduction to Code Optimizations

  • Data-Flow Analyses

  • Static Single-Assignment Form

The book is freely available, but it likely contains typos or errors. If you find any, I'd greatly appreciate it if you could report them to me. One more chapter, on register allocation, still needs to be added, as it’s part of our syllabus. I plan to include it next year.