Skip to content

Commit 3ae9004

Browse files
committed
backup commit(soon will be removed)
1 parent 1eb67b9 commit 3ae9004

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

vm/src/builtins/dict.rs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use crossbeam_utils::atomic::AtomicCell;
22
use std::fmt;
3+
use std::iter::FromIterator;
34
use std::mem::size_of;
45

56
use super::pystr::PyStrRef;
67
use super::pytype::PyTypeRef;
78
use super::set::PySet;
89
use super::IterStatus;
10+
use crate::builtins::list::PyList;
911
use crate::dictdatatype::{self, DictKey};
1012
use crate::exceptions::PyBaseExceptionRef;
1113
use crate::function::{ArgIterable, FuncArgs, KwArgs, OptionalArg};
@@ -15,7 +17,7 @@ use crate::vm::{ReprGuard, VirtualMachine};
1517
use crate::{
1618
IdProtocol, IntoPyObject, ItemProtocol, PyArithmaticValue::*, PyAttributes, PyClassDef,
1719
PyClassImpl, PyComparisonValue, PyContext, PyObjectRef, PyRef, PyResult, PyValue,
18-
TryFromBorrowedObject, TypeProtocol,
20+
TryFromBorrowedObject, TryFromObject, TypeProtocol,
1921
};
2022

2123
pub type DictContentType = dictdatatype::Dict;
@@ -957,7 +959,47 @@ pub struct PyMapping {
957959
Option<fn(PyObjectRef, PyObjectRef, Option<PyObjectRef>, &VirtualMachine) -> PyResult<()>>,
958960
}
959961

960-
impl PyMapping {}
962+
impl PyMapping {
963+
fn method_output_as_list(obj: PyObjectRef, method_name: &str, vm: &VirtualMachine) -> PyResult {
964+
let meth_output = vm.call_method(&obj, method_name, ())?;
965+
if meth_output.is(&vm.ctx.types.list_type) {
966+
return Ok(meth_output);
967+
}
968+
969+
iterator::get_iter(vm, meth_output)
970+
// TODO : iterator to pylist
971+
}
972+
973+
#[inline]
974+
pub fn check(cls: PyTypeRef, vm: &VirtualMachine) -> bool {
975+
// TODO : do check mapping_protocol and subscript
976+
true
977+
}
978+
979+
fn items(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyDictItems> {
980+
if obj.is(&vm.ctx.types.dict_type) {
981+
Ok(PyDict::items(PyDictRef::try_from_object(vm, obj)?))
982+
} else {
983+
method_output_as_list(obj, "items", vm)
984+
}
985+
}
986+
987+
fn keys(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyDictKeys> {
988+
if obj.is(&vm.ctx.types.dict_type) {
989+
Ok(PyDict::keys(PyDictRef::try_from_object(vm, obj)?))
990+
} else {
991+
method_output_as_list(obj, "keys", vm)
992+
}
993+
}
994+
995+
fn values(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyDictValues> {
996+
if obj.is(&vm.ctx.types.dict_type) {
997+
Ok(PyDict::values(PyDictRef::try_from_object(vm, obj)?))
998+
} else {
999+
method_output_as_list(obj, "values", vm)
1000+
}
1001+
}
1002+
}
9611003

9621004
impl TryFromBorrowedObject for PyMapping {
9631005
fn try_from_borrowed_object(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult<Self> {

vm/src/stdlib/winapi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use super::os::errno_err;
44
use crate::{
5-
builtins::{PyDictRef, PyStrRef},
5+
builtins::{dict::PyMapping, PyDictRef, PyStrRef},
66
exceptions::IntoPyException,
77
function::OptionalArg,
88
PyObjectRef, PyResult, PySequence, TryFromObject, VirtualMachine,
@@ -117,7 +117,7 @@ struct CreateProcessArgs {
117117
#[pyarg(positional)]
118118
creation_flags: u32,
119119
#[pyarg(positional)]
120-
env_mapping: Option<PyDictRef>,
120+
env_mapping: Option<PyMapping>,
121121
#[pyarg(positional)]
122122
current_dir: Option<PyStrRef>,
123123
#[pyarg(positional)]

0 commit comments

Comments
 (0)