Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit43118db

Browse files
committed
Remove None and NotImplemented payloads and replace with NoPayload
1 parent647cb08 commit43118db

File tree

4 files changed

+31
-30
lines changed

4 files changed

+31
-30
lines changed

‎vm/src/frame.rs‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,14 @@ impl Frame {
285285

286286
letmut out:Vec<Option<BigInt>> = elements
287287
.into_iter()
288-
.map(|x|match x.payload{
289-
PyObjectPayload::Integer{ref value} =>Some(value.clone()),
290-
PyObjectPayload::None =>None,
291-
_ =>panic!("Expect Int or None as BUILD_SLICE arguments, got {:?}", x),
288+
.map(|x|{
289+
if x.is(&vm.get_none()){
290+
None
291+
}elseifletPyObjectPayload::Integer{ref value} = x.payload{
292+
Some(value.clone())
293+
}else{
294+
panic!("Expect Int or None as BUILD_SLICE arguments, got {:?}", x);
295+
}
292296
})
293297
.collect();
294298

@@ -574,18 +578,15 @@ impl Frame {
574578
}
575579
bytecode::Instruction::PrintExpr =>{
576580
let expr =self.pop_value();
577-
match expr.payload{
578-
PyObjectPayload::None =>(),
579-
_ =>{
580-
let repr = vm.to_repr(&expr)?;
581-
builtins::builtin_print(
582-
vm,
583-
PyFuncArgs{
584-
args:vec![repr],
585-
kwargs:vec![],
586-
},
587-
)?;
588-
}
581+
if !expr.is(&vm.get_none()){
582+
let repr = vm.to_repr(&expr)?;
583+
builtins::builtin_print(
584+
vm,
585+
PyFuncArgs{
586+
args:vec![repr],
587+
kwargs:vec![],
588+
},
589+
)?;
589590
}
590591
Ok(None)
591592
}

‎vm/src/pyobject.rs‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub struct PyContext {
155155

156156
fn_nothing() ->PyObjectRef{
157157
PyObject{
158-
payload:PyObjectPayload::None,
158+
payload:PyObjectPayload::NoPayload,
159159
typ:None,
160160
}
161161
.into_ref()
@@ -223,14 +223,14 @@ impl PyContext {
223223
let exceptions = exceptions::ExceptionZoo::new(&type_type,&object_type,&dict_type);
224224

225225
let none =PyObject::new(
226-
PyObjectPayload::None,
226+
PyObjectPayload::NoPayload,
227227
create_type("NoneType",&type_type,&object_type,&dict_type),
228228
);
229229

230-
let ellipsis =PyObject::new(PyObjectPayload::None, ellipsis_type.clone());
230+
let ellipsis =PyObject::new(PyObjectPayload::NoPayload, ellipsis_type.clone());
231231

232232
let not_implemented =PyObject::new(
233-
PyObjectPayload::NotImplemented,
233+
PyObjectPayload::NoPayload,
234234
create_type("NotImplementedType",&type_type,&object_type,&dict_type),
235235
);
236236

@@ -1484,8 +1484,7 @@ pub enum PyObjectPayload {
14841484
name:String,
14851485
scope:ScopeRef,
14861486
},
1487-
None,
1488-
NotImplemented,
1487+
NoPayload,
14891488
Class{
14901489
name:String,
14911490
dict:RefCell<PyAttributes>,
@@ -1531,8 +1530,7 @@ impl fmt::Debug for PyObjectPayload {
15311530
ref object,
15321531
} =>write!(f,"bound-method: {:?} of {:?}", function, object),
15331532
PyObjectPayload::Module{ ..} =>write!(f,"module"),
1534-
PyObjectPayload::None =>write!(f,"None"),
1535-
PyObjectPayload::NotImplemented =>write!(f,"NotImplemented"),
1533+
PyObjectPayload::NoPayload =>write!(f,"NoPayload"),
15361534
PyObjectPayload::Class{ref name, ..} =>write!(f,"class {:?}", name),
15371535
PyObjectPayload::Instance{ ..} =>write!(f,"instance"),
15381536
PyObjectPayload::RustFunction{ ..} =>write!(f,"rust function"),

‎vm/src/stdlib/json.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::obj::{
1111
objtype,
1212
};
1313
usecrate::pyobject::{
14-
create_type,DictProtocol,PyContext,PyFuncArgs,PyObjectPayload,PyObjectRef,PyResult,
14+
create_type,DictProtocol,IdProtocol,PyContext,PyFuncArgs,PyObjectRef,PyResult,
1515
TypeProtocol,
1616
};
1717
usecrate::VirtualMachine;
@@ -69,7 +69,7 @@ impl<'s> serde::Serialize for PyObjectSerializer<'s> {
6969
map.serialize_entry(&key,&self.clone_with_object(&e.1))?;
7070
}
7171
map.end()
72-
}elseifletPyObjectPayload::None =self.pyobject.payload{
72+
}elseifself.pyobject.is(&self.vm.get_none()){
7373
serializer.serialize_none()
7474
}else{
7575
Err(serde::ser::Error::custom(format!(

‎vm/src/vm.rs‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,12 @@ impl VirtualMachine {
473473
// Add missing positional arguments, if we have fewer positional arguments than the
474474
// function definition calls for
475475
if nargs < nexpected_args{
476-
let available_defaults =match defaults.payload{
477-
PyObjectPayload::Sequence{ref elements} => elements.borrow().clone(),
478-
PyObjectPayload::None =>vec![],
479-
_ =>panic!("function defaults not tuple or None"),
476+
let available_defaults =if defaults.is(&self.get_none()){
477+
vec![]
478+
}elseifletPyObjectPayload::Sequence{ref elements} = defaults.payload{
479+
elements.borrow().clone()
480+
}else{
481+
panic!("function defaults not tuple or None");
480482
};
481483

482484
// Given the number of defaults available, check all the arguments for which we

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp