|
1 | 1 | use super::objdict::{self, PyDictRef};
|
2 | 2 | use super::objlist::PyList;
|
3 |
| -use super::objstr::{self, PyStringRef}; |
| 3 | +use super::objstr::PyStringRef; |
4 | 4 | use super::objtype;
|
5 | 5 | use crate::function::PyFuncArgs;
|
6 | 6 | use crate::obj::objproperty::PropertyBuilder;
|
@@ -31,69 +31,31 @@ pub fn new_instance(vm: &VirtualMachine, mut args: PyFuncArgs) -> PyResult {
|
31 | 31 | Ok(PyObject::new(PyInstance, cls, dict))
|
32 | 32 | }
|
33 | 33 |
|
34 |
| -fn object_eq(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult { |
35 |
| - arg_check!( |
36 |
| - vm, |
37 |
| - args, |
38 |
| - required = [(_zelf, Some(vm.ctx.object())), (_other, None)] |
39 |
| - ); |
40 |
| - Ok(vm.ctx.not_implemented()) |
| 34 | +fn object_eq(_zelf: PyObjectRef, _other: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef { |
| 35 | + vm.ctx.not_implemented() |
41 | 36 | }
|
42 | 37 |
|
43 |
| -fn object_ne(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult { |
44 |
| - arg_check!( |
45 |
| - vm, |
46 |
| - args, |
47 |
| - required = [(_zelf, Some(vm.ctx.object())), (_other, None)] |
48 |
| - ); |
49 |
| - |
50 |
| - Ok(vm.ctx.not_implemented()) |
| 38 | +fn object_ne(_zelf: PyObjectRef, _other: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef { |
| 39 | + vm.ctx.not_implemented() |
51 | 40 | }
|
52 | 41 |
|
53 |
| -fn object_lt(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult { |
54 |
| - arg_check!( |
55 |
| - vm, |
56 |
| - args, |
57 |
| - required = [(_zelf, Some(vm.ctx.object())), (_other, None)] |
58 |
| - ); |
59 |
| - |
60 |
| - Ok(vm.ctx.not_implemented()) |
| 42 | +fn object_lt(_zelf: PyObjectRef, _other: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef { |
| 43 | + vm.ctx.not_implemented() |
61 | 44 | }
|
62 | 45 |
|
63 |
| -fn object_le(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult { |
64 |
| - arg_check!( |
65 |
| - vm, |
66 |
| - args, |
67 |
| - required = [(_zelf, Some(vm.ctx.object())), (_other, None)] |
68 |
| - ); |
69 |
| - |
70 |
| - Ok(vm.ctx.not_implemented()) |
| 46 | +fn object_le(_zelf: PyObjectRef, _other: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef { |
| 47 | + vm.ctx.not_implemented() |
71 | 48 | }
|
72 | 49 |
|
73 |
| -fn object_gt(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult { |
74 |
| - arg_check!( |
75 |
| - vm, |
76 |
| - args, |
77 |
| - required = [(_zelf, Some(vm.ctx.object())), (_other, None)] |
78 |
| - ); |
79 |
| - |
80 |
| - Ok(vm.ctx.not_implemented()) |
| 50 | +fn object_gt(_zelf: PyObjectRef, _other: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef { |
| 51 | + vm.ctx.not_implemented() |
81 | 52 | }
|
82 | 53 |
|
83 |
| -fn object_ge(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult { |
84 |
| - arg_check!( |
85 |
| - vm, |
86 |
| - args, |
87 |
| - required = [(_zelf, Some(vm.ctx.object())), (_other, None)] |
88 |
| - ); |
89 |
| - |
90 |
| - Ok(vm.ctx.not_implemented()) |
| 54 | +fn object_ge(_zelf: PyObjectRef, _other: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef { |
| 55 | + vm.ctx.not_implemented() |
91 | 56 | }
|
92 | 57 |
|
93 |
| -fn object_hash(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult { |
94 |
| - arg_check!(vm, args, required = [(_zelf, Some(vm.ctx.object()))]); |
95 |
| - |
96 |
| - // For now default to non hashable |
| 58 | +fn object_hash(_zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult { |
97 | 59 | Err(vm.new_type_error("unhashable type".to_string()))
|
98 | 60 | }
|
99 | 61 |
|
@@ -147,15 +109,12 @@ fn object_delattr(obj: PyObjectRef, attr_name: PyStringRef, vm: &VirtualMachine)
|
147 | 109 | }
|
148 | 110 | }
|
149 | 111 |
|
150 |
| -fn object_str(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult { |
151 |
| - arg_check!(vm, args, required = [(zelf, Some(vm.ctx.object()))]); |
152 |
| - vm.call_method(zelf, "__repr__", vec![]) |
| 112 | +fn object_str(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult { |
| 113 | + vm.call_method(&zelf, "__repr__", vec![]) |
153 | 114 | }
|
154 | 115 |
|
155 |
| -fn object_repr(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult { |
156 |
| - arg_check!(vm, args, required = [(obj, Some(vm.ctx.object()))]); |
157 |
| - let address = obj.get_id(); |
158 |
| - Ok(vm.new_str(format!("<{} object at 0x{:x}>", obj.class().name, address))) |
| 116 | +fn object_repr(zelf: PyObjectRef, _vm: &VirtualMachine) -> String { |
| 117 | + format!("<{} object at 0x{:x}>", zelf.class().name, zelf.get_id()) |
159 | 118 | }
|
160 | 119 |
|
161 | 120 | pub fn object_dir(obj: PyObjectRef, vm: &VirtualMachine) -> PyList {
|
@@ -235,34 +194,26 @@ fn object_dict(object: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyDictRef>
|
235 | 194 | }
|
236 | 195 | }
|
237 | 196 |
|
238 |
| -fn object_getattribute(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult { |
239 |
| - arg_check!( |
240 |
| - vm, |
241 |
| - args, |
242 |
| - required = [ |
243 |
| - (obj, Some(vm.ctx.object())), |
244 |
| - (name_str, Some(vm.ctx.str_type())) |
245 |
| - ] |
246 |
| - ); |
247 |
| - let name = objstr::get_value(&name_str); |
| 197 | +fn object_getattribute(obj: PyObjectRef, name_str: PyStringRef, vm: &VirtualMachine) -> PyResult { |
| 198 | + let name = &name_str.value; |
248 | 199 | trace!("object.__getattribute__({:?}, {:?})", obj, name);
|
249 | 200 | let cls = obj.class();
|
250 | 201 |
|
251 | 202 | if let Some(attr) = objtype::class_get_attr(&cls, &name) {
|
252 | 203 | let attr_class = attr.class();
|
253 | 204 | if objtype::class_has_attr(&attr_class, "__set__") {
|
254 | 205 | if let Some(descriptor) = objtype::class_get_attr(&attr_class, "__get__") {
|
255 |
| - return vm.invoke(descriptor, vec![attr, obj.clone(), cls.into_object()]); |
| 206 | + return vm.invoke(descriptor, vec![attr, obj, cls.into_object()]); |
256 | 207 | }
|
257 | 208 | }
|
258 | 209 | }
|
259 | 210 |
|
260 | 211 | if let Some(obj_attr) = object_getattr(&obj, &name) {
|
261 | 212 | Ok(obj_attr)
|
262 | 213 | } else if let Some(attr) = objtype::class_get_attr(&cls, &name) {
|
263 |
| - vm.call_get_descriptor(attr, obj.clone()) |
| 214 | + vm.call_get_descriptor(attr, obj) |
264 | 215 | } else if let Some(getter) = objtype::class_get_attr(&cls, "__getattr__") {
|
265 |
| - vm.invoke(getter, vec![obj.clone(), name_str.clone()]) |
| 216 | + vm.invoke(getter, vec![obj, name_str.into_object()]) |
266 | 217 | } else {
|
267 | 218 | Err(vm.new_attribute_error(format!("{} has no attribute '{}'", obj, name)))
|
268 | 219 | }
|
|
0 commit comments