Skip to content

Commit 8105ec3

Browse files
refactor(vm): address clippy linter comments.
1 parent c3118d4 commit 8105ec3

5 files changed

Lines changed: 14 additions & 17 deletions

File tree

compiler/src/modules/vm/builtins.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ impl<'a> VM<'a> {
10721072
if was_yielded {
10731073
// Check if it yielded a sleep request (negative int = sleep cycles)
10741074
let new_sleep = if result.is_int() && result.as_int() < 0 {
1075-
(-result.as_int()) as i64
1075+
-result.as_int()
10761076
} else { 0 };
10771077
next_queue.push((coro, new_sleep));
10781078
} else if result.is_none() {

compiler/src/modules/vm/handlers/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'a> VM<'a> {
147147
args.extend_from_slice(&positional);
148148
for a in &args { self.push(*a); }
149149
let argc = args.len() as u16;
150-
let encoded = ((0u16) << 8) | argc;
150+
let encoded = argc;
151151
self.exec_call(encoded, chunk, slots)?;
152152
self.pop()?; // discard __init__ return
153153
}

compiler/src/modules/vm/handlers/methods.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,13 @@ impl<'a> VM<'a> {
8888
return Ok(());
8989
}
9090
if cls_val.is_heap()
91-
&& let HeapObj::Class(_, methods) = self.heap.get(cls_val) {
92-
if let Some((_, mv)) = methods.iter().find(|(n, _)| n == name) {
93-
let mv = *mv;
91+
&& let HeapObj::Class(_, methods) = self.heap.get(cls_val)
92+
&& let Some((_, mv)) = methods.iter().find(|(n, _)| n == name) {
93+
let mv = *mv;
9494
let bound = self.heap.alloc(HeapObj::BoundUserMethod(obj, mv))?;
9595
self.push(bound);
9696
return Ok(());
9797
}
98-
}
9998
return Err(VmErr::Type("attribute not found"));
10099
}
101100

compiler/src/modules/vm/mod.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,11 @@ impl<'a> VM<'a> {
251251
let (params, _, _, _) = vm.functions[fi];
252252
let bm = &vm.body_maps[fi];
253253
params.iter().map(|p| {
254-
if p.starts_with("**") {
255-
let slot = bm.get(&alloc::format!("{}_0", &p[2..])).copied().unwrap_or(usize::MAX);
254+
if let Some(stripped) = p.strip_prefix("**") {
255+
let slot = bm.get(&alloc::format!("{}_0", stripped)).copied().unwrap_or(usize::MAX);
256256
(ParamKind::DoubleStar, slot)
257-
} else if p.starts_with('*') {
258-
let slot = bm.get(&alloc::format!("{}_0", &p[1..])).copied().unwrap_or(usize::MAX);
257+
} else if let Some(stripped) = p.strip_prefix('*') {
258+
let slot = bm.get(&alloc::format!("{}_0", stripped)).copied().unwrap_or(usize::MAX);
259259
(ParamKind::Star, slot)
260260
} else {
261261
let slot = bm.get(&alloc::format!("{}_0", p)).copied().unwrap_or(usize::MAX);
@@ -566,10 +566,10 @@ impl<'a> VM<'a> {
566566
if obj.is_heap()
567567
&& let HeapObj::Instance(cls_val, _) = self.heap.get(obj) {
568568
let cls_val = *cls_val;
569-
if cls_val.is_heap() {
570-
if let HeapObj::Class(_, methods) = self.heap.get(cls_val)
571-
&& let Some((_, mv)) = methods.iter().find(|(n, _)| n == name.as_str()) {
572-
let mv = *mv;
569+
if cls_val.is_heap()
570+
&& let HeapObj::Class(_, methods) = self.heap.get(cls_val)
571+
&& let Some((_, mv)) = methods.iter().find(|(n, _)| n == name.as_str()) {
572+
let mv = *mv;
573573
// Call the method with self prepended
574574
self.push(mv);
575575
self.push(obj);
@@ -578,7 +578,6 @@ impl<'a> VM<'a> {
578578
let encoded = ((kw_flat.len() as u16 / 2) << 8) | argc;
579579
return self.exec_call(encoded, chunk, slots);
580580
}
581-
}
582581
}
583582
let method_id = handlers::methods::lookup_method(ty, name.as_str())
584583
.ok_or(VmErr::Type("'object' has no attribute"))?;

compiler/src/modules/vm/ops.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ impl<'a> VM<'a> {
9999
HeapObj::BoundMethod(..) => "builtin_function_or_method",
100100
HeapObj::NativeFn(_) => "builtin_function_or_method",
101101
HeapObj::Class(_name, _) => "type",
102-
103-
HeapObj::BoundUserMethod(_, _) => "<bound method>".into(),
102+
HeapObj::BoundUserMethod(_, _) => "<bound method>",
104103
HeapObj::Instance(..) => "object",
105104
HeapObj::Coroutine(..) => "coroutine",
106105
}}

0 commit comments

Comments
 (0)