Files
boring-lang/examples/math/main.bl

84 lines
1.3 KiB
Plaintext
Raw Normal View History

2021-05-29 12:16:03 -06:00
// adds a and b, but also 4 for some reason
2021-05-28 23:57:07 -06:00
fn add(a: I32, b: I32): I32 {
2021-05-30 09:57:41 -06:00
let foo = 4; // because I feel like it
2021-05-29 11:01:34 -06:00
let test_float: F32 = {
10.2
};
2021-06-01 23:05:17 -06:00
test_float = 5.0;
2021-05-05 19:32:55 -06:00
a + b + foo
2020-04-19 22:22:15 -06:00
}
2021-05-28 23:57:07 -06:00
fn subtract(a: I32, b: I32): I32 {
2020-04-19 22:22:15 -06:00
a - b
}
2021-05-30 09:57:41 -06:00
fn return_type_test(a: F64): F64 {
return a * 2.0;
}
fn i_hate_this(a: F64): F64 {
return {
return {
return a;
};
};
}
2021-05-30 10:02:58 -06:00
fn unit_function() {
let a: I32 = 4;
}
2021-06-12 12:26:53 -06:00
fn main(): I32 {
add(4, subtract(5, 2))
}
2021-06-12 10:59:58 -06:00
fn returns_user(): User {
return User{
id: 4,
};
}
2021-06-12 12:26:53 -06:00
fn get_user_id(): U64 {
let user = returns_user();
2021-06-12 12:47:10 -06:00
user.id = 5;
2021-06-12 12:26:53 -06:00
return user.id;
2020-04-19 22:22:15 -06:00
}
2021-06-11 20:59:51 -06:00
2021-06-26 17:47:52 -06:00
fn use_method(user: User): U64 {
return user.get_id();
}
2021-06-11 20:59:51 -06:00
type User struct {
id: U64,
}
2021-06-13 10:38:13 -06:00
impl User {
fn new(id: U64): Self {
return Self{
id: id,
};
}
fn get_id(self: Self): U64 {
return self.id;
}
}
2021-07-17 15:40:22 -06:00
// type TestTrait trait {
// fn classMethod(id: I64): Self;
// fn instanceMethod(self: Self): I64;
// fn defaultImpl(self: Self): I64 {
// return self.instanceMethod;
// }
// }
//
// impl TestTrait for User {
// fn classMethod(id: I64): Self {
// return User{id: id,};
// }
// fn instanceMethod(self: Self): I64 {
// return self.get_id();
// }
// }