Compiler Development

MonoLangx86-64

A programming language built from scratch in C, featuring typed variables, function calls, arithmetic expressions, and compilation to x86-64 assembly.

View Repository

Implementation

C

Target Architecture

x86-64

Compilation

Assembly generation

The Project

The goal is to build a programming language from the ground up, from parsing source code to generating machine-oriented assembly. Rather than interpreting expressions directly, the compiler translates programs into x86-64 assembly.

The language currently focuses on typed integer values, arithmetic expressions, function declarations, function calls, and return values. The scope is intentionally small, keeping the focus on the fundamentals of compiler design and low-level execution.

Language Features

A small but functional language

01

Primitive Types

Four integer types, from int8 to int64, with support for integer and character literals.

int8 a = 1;
int8 c = 'a';
02

Functions & Arguments

Define functions with typed parameters and return types, pass arguments, and call other functions.

fn add2(int32 a, int32 b): int32 {
    return a + b;
}
03

Expressions & Returns

Declare and update variables, perform arithmetic operations, call functions, and return computed values.

int32 result = add2(10, 20);
return result;

Type System

Explicit integer types

Variables and function signatures use explicit integer types, making the size of each value part of the language syntax.

int8

8-bit

int16

16-bit

int32

32-bit

int64

64-bit

Both numeric and character literals can initialize variables.

int8 a = 1;
int8 c = 'a';

Syntax

Familiar syntax, low-level output

Functions declare their parameter types and return type. Statements end with semicolons, and the # character introduces comments.

example.src
# A function with two parameters
fn add2(int32 a, int32 b): int32 {
    return a + b;
}

fn main(int32 x): int32 {
    int8 c = 'a';
    c = add2(c, 't');

    return c;
}

Language Reference

Core syntax

Function declarations

Functions declare typed parameters and a return type.

fn add(int32 a, int32 b): int32 { ... }

Variable declarations

Variables are declared with a type and an initial value.

int32 value = 42;

Statements

Statements are terminated with a semicolon.

return value;

Comments

Use # to write a comment.

# This is a comment

Current Scope

Built around x86-64

The compiler currently targets x86-64 and supports functions with return values, typed parameters, function calls, integer variables, and arithmetic expressions. Functions with more than seven parameters are not currently supported.

From source code to assembly.

Exploring compiler construction, language design, and the fundamentals of low-level programming.

Explore the source