Add type to Obj instantiation, and fix mutable borrow
* Objects will set their __ty__ during instantiation to the Obj type if no __ty__ has been set * In Object::get_vtable_attr we were borrowing the type as mutable, which was not necessary and causing issues when trying to borrow it mutably twice. This is probably because warnings of various types have been turned off and that will be investigated soon. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
11
src/obj.rs
11
src/obj.rs
@@ -147,8 +147,8 @@ pub trait Object: Debug + Display + Any + Trace {
|
|||||||
let mut ty = self.ty();
|
let mut ty = self.ty();
|
||||||
loop {
|
loop {
|
||||||
let vtable_entry =
|
let vtable_entry =
|
||||||
with_obj_downcast_mut(ty.clone(), |ty: &mut Ty| ty.vtable().get(name).cloned())
|
with_obj_downcast(ty.clone(), |ty: &Ty| ty.vtable().get(name).cloned()).map(
|
||||||
.map(|vtable_entry| {
|
|vtable_entry| {
|
||||||
let ptr = if obj_is_inst::<BuiltinFunction>(&vtable_entry)
|
let ptr = if obj_is_inst::<BuiltinFunction>(&vtable_entry)
|
||||||
|| obj_is_inst::<UserFunction>(&vtable_entry)
|
|| obj_is_inst::<UserFunction>(&vtable_entry)
|
||||||
{
|
{
|
||||||
@@ -161,7 +161,8 @@ pub trait Object: Debug + Display + Any + Trace {
|
|||||||
// floating around.
|
// floating around.
|
||||||
//self.set_attr(name, ptr.clone());
|
//self.set_attr(name, ptr.clone());
|
||||||
ptr
|
ptr
|
||||||
});
|
},
|
||||||
|
);
|
||||||
if vtable_entry.is_some() {
|
if vtable_entry.is_some() {
|
||||||
return vtable_entry;
|
return vtable_entry;
|
||||||
}
|
}
|
||||||
@@ -261,6 +262,10 @@ impl Debug for Obj {
|
|||||||
|
|
||||||
impl Object for Obj {
|
impl Object for Obj {
|
||||||
fn instantiate(&mut self) {
|
fn instantiate(&mut self) {
|
||||||
|
if self.get_attr("__ty__").is_none() {
|
||||||
|
let ty = BUILTINS.with_borrow(|builtins| builtins.get("Obj").expect("no Obj").clone());
|
||||||
|
self.set_attr("__ty__", ty);
|
||||||
|
}
|
||||||
self.is_instantiated = true;
|
self.is_instantiated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user