Skip to content

Commit fae776d

Browse files
Merge pull request #638 from adrian17/tuple_list
Convert most tuple/list methods to new args style
2 parents adde4e7 + 1053119 commit fae776d

File tree

6 files changed

+444
-709
lines changed

6 files changed

+444
-709
lines changed

vm/src/frame.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::obj::objstr;
2121
use crate::obj::objtype;
2222
use crate::pyobject::{
2323
DictProtocol, IdProtocol, PyFuncArgs, PyObject, PyObjectPayload, PyObjectRef, PyResult,
24-
TypeProtocol,
24+
TryFromObject, TypeProtocol,
2525
};
2626
use crate::vm::VirtualMachine;
2727

@@ -138,14 +138,7 @@ impl Frame {
138138
vm.ctx.new_int(lineno.get_row()),
139139
vm.ctx.new_str(run_obj_name.clone()),
140140
]);
141-
objlist::list_append(
142-
vm,
143-
PyFuncArgs {
144-
args: vec![traceback, pos],
145-
kwargs: vec![],
146-
},
147-
)
148-
.unwrap();
141+
objlist::PyListRef::try_from_object(vm, traceback)?.append(pos, vm);
149142
// exception.__trace
150143
match self.unwind_exception(vm, exception) {
151144
None => {}
@@ -312,13 +305,7 @@ impl Frame {
312305
bytecode::Instruction::ListAppend { i } => {
313306
let list_obj = self.nth_value(*i);
314307
let item = self.pop_value();
315-
objlist::list_append(
316-
vm,
317-
PyFuncArgs {
318-
args: vec![list_obj.clone(), item],
319-
kwargs: vec![],
320-
},
321-
)?;
308+
objlist::PyListRef::try_from_object(vm, list_obj)?.append(item, vm);
322309
Ok(None)
323310
}
324311
bytecode::Instruction::SetAdd { i } => {

vm/src/function.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ where
4444
_payload: PhantomData,
4545
}
4646
}
47+
48+
pub fn as_object(&self) -> &PyObjectRef {
49+
&self.obj
50+
}
51+
pub fn into_object(self) -> PyObjectRef {
52+
self.obj
53+
}
4754
}
4855

4956
impl<T> Deref for PyRef<T>

vm/src/obj/objfloat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl PyFloatRef {
152152
}
153153
}
154154

155-
fn new_str(cls: PyObjectRef, arg: PyObjectRef, vm: &mut VirtualMachine) -> PyResult {
155+
fn new_float(cls: PyObjectRef, arg: PyObjectRef, vm: &mut VirtualMachine) -> PyResult {
156156
let value = if objtype::isinstance(&arg, &vm.ctx.float_type()) {
157157
get_value(&arg)
158158
} else if objtype::isinstance(&arg, &vm.ctx.int_type()) {
@@ -373,7 +373,7 @@ pub fn init(context: &PyContext) {
373373
context.set_attr(&float_type, "__radd__", context.new_rustfunc(PyFloatRef::add));
374374
context.set_attr(&float_type, "__divmod__", context.new_rustfunc(PyFloatRef::divmod));
375375
context.set_attr(&float_type, "__floordiv__", context.new_rustfunc(PyFloatRef::floordiv));
376-
context.set_attr(&float_type, "__new__", context.new_rustfunc(PyFloatRef::new_str));
376+
context.set_attr(&float_type, "__new__", context.new_rustfunc(PyFloatRef::new_float));
377377
context.set_attr(&float_type, "__mod__", context.new_rustfunc(PyFloatRef::mod_));
378378
context.set_attr(&float_type, "__neg__", context.new_rustfunc(PyFloatRef::neg));
379379
context.set_attr(&float_type, "__pow__", context.new_rustfunc(PyFloatRef::pow));

0 commit comments

Comments
 (0)