Skip to content

Convert most tuple/list methods to new args style #638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions vm/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::obj::objstr;
use crate::obj::objtype;
use crate::pyobject::{
DictProtocol, IdProtocol, PyFuncArgs, PyObject, PyObjectPayload, PyObjectRef, PyResult,
TypeProtocol,
TryFromObject, TypeProtocol,
};
use crate::vm::VirtualMachine;

Expand Down Expand Up @@ -138,14 +138,7 @@ impl Frame {
vm.ctx.new_int(lineno.get_row()),
vm.ctx.new_str(run_obj_name.clone()),
]);
objlist::list_append(
vm,
PyFuncArgs {
args: vec![traceback, pos],
kwargs: vec![],
},
)
.unwrap();
objlist::PyListRef::try_from_object(vm, traceback)?.append(pos, vm);
// exception.__trace
match self.unwind_exception(vm, exception) {
None => {}
Expand Down Expand Up @@ -312,13 +305,7 @@ impl Frame {
bytecode::Instruction::ListAppend { i } => {
let list_obj = self.nth_value(*i);
let item = self.pop_value();
objlist::list_append(
vm,
PyFuncArgs {
args: vec![list_obj.clone(), item],
kwargs: vec![],
},
)?;
objlist::PyListRef::try_from_object(vm, list_obj)?.append(item, vm);
Ok(None)
}
bytecode::Instruction::SetAdd { i } => {
Expand Down
7 changes: 7 additions & 0 deletions vm/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ where
_payload: PhantomData,
}
}

pub fn as_object(&self) -> &PyObjectRef {
&self.obj
}
pub fn into_object(self) -> PyObjectRef {
self.obj
}
}

impl<T> Deref for PyRef<T>
Expand Down
4 changes: 2 additions & 2 deletions vm/src/obj/objfloat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl PyFloatRef {
}
}

fn new_str(cls: PyObjectRef, arg: PyObjectRef, vm: &mut VirtualMachine) -> PyResult {
fn new_float(cls: PyObjectRef, arg: PyObjectRef, vm: &mut VirtualMachine) -> PyResult {
let value = if objtype::isinstance(&arg, &vm.ctx.float_type()) {
get_value(&arg)
} else if objtype::isinstance(&arg, &vm.ctx.int_type()) {
Expand Down Expand Up @@ -373,7 +373,7 @@ pub fn init(context: &PyContext) {
context.set_attr(&float_type, "__radd__", context.new_rustfunc(PyFloatRef::add));
context.set_attr(&float_type, "__divmod__", context.new_rustfunc(PyFloatRef::divmod));
context.set_attr(&float_type, "__floordiv__", context.new_rustfunc(PyFloatRef::floordiv));
context.set_attr(&float_type, "__new__", context.new_rustfunc(PyFloatRef::new_str));
context.set_attr(&float_type, "__new__", context.new_rustfunc(PyFloatRef::new_float));
context.set_attr(&float_type, "__mod__", context.new_rustfunc(PyFloatRef::mod_));
context.set_attr(&float_type, "__neg__", context.new_rustfunc(PyFloatRef::neg));
context.set_attr(&float_type, "__pow__", context.new_rustfunc(PyFloatRef::pow));
Expand Down
Loading