Skip to content

Commit 18f77ce

Browse files
committed
Merge branch 'master' into wasm-explicit-stdout
2 parents dac7501 + 8ec1af5 commit 18f77ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+677
-917
lines changed

tests/snippets/list.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,22 @@
2929
assert x > y, "list __gt__ failed"
3030

3131

32-
assert [1,2,'a'].pop() == 'a', "list pop failed"
32+
x = [0, 1, 2]
33+
assert x.pop() == 2
34+
assert x == [0, 1]
35+
36+
def test_pop(lst, idx, value, new_lst):
37+
assert lst.pop(idx) == value
38+
assert lst == new_lst
39+
test_pop([0, 1, 2], -1, 2, [0, 1])
40+
test_pop([0, 1, 2], 0, 0, [1, 2])
41+
test_pop([0, 1, 2], 1, 1, [0, 2])
42+
test_pop([0, 1, 2], 2, 2, [0, 1])
3343
assert_raises(IndexError, lambda: [].pop())
44+
assert_raises(IndexError, lambda: [].pop(0))
45+
assert_raises(IndexError, lambda: [].pop(-1))
46+
assert_raises(IndexError, lambda: [0].pop(1))
47+
assert_raises(IndexError, lambda: [0].pop(-2))
3448

3549
recursive = []
3650
recursive.append(recursive)

vm/src/compile.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use crate::bytecode::{self, CallType, CodeObject, Instruction};
99
use crate::error::CompileError;
1010
use crate::obj::objcode;
11-
use crate::pyobject::{PyObject, PyObjectPayload, PyObjectRef};
11+
use crate::pyobject::{PyObject, PyObjectRef};
1212
use num_complex::Complex64;
1313
use rustpython_parser::{ast, parser};
1414

@@ -49,12 +49,7 @@ pub fn compile(
4949

5050
let code = compiler.pop_code_object();
5151
trace!("Compilation completed: {:?}", code);
52-
Ok(PyObject::new(
53-
PyObjectPayload::AnyRustValue {
54-
value: Box::new(objcode::PyCode::new(code)),
55-
},
56-
code_type,
57-
))
52+
Ok(PyObject::new(objcode::PyCode::new(code), code_type))
5853
}
5954

