Skip to content

Commit 77a2c32

Browse files
Chore: Add handle_load_attr to methods.
1 parent 1ebe98b commit 77a2c32

3 files changed

Lines changed: 14 additions & 78 deletions

File tree

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

Lines changed: 0 additions & 77 deletions
This file was deleted.

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ fn title_case(s: &str) -> String {
7070
.join(" ")
7171
}
7272

73+
impl<'a> VM<'a> {
74+
pub(crate) fn handle_load_attr(&mut self, name_idx: u16, chunk: &SSAChunk) -> Result<(), VmErr> {
75+
let name = chunk.names.get(name_idx as usize)
76+
.ok_or(VmErr::Runtime("LoadAttr: bad name index"))?;
77+
let obj = self.pop()?;
78+
let ty = self.type_name(obj);
79+
let method_id = lookup_method(ty, name.as_str())
80+
.ok_or(VmErr::Type("'object' has no attribute"))?;
81+
let bound = self.heap.alloc(HeapObj::BoundMethod(obj, method_id))?;
82+
self.push(bound);
83+
Ok(())
84+
}
85+
}
86+
7387
/// One macro that generates: enum, name lookup, dispatcher.
7488
/// Each row: (Variant, "name", category, |vm, recv, pos| body)
7589
/// Category `mutating` adds an automatic mark_impure() after the body.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// vm/handlers/mod.rs
22

33
pub(crate) mod arith;
4-
pub(crate) mod attr;
54
pub(crate) mod data;
65
pub(crate) mod function;
76
pub(crate) mod methods;

0 commit comments

Comments
 (0)