<<

wlab

WLAB (WLAng Bootstrap) is an LLVM-based compiler written from scratch (github).

Features

Example program

1#![declare_crate(hello_world)]
2
3struct Messages {
4 first: str,
5 second: str,
6 override: bool,
7};
8
9fn get_messages() -> Messages {
10 /*
11 * The last statement in a code block will be implicitly returned if it is
12 * not terminated by a semicolon
13 */
14
15 Messages {
16 override: true,
17 first: "This will be printed first",
18 second: "This will be not printed",
19 }
20}
21
22fn main() {
23 // Variable types are automatically inferred //
24 let mut messages = get_messages();
25
26 // `if` statements do not require parenthesis //
27 if messages.override {
28 messages.second = "This will be printed second";
29 }
30
31 std::println(messages.first);
32 std::println(messages.second);
33
34 // `if` can be used as an expression //
35 let third_message = if 2 + 2 == 4 {
36 "This will be printed third"
37 } else {
38 "This will not be printed"
39 };
40
41 std::println(third_message);
42}

Error messages

src:

1#![declare_crate(a)]
2
3fn foo(x: bool) {
4 if x {
5 loop {std::println("this will loop forever")};
6 } else {
7 std::exit(1);
8 }
9
10 std::println("This will never be printed")
11}

error:

image

src:

1#![declare_crate(a)]
2
3struct Foo {
4 x: i32,
5 y: i32,
6};
7
8fn main() {
9 let foo = Foo { x: 6, y: 12 }; // by default all variables are immutable
10
11 foo.y = 10;
12}

error:

Screenshot from 2024-09-14 16-03-48