6055
pub enum Mode {

vm/src/frame.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ use crate::obj::objslice::PySlice;
2222
use crate::obj::objstr;
2323
use crate::obj::objtype;
2424
use crate::pyobject::{
25-
DictProtocol, IdProtocol, PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectPayload2,
26-
PyObjectRef, PyResult, TryFromObject, TypeProtocol,
25+
DictProtocol, IdProtocol, PyContext, PyFuncArgs, PyObject, PyObjectRef, PyResult, PyValue,
26+
TryFromObject, TypeProtocol,
2727
};
2828
use crate::vm::VirtualMachine;
2929

@@ -181,7 +181,7 @@ pub struct Frame {
181181
pub lasti: RefCell<usize>, // index of last instruction ran
182182
}
183183

184-
impl PyObjectPayload2 for Frame {
184+
impl PyValue for Frame {
185185
fn required_type(ctx: &PyContext) -> PyObjectRef {
186186
ctx.frame_type()
187187
}
@@ -407,12 +407,7 @@ impl Frame {
407407
let stop = out[1].take();
408408
let step = if out.len() == 3 { out[2].take() } else { None };
409409

410-
let obj = PyObject::new(
411-
PyObjectPayload::AnyRustValue {
412-
value: Box::new(PySlice { start, stop, step }),
413-
},
414-
vm.ctx.slice_type(),
415-
);
410+
let obj = PyObject::new(PySlice { start, stop, step }, vm.ctx.slice_type());
416411
self.push_value(obj);
417412
Ok(None)
418413
}
@@ -706,11 +701,7 @@ impl Frame {
706701
}
707702
bytecode::Instruction::LoadBuildClass => {
708703
let rustfunc = PyObject::new(
709-
PyObjectPayload::AnyRustValue {
710-
value: Box::new(PyBuiltinFunction::new(Box::new(
711-
builtins::builtin_build_class_,
712-
))),
713-
},
704+
PyBuiltinFunction::new(Box::new(builtins::builtin_build_class_)),
714705
vm.ctx.type_type(),
715706
);
716707
self.push_value(rustfunc);

vm/src/function.rs

Lines changed: 0 additions & 118 deletions
This file was deleted.

vm/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ pub mod eval;
4141
mod exceptions;
4242
pub mod format;
4343
pub mod frame;
44-
pub mod function;
4544
pub mod import;
4645
pub mod obj;
4746
pub mod pyobject;

vm/src/obj/objbuiltinfunc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use std::fmt;
22

3-
use crate::pyobject::{PyContext, PyNativeFunc, PyObjectPayload2, PyObjectRef};
3+
use crate::pyobject::{PyContext, PyNativeFunc, PyObjectRef, PyValue};
44

55
pub struct PyBuiltinFunction {
66
// TODO: shouldn't be public
77
pub value: PyNativeFunc,
88
}
99

10-
impl PyObjectPayload2 for PyBuiltinFunction {
10+
impl PyValue for PyBuiltinFunction {
1111
fn required_type(ctx: &PyContext) -> PyObjectRef {
1212
ctx.builtin_function_or_method_type()
1313
}

vm/src/obj/objbytearray.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use std::fmt::Write;
55
use std::ops::{Deref, DerefMut};
66

77
use crate::pyobject::{
8-
PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectPayload2, PyObjectRef, PyResult,
9-
TypeProtocol,
8+
PyContext, PyFuncArgs, PyObject, PyObjectRef, PyResult, PyValue, TypeProtocol,
109
};
1110

1211
use super::objint;
@@ -29,7 +28,7 @@ impl PyByteArray {
2928
}
3029
}
3130

32-
impl PyObjectPayload2 for PyByteArray {
31+
impl PyValue for PyByteArray {
3332
fn required_type(ctx: &PyContext) -> PyObjectRef {
3433
ctx.bytearray_type()
3534
}
@@ -173,12 +172,7 @@ fn bytearray_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
173172
} else {
174173
vec![]
175174
};
176-
Ok(PyObject::new(
177-
PyObjectPayload::AnyRustValue {
178-
value: Box::new(PyByteArray::new(value)),
179-
},
180-
cls.clone(),
181-
))
175+
Ok(PyObject::new(PyByteArray::new(value), cls.clone()))
182176
}
183177

184178
fn bytesarray_len(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {

vm/src/obj/objbytes.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use std::ops::Deref;
55
use super::objint;
66
use super::objtype;
77
use crate::pyobject::{
8-
PyContext, PyFuncArgs, PyIteratorValue, PyObject, PyObjectPayload, PyObjectPayload2,
9-
PyObjectRef, PyResult, TypeProtocol,
8+
PyContext, PyFuncArgs, PyIteratorValue, PyObject, PyObjectRef, PyResult, PyValue, TypeProtocol,
109
};
1110
use crate::vm::VirtualMachine;
1211
use num_traits::ToPrimitive;
@@ -30,7 +29,7 @@ impl Deref for PyBytes {
3029
}
3130
}
3231

33-
impl PyObjectPayload2 for PyBytes {
32+
impl PyValue for PyBytes {
3433
fn required_type(ctx: &PyContext) -> PyObjectRef {
3534
ctx.bytes_type()
3635
}
@@ -95,12 +94,7 @@ fn bytes_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
9594
vec![]
9695
};
9796

98-
Ok(PyObject::new(
99-
PyObjectPayload::AnyRustValue {
100-
value: Box::new(PyBytes::new(value)),
101-
},
102-
cls.clone(),
103-
))
97+
Ok(PyObject::new(PyBytes::new(value), cls.clone()))
10498
}
10599

106100
fn bytes_eq(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
@@ -209,11 +203,9 @@ fn bytes_iter(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
209203
arg_check!(vm, args, required = [(obj, Some(vm.ctx.bytes_type()))]);
210204

211205
let iter_obj = PyObject::new(
212-
PyObjectPayload::AnyRustValue {
213-
value: Box::new(PyIteratorValue {
214-
position: Cell::new(0),
215-
iterated_obj: obj.clone(),
216-
}),
206+
PyIteratorValue {
207+
position: Cell::new(0),
208+
iterated_obj: obj.clone(),
217209
},
218210
vm.ctx.iter_type(),
219211
);

vm/src/obj/objcode.rs

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

55
use crate::bytecode;
66
use crate::pyobject::{
7-
IdProtocol, PyContext, PyFuncArgs, PyObjectPayload2, PyObjectRef, PyResult, TypeProtocol,
7+
IdProtocol, PyContext, PyFuncArgs, PyObjectRef, PyResult, PyValue, TypeProtocol,
88
};
99
use crate::vm::VirtualMachine;
1010
use std::fmt;
@@ -25,7 +25,7 @@ impl fmt::Debug for PyCode {
2525
}
2626
}
2727

28-
impl PyObjectPayload2 for PyCode {
28+
impl PyValue for PyCode {
2929
fn required_type(ctx: &PyContext) -> PyObjectRef {
3030
ctx.code_type()
3131
}

vm/src/obj/objcomplex.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use super::objfloat;
22
use super::objint;
33
use super::objtype;
44
use crate::pyobject::{
5-
PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectPayload2, PyObjectRef, PyResult,
6-
TypeProtocol,
5+
PyContext, PyFuncArgs, PyObject, PyObjectRef, PyResult, PyValue, TypeProtocol,
76
};
87
use crate::vm::VirtualMachine;
98
use num_complex::Complex64;
@@ -14,7 +13,7 @@ pub struct PyComplex {
1413
value: Complex64,
1514
}
1615

17-
impl PyObjectPayload2 for PyComplex {
16+
impl PyValue for PyComplex {
1817
fn required_type(ctx: &PyContext) -> PyObjectRef {
1918
ctx.complex_type()
2019
}
@@ -90,12 +89,7 @@ fn complex_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
9089

9190
let value = Complex64::new(real, imag);
9291

93-
Ok(PyObject::new(
94-
PyObjectPayload::AnyRustValue {
95-
value: Box::new(PyComplex { value }),
96-
},
97-
cls.clone(),
98-
))
92+
Ok(PyObject::new(PyComplex { value }, cls.clone()))
9993
}
10094

10195
fn complex_real(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {

0 commit comments

Comments
 (0)