A picture of 3 separate files in my programming language that form a dependency chain. main.os imports io.os and math.os, math.os imports io.os.
main.os:
```
import "math.os";
import "io.os";
fn main() {
io::print_msg("Hello from main.os!");
var v = math::Vec(1.0, 2.0);
println(math::dot(v, v));
var x = math::pow(2.0, 3);
println(x);
math::greet();
}
```
math.os:
```
import "io.os";
struct Vec(x: f32, y: f32) {
fn dot(v1: Vec, v2: Vec): f32 {
return v1.x * v2.x + v1.y * v2.y;
}
}
fn pow(x: f32, p: u32): f32 {
for _ in 1..p x = x * x;
return x;
}
fn greet() {
io::print_msg("Hello from math.os!");
}
```
io.os:
```
fn print_msg(msg: string) {
println(msg);
}
```
The output of the program:
```
Hello from main.os!
5.000000
16.000000
Hello from math.os!
```
I managed to implement a somewhat halfway decent module system. I'm not thrilled that the import needs the relative path but it'll do for now. Plus it handles the same file being imported multiple times across the compilation graph 😌
#compiler #llvm