A program in my language showing function overloads:
```
struct Vec2 { x: u32, y: u32 }
struct Vec3 { x: u32, y: u32, z: u32 }
fn add(a: Vec2, b: Vec2): Vec2 {
return Vec2 { a.x + b.x, a.y + b.y }
}
fn add(a: Vec3, b: Vec3): Vec3 {
return Vec3 { a.x + b.x, a.y + b.y, a.z + b.z }
}
fn main(): u32 {
let v2a = Vec2 { 3, 2 }
let v2b = Vec2 { 4, 3 }
let v2c = add(v2a, v2b)
println(v2c)
let v3a = Vec3 { 3, 2, 1 }
let v3b = Vec3 { 2, 1, 1 }
let v3c: Vec3 = add(v3a, v3b)
println(v3c)
return 0
}
```
The output of the program:
```
{ 7, 5 }
{ 5, 3, 2 }
```
Had to implement some name mangling when emitting functions to lay the groundwork for interfaces, and I noticed this gave me function overloads for free. Take that, C!
#compiler #programming