wlab
WLAB (WLAng Bootstrap) is an LLVM-based compiler written from scratch (Github).
Features
- Helpful error messages
- Name Mangling
- DWARF debug info
- Visibility
- Function and struct attributes
- Multi-file support
- If statements
- Type inference
- Structs
Example program
1 #![declare_crate(hello_world)]
 2 
 3 struct Messages {
 4     first: str,
 5     second: str,
 6     override: bool,
 7 };
 8 
 9 fn 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 
 22 fn 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 
 3 fn 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:
src:
1 #![declare_crate(a)]
 2 
 3 struct Foo {
 4     x: i32,
 5     y: i32,
 6 };
 7 
 8 fn main() {
 9     let foo = Foo { x: 6, y: 12 }; // by default all variables are immutable
 10 
 11     foo.y = 10;
 12 }
 
error: