mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Format code properly and try to implement append function
This commit is contained in:
1 parent
51acd6c4b5
commit
4ada085234
3 files changed
+15
-13
No files matched your search
+11
-7
@@ -1,5 +1,5 @@
|
||||
use super::objsequence::PySliceableSequence;
|
||||
use super::pyobject::{PyObjectKind, PyObjectRef, PyResult, PyObject, PyFuncArgs};
|
||||
use super::pyobject::{PyFuncArgs, PyObject, PyObjectKind, PyObjectRef, PyResult};
|
||||
use super::vm::VirtualMachine;
|
||||
use std::collections::HashMap;
|
||||
|
||||
@@ -25,10 +25,16 @@ pub fn set_item(
|
||||
|
||||
fn append(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
// TODO: Implement objlist::append
|
||||
// println!("{:?}", args);
|
||||
// if let PyObjectKind
|
||||
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())
|
||||
} else {
|
||||
unimplemented!("Raise error when list.append is called with no list")
|
||||
// Err()
|
||||
}
|
||||
// Ok(vm.new_bound_method(args.args[0].clone(), args.args[1].clone()))
|
||||
Ok(vm.get_none())
|
||||
}
|
||||
|
||||
pub fn create_type(type_type: PyObjectRef) -> PyObjectRef {
|
||||
@@ -36,9 +42,7 @@ pub fn create_type(type_type: PyObjectRef) -> PyObjectRef {
|
||||
dict.insert(
|
||||
"append".to_string(),
|
||||
PyObject::new(
|
||||
PyObjectKind::RustFunction {
|
||||
function: append,
|
||||
},
|
||||
PyObjectKind::RustFunction { function: append },
|
||||
type_type.clone(),
|
||||
),
|
||||
);
|
||||
|
||||
+2
-2
@@ -91,10 +91,10 @@ impl PyContext {
|
||||
PyObject::new(PyObjectKind::Boolean { value: b }, self.type_type.clone())
|
||||
}
|
||||
|
||||
pub fn new_tuple(&self) -> PyObjectRef {
|
||||
pub fn new_tuple(&self, elements: Option<Vec<PyObjectRef>>) -> PyObjectRef {
|
||||
PyObject::new(
|
||||
PyObjectKind::Tuple {
|
||||
elements: Vec::new(),
|
||||
elements: elements.unwrap_or(Vec::new()),
|
||||
},
|
||||
self.type_type.clone(),
|
||||
)
|
||||
|
||||
+2
-4
@@ -594,15 +594,13 @@ impl VirtualMachine {
|
||||
}
|
||||
bytecode::Instruction::BuildList { size } => {
|
||||
let elements = self.pop_multiple(*size);
|
||||
let list_obj =
|
||||
self.context().new_list( Some(elements) );
|
||||
let list_obj = self.context().new_list(Some(elements));
|
||||
self.push_value(list_obj);
|
||||
None
|
||||
}
|
||||
bytecode::Instruction::BuildTuple { size } => {
|
||||
let elements = self.pop_multiple(*size);
|
||||
let list_obj =
|
||||
PyObject::new(PyObjectKind::Tuple { elements: elements }, self.get_type());
|
||||
let list_obj = self.context().new_tuple(Some(elements));
|
||||
self.push_value(list_obj);
|
||||
None
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user