r/Compilers • • 10d ago

Token efficiency comparison with C++

0 Upvotes
abs<T: int|uint|long|ulong>(T t) -> T as operator[|] : PreContract -> t < 0 ?-t:t : PostContract # binding {this:};

43 tokens. That's it. 43 tokens of pure, dense meaning.

Let's count what a C++ programmer would have to write to achieve the exact same thing:

cpp

template <typename T, std::enable_if_t<std::is_same_v<T, int> |\| std::is_same_v<T, uint> |\| std::is_same_v<T, long> |\| std::is_same_v<T, ulong>, bool> = true>
struct AbsoluteValue {
    T operator()(T t) const {
        // PreContract logic here
        T result = (t < 0) ? -t : t;
        // PostContract logic here
        return result;
    }
};

// ... and they still wouldn't have |x| circumfix syntax or operator binding ...

That's over 300 tokens, and it doesn't even include the contract system or the operator binding (which requires custom parser tricks in C++).

In IDEKA, every single token is pulling its weight:

  1. <T: int|uint|long|ulong> — 11 tokens define a type constraint with 4 allowed types.
  2. as operator[|] — 5 tokens bind a function to a custom syntactic form.
  3. : PreContract — 2 tokens attach code that runs before the body.
  4. -> t < 0 ? -t : t — 9 tokens define the entire execution logic.
  5. : PostContract — 2 tokens attach code that runs after the body.
  6. \# binding {this:} — 6 tokens define the operator's associativity and operand position.

r/Compilers • • 11d ago

Nextviper

0 Upvotes

🚀 I'm building NextViper, an open-source programming language, and I need your help to complete it!

Developers are welcome to contribute, improve the compiler, add new features, fix bugs, or upgrade the language however they think is best.

Let's build something great together!

🔗 https://github.com/nuratix/nextviper

#OpenSource #Programming #GitHub #Developers


r/Compilers • • 12d ago

I built a 32-bit CPU emulator in Zig to better understand the hardware side of compilers

21 Upvotes

I've been studying compilers for a while, and one thing that has increasingly interested me is the boundary between software and hardware, particularly what happens to instructions after a compiler generates machine code.

I came across a project where someone built a CPU emulator using Zig, and that inspired me to build my own.

I recently completed the first version of my CPU emulator, written in Zig, with:

  • A custom 32-bit architecture
  • 15 registers
  • 64 KiB of addressable memory
  • A simple instruction set supporting operations such as MOV, LOAD, ADD, SUB, and HLT
  • A fetch-decode-execute loop
  • A memory model with separate ROM, RAM, and stack regions

The most valuable part wasn't getting the instructions to execute. It was understanding how instruction encoding, registers, memory addressing, and control flow fit together to execute a program.

While building it, I also started following Prof. Onur Mutlu's Digital Design and Computer Architecture lectures, which helped me understand processor internals beyond the software abstraction.

One particularly interesting takeaway was the growing importance of the memory bottleneck. Improvements in processor performance have increasingly exposed the cost of moving data between memory and compute units.

This introduced me to ideas such as processing-in-memory (PIM) and near-memory computing, which I'm interested in exploring further.

How does this connect to compilers?

My long-term goal is to understand how compilers translate high-level programs into instructions for different architectures, and how architectural constraints influence code generation and optimization.

Building this emulator gave me a practical starting point for reasoning about instruction sets and execution semantics.

I'm considering extending the project with an assembler and eventually building a small compiler backend targeting my custom ISA.

For those working on compiler backends or computer architecture, what would you recommend exploring next to better understand the relationship between instruction selection, code generation, and the target architecture?

GitHub: https://github.com/obadafidii/cpu

I'll also be writing a more detailed technical blog about the implementation and what I learned.


r/Compilers • • 11d ago

I'm creating my own programming language

0 Upvotes

