Skip to content

Commit bd73db6

Browse files
committed
refactor: migrate to rust 2024 edition
1 parent 380e118 commit bd73db6

File tree

12 files changed

+39
-40
lines changed

12 files changed

+39
-40
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
resolver = "2"
2+
resolver = "3"
33
members = [
44
"crates/belalang",
55
"crates/belalang_compiler",

crates/belalang/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "belalang"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55
publish = false
66
license = "Apache-2.0"
77

crates/belalang/src/main.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ fn main() {
1313
.get_matches();
1414

1515
match matches.subcommand() {
16-
None => {
17-
if let Some(filename) = matches.get_one::<String>("filename") {
18-
run(filename.into()).unwrap();
19-
} else {
20-
repl();
21-
}
22-
}
16+
None => match matches.get_one::<String>("filename") {
17+
Some(filename) => run(filename.into()).unwrap(),
18+
_ => repl(),
19+
},
2320
_ => unreachable!(),
2421
}
2522
}

crates/belalang_compiler/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "belalang_compiler"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55
publish = false
66
license = "Apache-2.0"
77

crates/belalang_compiler/src/ast/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl From<&Token> for Precedence {
4848
}
4949

5050
macro_rules! expect_peek {
51-
($self:expr, $token:pat) => {
51+
($self:expr_2021, $token:pat) => {
5252
if matches!($self.peek_token, $token) {
5353
$self.next_token()?;
5454
true
@@ -61,7 +61,7 @@ macro_rules! expect_peek {
6161
pub(super) use expect_peek;
6262

6363
macro_rules! optional_peek {
64-
($self:expr, $token:pat) => {
64+
($self:expr_2021, $token:pat) => {
6565
if matches!($self.peek_token, $token) {
6666
$self.next_token()?;
6767
true

crates/belalang_compiler/tests/common/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn test_parse_to_string(input: &str, expected: &str) {
1818

1919
#[macro_export]
2020
macro_rules! as_variant {
21-
($value:expr, $variant:path) => {
21+
($value:expr_2021, $variant:path) => {
2222
if let $variant(x) = $value {
2323
x
2424
} else {
@@ -29,28 +29,28 @@ macro_rules! as_variant {
2929

3030
#[macro_export]
3131
macro_rules! ident_has_name {
32-
($value:expr, $expected:expr) => {
32+
($value:expr_2021, $expected:expr_2021) => {
3333
assert_eq!($value.value, $expected);
3434
assert_eq!($value.token.to_string(), $expected.to_string());
3535
};
3636
}
3737

3838
#[macro_export]
3939
macro_rules! expr_variant {
40-
($value:expr, $variant:path = $expected:expr) => {
40+
($value:expr_2021, $variant:path = $expected:expr_2021) => {
4141
let v = as_variant!($value, $variant);
4242

4343
assert_eq!(v.value, $expected);
4444
assert_eq!(v.token.to_string(), $expected.to_string());
4545
};
46-
($value:expr, Infix => ($left_variant:path = $left:expr, $op:expr, $right_variant:path = $right:expr)) => {
46+
($value:expr_2021, Infix => ($left_variant:path = $left:expr_2021, $op:expr_2021, $right_variant:path = $right:expr_2021)) => {
4747
let v = as_variant!($value, ast::Expression::Infix);
4848

4949
expr_variant!(&*v.left, $left_variant = $left);
5050
expr_variant!(&*v.right, $right_variant = $right);
5151
assert_eq!(v.operator, $op);
5252
};
53-
($value: expr, Prefix => ($op:expr, $right_variant:path = $right:expr)) => {
53+
($value: expr_2021, Prefix => ($op:expr_2021, $right_variant:path = $right:expr_2021)) => {
5454
let v = as_variant!($value, ast::Expression::Prefix);
5555

5656
expr_variant!(&*v.right, $right_variant = $right);

crates/belalang_macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "belalang_macros"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55
publish = false
66
license = "Apache-2.0"
77

crates/belalang_vm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "belalang_vm"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55
publish = false
66
license = "Apache-2.0"
77

crates/belalang_vm/src/core/vm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::objects::integer::BelalangInteger;
1010
use crate::objects::string::BelalangString;
1111

1212
macro_rules! pop_object {
13-
($self:expr) => {
13+
($self:expr_2021) => {
1414
if let Ok(StackObject::Object(obj)) = $self.stack.pop() {
1515
obj.as_ptr()
1616
} else {

crates/belalang_vm/src/mem/heap.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,30 @@ impl Heap {
6666
/// - The type T matches the type that was originally allocated
6767
/// - No other parts of the program retain references to this memory after deallocation
6868
pub unsafe fn dealloc<T>(&mut self, ptr: NonNull<T>) -> Result<(), RuntimeError> {
69-
let layout = Layout::new::<T>();
70-
71-
let base_ptr = ptr.as_ptr() as *mut BelalangBase;
72-
73-
if let Some(start) = self.start {
74-
if start.as_ptr() == base_ptr {
75-
self.start = (*base_ptr).next;
76-
} else {
77-
let mut current = start;
78-
while let Some(next) = (*current.as_ptr()).next {
79-
if next.as_ptr() == base_ptr {
80-
(*current.as_ptr()).next = (*base_ptr).next;
81-
break;
69+
unsafe {
70+
let layout = Layout::new::<T>();
71+
72+
let base_ptr = ptr.as_ptr() as *mut BelalangBase;
73+
74+
if let Some(start) = self.start {
75+
if start.as_ptr() == base_ptr {
76+
self.start = (*base_ptr).next;
77+
} else {
78+
let mut current = start;
79+
while let Some(next) = (*current.as_ptr()).next {
80+
if next.as_ptr() == base_ptr {
81+
(*current.as_ptr()).next = (*base_ptr).next;
82+
break;
83+
}
84+
current = next;
8285
}
83-
current = next;
8486
}
8587
}
86-
}
8788

88-
dealloc(ptr.as_ptr() as *mut u8, layout);
89+
dealloc(ptr.as_ptr() as *mut u8, layout);
8990

90-
Ok(())
91+
Ok(())
92+
}
9193
}
9294
}
9395

0 commit comments

Comments
 (0)