mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Borrow list object mutably and append item
This commit is contained in:
1 parent
4ada085234
commit
34bba7a257
2 files changed
+17
-10
No files matched your search
+5
-1
@@ -30,8 +30,12 @@ fn dir_locals(vm: &mut VirtualMachine) -> PyObjectRef {
|
||||
}
|
||||
|
||||
fn dir_object(vm: &mut VirtualMachine, _obj: PyObjectRef) -> PyObjectRef {
|
||||
// TODO: Implement dir for objects
|
||||
let d = vm.new_dict();
|
||||
// TODO: loop over dict of instance, next of class?
|
||||
// TODO: Implement dir for objects
|
||||
// for i in obj.iter_items() {
|
||||
// d.set_item(k, v);
|
||||
// }
|
||||
d
|
||||
}
|
||||
|
||||
|
||||
+12
-9
@@ -24,17 +24,20 @@ pub fn set_item(
|
||||
}
|
||||
|
||||
fn append(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
// TODO: Implement objlist::append
|
||||
trace!("list.append called with: {:?}", args);
|
||||
if let PyObjectKind::List { ref elements } = args.args[0].borrow().kind {
|
||||
warn!("implement append here: {:?}", elements);
|
||||
// elements.push(args.args[1].clone());
|
||||
Ok(vm.get_none())
|
||||
if args.args.len() == 2 {
|
||||
let l = args.args[0].clone();
|
||||
let o = args.args[1].clone();
|
||||
trace!("list.append called with: {:?}", args);
|
||||
let mut list_obj = l.borrow_mut();
|
||||
if let PyObjectKind::List { ref mut elements } = list_obj.kind {
|
||||
elements.push(o);
|
||||
Ok(vm.get_none())
|
||||
} else {
|
||||
Err(vm.new_exception("list.append is called with no list".to_string()))
|
||||
}
|
||||
} else {
|
||||
unimplemented!("Raise error when list.append is called with no list")
|
||||
// Err()
|
||||
Err(vm.new_exception("list.append requires two arguments".to_string()))
|
||||
}
|
||||
// Ok(vm.new_bound_method(args.args[0].clone(), args.args[1].clone()))
|
||||
}
|
||||
|
||||
pub fn create_type(type_type: PyObjectRef) -> PyObjectRef {
|
||||
|
||||
Reference in new issue
Block a user