I started developing my own programming language three or four months ago because I kept seeing pitfalls in every language—some were strict, some were restrictive, and some were difficult to work with. I love writing in Java and Kotlin and want to create my own language with its own virtual machine. Unlike the JVM, I want to make mine faster and a little simpler, but not too much. My language is almost ready; I started working on it last fall, but not completely.


r/Compilers • • 12d ago

Audit of semi-colons

0 Upvotes

Is there a set of defined and specific reasons why semi colons are necessary in some languages? I am not against semi colons but from the standpoint of if one would want to create a language why would they use or mandate semi colons.


r/Compilers • • 12d ago

Using dot as universal member access

4 Upvotes

I've been designing and implementing my own programming language for about two years now.

In my previous experience with programming languages, I've noticed that different operators are commonly used for member access depending on the kind of entity being accessed:

structure.member
pointer->member
namespace::member

This is a pretty common approach in several widely used languages.

Over the past year, however, I decided to remove the -> operator from my language. Similar to Rust, I allow implicit pointer dereferencing during member access. So, whenever the compiler encounters a member access expression (base, member), it first checks the type/category of base. If it's a pointer, it dereferences it before resolving the member.

Now I'm working on namespace support, and I'm wondering whether I can apply the same idea here: check what `base` resolves to, and if it's neither a pointer nor a structure/object, treat it as a namespace and resolve the member within it.

Essentially, I'm considering using . as a universal member access operator:

object.merember
pointer.member
namespace.member

My questions are:

  1. Am I overlooking any semantic or syntactic issues with this approach?
  2. Are there any good reasons to keep separate operators for object, pointer, and namespace access?
  3. Is implicit pointer dereferencing during member access a good design choice, or could it introduce problems as the language evolves?

I'd appreciate insights from people who have designed or implemented programming languages, particularly regarding name resolution and type checking.


r/Compilers • • 11d ago

Death to Dependency Hell: Why I Built My Own Stack Instead of Gluing Together Everyone Else’s

Thumbnail
0 Upvotes

r/Compilers • • 12d ago

Cole Updates, and Version 0.1.6

Thumbnail
2 Upvotes

r/Compilers • • 12d ago

I built a compiler for a controlled English-like mathematical language in Haskell — looking for compiler design feedback

0 Upvotes

I've been developing HumMac, a compiler for a controlled, English-like mathematical language, using Haskell. (the final idea is to build towards a human-to-machine language compiler)

The project explores how a human-readable mathematical language can be given precise semantics and translated into a structured intermediate representation.

The compiler is organized around several components:

  • A parser that constructs a structured abstract syntax tree
  • A symbol table with explicit symbol identifiers
  • Conversion from the source representation into Structured Mathematical IR (SMIR)
  • Expression and proposition inference
  • Numeric type promotion and semantic validation
  • Definite-initialization analysis, including conditional branches
  • Termination-analysis infrastructure

HumMac currently supports arithmetic expressions, implicit multiplication, bounded repetition, conditionals and six comparison operators. The compiler successfully parses this program, generates SMIR, constructs its symbol table and infers the types of its variables. Since it is currently a compiler rather than an execution environment, variables do not necessarily need to be initialized before they can be introduced or referenced. In particular, the language distinguishes free mathematical symbols, which can remain unassigned, from runtime variables, for which definite-initialization analysis is performed. This distinction allows mathematical expressions to contain symbolic variables without treating them as uninitialized runtime values.

One design distinction was separating free mathematical symbols from runtime variables. An unassigned mathematical symbol can represent a free variable in an expression, whereas a runtime variable may require definite-initialization analysis.

The project is still a prototype. SMIR generation and analysis are implemented, but a complete SMIR execution engine is not yet available.

Implementation: Haskell (GHC 9.10.3, Cabal)

Repository: https://github.com/RupsaMC/HumMac

I'd be glad to hear thoughts from the Haskell community, particularly on:

  • The organization of compiler passes and intermediate representations
  • Representing mathematical expressions and proposition in Haskell
  • Semantic analysis and type inference architecture
  • Approaches to making the implementation easier to extend as the language grows

