MinLang is a compact, clean, and expressive programming language designed for educational, experimental, and low-overhead compiler development. With just a handful of core features, MinLang makes it easy to explore compiler design, code generation, and systems programming in OCaml.
This repository includes mincc.ml, a single-file compiler that transforms MinLang source code into assembly.
MinLang draws inspiration from C, while stripping the syntax down to the essentials. Here's what the language supports:
- Primitive types:
int,char,ptr<T>(pointers) - Variable declarations with type inference (i.e.
let x = 0;, optionallylet x: int = 0) - Functions with typed parameters and return values
- Function calls: Nested function calls result in undefined behavior
- Basic expressions and operators:
- Binary:
+,-,*,/,%,==,!=,<,>,<=,>=,= - Unary:
!,*(dereference),&(address-of)
- Binary:
- Return statements
- No runtime, no standard library—just minimal code and direct control
MinLang is an experimental programming language not meant to be used in production. Up to now, it includes several features, but contains some limits:
- No vaiadic functions
- No position independent binaries
- Until now, only x64 assembler output is tested
- No nested function calls (no compiler rejection, but execution is undefined behavior)
Also, this project is currently WIP. The following features are still under construction:
- More x64 tests
- RISC-V testing infrastructure
- Add support for variadic C function calls (i.e.
fn printf(fmt: ptr<char>, ...): int;declaration support)
fn square(x: int): int {
return x * x;
}
fn main(): int {
let a: int = 5;
let b: int = square(a);
return b;
}
The compiler is implemented in OCaml as a single file: mincc.ml. To build and run:
ocamlc -o mincc mincc.mlTo compile a minLang source file to an executable, run the following script (x64 linux):
# Compile the source file to assembler code
./mincc -c input.minLang -o output.asm -a nasm
# Assemble assembly code to object file
nasm -felf64 output.asm -o output.o
# Link object file with C standard library
gcc -fno-pie -no-pie output.o -o OutputBy default, minLang is linked with the C standard library by linking with gcc. You can freely access library functions by declaring function prototypes:
fn printf(ptr<char>): int;
fn exit(int): int;
fn main(): int {
printf("Hello World!\n");
return exit(1);
}
Or for example using files:
fn fopen(ptr<char>, ptr<char>): ptr<void>;
fn fclose(ptr<void>);
fn fputs(ptr<char>, ptr<void>);
fn main(): int {
let msg = "Hello world!\n";
let fd = fopen("hello.txt", "w");
fputs(msg, fd);
fclose(fd);
return 0;
}
-c <input>: MinLang source file to compile-o <output>: Output assembly file-a <asm>: Assembler dialectriscv: Generate 32bit RISC-V codeir: Dump IR (Intermediate Representation) codenasm: Generate 64bit x64 NASM assembler code
The compiler emits x86 assembly code with basic structure, suitable for further compilation via nasm, gcc, or similar tools.
MinLang is designed for:
- Learning compiler internals
- Playing with parsing, ASTs, and code generation in OCaml
- Keeping things as simple as possible—and nothing more
This project is open source under the MIT License. See the LICENSE file for details.