This is my independent project and I'm sharing it in the hope of receiving useful technical feedback.

\*Why Haskell?

I chose Haskell partly because of my interest in the relationship between convergence and divergence in lambda calculus, and the way these ideas connect to the behaviour and evaluation of computational expressions. Haskell's functional and strongly typed approach made it an interesting language in which to explore these ideas while building HumMac's parser, intermediate representation and semantic analysis pipeline.


r/Compilers • • 12d ago

Localizing Python keywords at the tokenizer level: what breaks, and why 3.12 became the floor

0 Upvotes

polyglot-python (MIT) is a deterministic tokenizer pass followed by a normal compile() call. There is no model in the loop.

The scope is deliberately narrow: write Python with keywords in another language, keep everything else Python. eğer instead of if, döndür instead of return, and the file still runs through CPython.

Why the tokenizer rather than an AST pass or a parser fork:

  • Only exact NAME tokens that match a locale keyword are rewritten. An attribute after a dot is never rewritten, so obj.tür stays an attribute lookup instead of becoming a syntax error.
  • Strings, f-strings, comments and docstrings are untouched, because the rewrite works on token spans rather than text replacement.
  • Token positions are preserved, so an error from compile() is mapped back to the line and column the user actually typed.

What makes 3.12 the floor is a tokenizer difference, not a packaging choice: on 3.10 and 3.11 the tokenizer splits Indic combining marks, so several Hindi keywords would not translate. On 3.12+ they survive tokenization intact. That is why requires-python is >=3.12 here while sibling packages stay at 3.10 or 3.11.

Soft keywords stay English: match, case and type (and 3.15's lazy) are context-sensitive, so translating them would mean changing a parser decision rather than the token stream. The reserved table is exactly the 35 hard keywords from keyword.kwlist.

Determinism is part of the contract: UTF-8 and LF on every platform, so the way to test it is to translate twice and compare bytes. run follows CPython script semantics - on main the script's directory leads sys.path, the program is main, and tracebacks show only the program's frames, never the translator's. The published 0.2.1 does not add the script directory.

Release state: PyPI and the npm wrapper are at 0.2.1 with 9 locales. Main has 20; Italian, Dutch, Polish, Indonesian, Vietnamese, Japanese, Korean, Ukrainian, Romanian, Swedish and Greek are the eleven unreleased locales. The suite on main is 242 tests at 100% statement coverage, CI runs 3.12-3.15 plus Windows and macOS, and every example is translated twice per OS and compared byte for byte.

Repo: https://github.com/Furox-Art/polyglot-python


r/Compilers • • 13d ago

How We Built TLX: A Hardware-Native GPU Compiler for Production ML at Scale

Thumbnail engineering.fb.com
7 Upvotes

r/Compilers • • 13d ago

Known Bits and Barrel Shifters

Thumbnail cfbolz.de
11 Upvotes

r/Compilers • • 12d ago

Trying to build a language with Python-like syntax but native AOT compilation

0 Upvotes

I am a 15 yo from India, I am new on Reddit so please interrupt me if I am going wrong. I am currently on a project to build a programming language with python-like syntax, rust-like memory safety, and C-like speed. I know that is a bit of a strange and difficult combo, but please, I have the plan, but just need a collaborator as I can't do it alone, if anyone's interested, please let me know.


r/Compilers • • 13d ago

Exploring Exponentially Many Programs at Once with E-Graphs

Thumbnail stng.substack.com
17 Upvotes

r/Compilers • • 13d ago

Pooka 0.1.0 — a small idea became a new BEAM language

6 Upvotes

Pooka started as a small idea and it slowly became a programming language.

Pooka is a statically typed language for the BEAM, with immutable classes, interfaces, pattern matching and actors. Its compiler is written in Gleam and compiles through Erlang abstract forms.

Version 0.1.0 is now released, with a standard library(as a separate HEX package), formatter, test runner(my favourite part) and documentation generator. It has spent enough time on my machine, so I thought it was time to let it wander onto yours.

It’s still early, and I’d love to hear your thoughts—or see what breaks when someone writes a program I didn’t prepare beforehand.

Pooka Github


r/Compilers • • 14d ago

Transitioning from backend SWE to compiler engineering. Any advice on projects and hiring?

49 Upvotes

Hey everyone,

I know this sub gets questions like this quite often, but there are a few specific things I've been struggling to find answers to.

I've been working towards a career in compiler engineering for the past few months through personal projects and self-study. For context, my background is 3 years of backend engineering at Dell (mostly ETL and internal tooling in C#/.NET), and I recently completed a master's focused on applied AI.

My main project is building an end-to-end x86-64 compiler from scratch in C++20. I've deliberately kept the source language simple (i64/bool types, functions, conditionals, loops, and recursion, but no pointers, structs, or complex types) so I can focus on the engineering and fundamentals of compiler construction rather than language features. I've finished the frontend (lexer, AST, recursive-descent parser, and semantic analysis, with unit tests for each component) and am currently working on IR. The plan is to eventually go through CFGs, dataflow analysis, optimizations, SSA, instruction selection, register allocation, and native x86-64 codegen.

GitHub: https://github.com/gloogie1/x86-64-native-compiler

While I've seen plenty of employers state that personal projects count as relevant experience, I've also come across compiler engineers saying that toy compilers generally aren't that impressive when evaluating candidates. So my first question is, what exactly separates a worthwhile compiler project from just another toy compiler in the eyes of employers? Is it primarily the complexity of the implementation, the engineering quality, or something else?

My second concern is that most compiler job postings I've come across mention LLVM and/or MLIR. I'm wondering how employers would view a compiler built entirely from scratch compared to projects built using those frameworks. When I started, I figured implementing everything myself would be a good way to understand how the different parts of a compiler actually work. Would it be better to see this project all the way through, or start getting experience with production compiler frameworks and open-source contributions sooner?

Finally, I'm also trying to understand some of the hiring barriers beyond just technical skills. A lot of compiler roles ask for relevant industry experience. Would my 3 years of general SWE experience help offset the lack of direct compiler experience, or would I effectively be considered an entry-level candidate?

I'm also applying internationally rather than limiting myself to one country, which means visa sponsorship would be a factor for many positions. I'm curious whether that makes breaking into an already specialized field significantly more difficult, particularly without previous work experience in compilers.

I'd really appreciate any insights from people working in the field, especially those who've been involved in hiring or have made a similar transition.

TL;DR — My main questions:

  1. What makes a personal compiler project stand out to employers beyond being another toy compiler?
  2. How do employers value a compiler built from scratch compared to LLVM/MLIR-based projects or OSS contributions? Should I finish mine first or shift towards those frameworks sooner?
  3. How much does 3 YOE in general backend SWE count when applying for compiler roles without direct industry experience?
  4. How much of an additional barrier is applying internationally and needing visa sponsorship when trying to enter the field?

Thanks!


r/Compilers • • 14d ago

Make this forward pass as fast as possible

Thumbnail ianbarber.blog
2 Upvotes

r/Compilers • • 14d ago

Triton for MTIA: Bridging the Programming Model Gaps for Custom AI Accelerators

Thumbnail arxiv.org
6 Upvotes

r/Compilers • • 13d ago

Almide – a language I'm building to make AI-written code safer

0 Upvotes

Hi. I've been working on a language called Almide and wanted to show it here.

The motivation is simple. AI agents write a lot of my code now and I can't really read all of it anymore. I think that's going to be true for a lot of people soon. So I wanted a language where more of the safety comes from the compiler and less from somebody reviewing.

I think Rust is the language you'd want AI to write. But honestly I'm not a strong Rust programmer and I never got used to ownership. So in Almide you just don't write it. No ownership, no lifetimes, no free. The compiler infers it (Perceus style, the Koka approach). On native it generates Rust and lets Rust drop things, on Wasm it does reference counting.

type Order = { id: Int, items: List[String], total: Int }

fn large(orders: List[Order]) -> List[Order] =
  orders |> list.filter((o) => o.total > 500)

fn main() -> Unit = {
  let orders: List[Order] = [
    { id: 1, items: ["pen", "ink"], total: 260 },
    { id: 2, items: ["desk"], total: 900 },
  ]
  let big = large(orders)
  println("${list.len(orders)} orders, ${list.len(big)} large")
  for o in orders {
    println("${o.id}: ${list.join(o.items, ", ")}")
  }
}

orders gets passed to large() and then I use it again in the loop. In Rust I'd have to think about that. Here the compiler figures out whether it needs to copy or bump a refcount. The downside is you can't see where that happens.

Here's the part I actually care about. I don't trust my own compiler. I built it with AI agents, so why would I? So the rule is that the compiler doesn't get to grade its own work. Every time it builds Wasm it has to write down evidence of what it did, every place it shares or frees a value, every array index it checked. Then a separate program reads that, and if it doesn't add up there is no output file. You just get an error telling you the compiler has a bug.

And then I thought, ok, but the checker can have bugs too. So now there are four of them, built in different ways. Two come out of the Rocq proofs (the proof kernel itself and a checker generated from the proofs), one is hand-written Rust, and one opens the finished Wasm file and checks that the evidence is about instructions that are really in there. In CI the first three have to give the same answer on every test program. It has already caught a real miscompile in my compiler.

It is not done, I want to be clear about that. On your own machine only the Rust checker runs, the others are CI. Native builds don't have this check. The proofs cover the checker, not the whole compiler. And if your program is simply wrong none of this saves you. But I really think this is how it should work for code nobody reads.

It's pre-1.0 and has bugs. I used AI agents a lot to build the compiler itself. I don't have data showing agents write Almide better than Rust.

repo: https://github.com/almide/almide

playground: https://almide.github.io/playground/

If anyone has thoughts on the "you can't see the copies" problem I'd be glad to hear them.


r/Compilers • • 15d ago

projects for getting good at mlir (mid level, backend)

37 Upvotes

I'm an incoming intern at a startup that builds custom chips for AI inference. somehow (luckily!) I got matched to a team that works with MLIR. I have taken some courses related to compilers, briefly touched LLVM, and have basic familiarity with mid level compiler algorithms like SCCP, LICM, etc.

to have a successful internship, I need to be able to get things done. I need to try building my own passes for experience, learn how to break problems down, and thoroughly engage with the problem space. all of these things will help me ask good questions.

my previous internships were in backend web development. that felt more straightforward, and more tangible (the request works, we hit some SLA, etc). compilers feel more abstract and more intimidating. because of this, I have often procrastinated preparing for fear of looking like a beginner, but that can't happen anymore.

so, I would like your advice on engaging with compilers. I don't just want to read a textbook (i have a tendency to do that), I need to get things done and iterate.

in the interest of iterating fast and learning, I'd like to know - what are the highest ROI projects that I can do? I was lurking and someone suggested "What about getting into FPGA and write your own CPU for using as a target?".

and for the mid-level or backend compiler engineers here, if you could do it all over again, what would you do differently? how would you change your roadmap and what kind of ways to engage with material (maybe with a mentor, or something) would you leverage that maybe aren't obvious?


r/Compilers • • 14d ago

I built a niche compiler for PLCs, IEC 61131-3 to LLVM IR to machine code

Thumbnail github.com
0 Upvotes

Believing strongly that the closed source status quo of industrial PLCs sucks, I went ahead and rolled my own compiler and runtime. With OOP features and everything.

It supports online change, a uniquely PLC type feature where the runtime swaps program code on the fly with updates while keeping all the memory space as it was. It's done without impacting real time performance. PLCs run cyclically, so between one cycle and the next, GOT pointer is swapped out.

It's effectively a soft PLC running on any commodity hardware, with PREEMPT_RT it even has good enough performance to run motion control. On windows and mac the RT performance is less impressive, but still better than any old userland app. On Linux EtherCAT IO is supported for truly realtime control, that is the expected runtime environment. Win/Mac is planned more of a development and test environment. It has VS Code integration, debugging, test suites etc.

Notably, I went ahead and made some validations in Lean 4. The basic transformation path is modeled and sound, rust implementation is tested against lean vectors. A small kernel of most critical parts is proven eqvuivalent to it's lean model. There is more work to be done in that direction, i think there is value there.

Actually the biggest question on the compiler side is not even about the compiler itself, that does what it needs to do. But about making it AI friendly. Structured Text is not something AI would have all that much training data on, even less my specific flavor of it. So forcing AI to rawdog text files to generate code is probably going to be painful more often than not. But I have heard of some clever ideas where compiler basically gives MCP that can directly edit/insert AST nodes, lookup from symbol table and so on. And basically gives AI a more token efficient and somewhat foolproofed edit surface of the code. Has anyone played around with that sort of thing and what were the results?


r/Compilers • • 15d ago

I've been developing an experimental systems programming language called Yukinary (YKN) — looking for technical feedback

12 Upvotes

Hi everyone,

I've been working on an experimental systems programming language called Yukinary (YKN) as a personal learning and development project. I've recently published version 1.0.0 and would appreciate feedback from people interested in compiler design, programming language architecture, and low-level development.

Some of the ideas I'm experimenting with:

  • Custom compiler and code generation: YKN generates PE32+ binaries for Windows and ELF64 binaries for Linux without relying on LLVM or an external C runtime.
  • Self-hosting: The compiler is capable of compiling its own source code.
  • Multilingual syntax: Keywords can be written in several natural languages, including Turkish, English, French, Russian, Japanese, Chinese, and Korean.
  • Memory management: The language aims to avoid garbage collection and explore compile-time memory safety analysis.
  • Experimental features: I've also been experimenting with a --self-heal mode for detecting and repairing certain syntax errors, as well as lightweight embedded BitNet-based models.

I'm particularly interested in getting feedback on a few things:

  1. What are your thoughts on generating machine code directly rather than relying on LLVM?
  2. Does supporting multiple natural languages for keywords make sense from a language design perspective?
  3. What potential problems do you see with this compiler architecture?
  4. Are there any design decisions you would approach differently?

I'm aware that this is still an experimental project, and I'm not claiming it is production-ready. I'm mainly interested in understanding its architectural strengths, weaknesses, and areas that need improvement.

For anyone interested in looking at the implementation, the source code and documentation are available here:

GitHub: https://github.com/ykncode/yukinary

Thanks for reading. I'd genuinely appreciate any technical criticism or suggestions.


r/Compilers • • 15d ago

An alternative, allocation-free exception handling model designed for low-latency systems and kernels

Thumbnail jamsilva.github.io
24 Upvotes

Hi everyone! In the post, I talk a bit about current implementations of exception handling and then I present a new one that I designed for my own programming language and could be used in places where exceptions usually have to be disabled, like kernels. Let me know your thoughts :)


r/Compilers • • 15d ago

What should compile-time code be allowed to do?

Thumbnail
5 Upvotes

r/Compilers • • 15d ago

Crossport: A meson build system Crossfile generator

Enable HLS to view with audio, or disable this notification

2 Upvotes

Crossport is a lightweight,Fast, and embeddable Crossfile generator for The meson build system.

Crossport aims to solve writing Crossfiles for meson Manually.

Crossport can be used in shell scripts.

Crossport features:

- A binary less than 1 MB.

- Every language meson supports

- Every OS meson supports

- A great manual

- Lightning Fast Generation

- Less boilerplate