Skip to content

Commit e3000e2

Browse files
committed
Add super object type skeleton.
1 parent 0045d74 commit e3000e2

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

vm/src/builtins.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,6 @@ fn builtin_sum(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
531531
Ok(sum)
532532
}
533533

534-
// builtin_super
535534
// builtin_vars
536535
// builtin_zip
537536
// builtin___import__
@@ -597,6 +596,7 @@ pub fn make_module(ctx: &PyContext) -> PyObjectRef {
597596
dict.insert(String::from("staticmethod"), ctx.staticmethod_type());
598597
dict.insert(String::from("str"), ctx.str_type());
599598
dict.insert(String::from("sum"), ctx.new_rustfunc(builtin_sum));
599+
dict.insert(String::from("super"), ctx.super_type());
600600
dict.insert(String::from("tuple"), ctx.tuple_type());
601601
dict.insert(String::from("type"), ctx.type_type());
602602

vm/src/obj/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ pub mod objproperty;
1616
pub mod objsequence;
1717
pub mod objset;
1818
pub mod objstr;
19+
pub mod objsuper;
1920
pub mod objtuple;
2021
pub mod objtype;

vm/src/obj/objsuper.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*! Python `super` class.
2+
3+
*/
4+
5+
use super::super::pyobject::{
6+
AttributeProtocol, PyContext, PyFuncArgs, PyObjectRef, PyResult, TypeProtocol,
7+
};
8+
use super::super::vm::VirtualMachine;
9+
use super::objtype;
10+
11+
pub fn init(context: &PyContext) {
12+
let ref super_type = context.super_type;
13+
super_type.set_attr("__init__", context.new_rustfunc(super_init));
14+
}
15+
16+
fn super_init(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
17+
trace!("super.__init__ {:?}", args.args);
18+
arg_check!(vm, args, required = [(_inst, None)]);
19+
20+
// TODO: implement complex logic here....
21+
22+
Ok(vm.get_none())
23+
}

vm/src/pyobject.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use super::obj::objobject;
1616
use super::obj::objproperty;
1717
use super::obj::objset;
1818
use super::obj::objstr;
19+
use super::obj::objsuper;
1920
use super::obj::objtuple;
2021
use super::obj::objtype;
2122
use super::vm::VirtualMachine;
@@ -88,6 +89,7 @@ pub struct PyContext {
8889
pub tuple_type: PyObjectRef,
8990
pub set_type: PyObjectRef,
9091
pub iter_type: PyObjectRef,
92+
pub super_type: PyObjectRef,
9193
pub str_type: PyObjectRef,
9294
pub function_type: PyObjectRef,
9395
pub property_type: PyObjectRef,
@@ -148,6 +150,7 @@ impl PyContext {
148150
let staticmethod_type = create_type("staticmethod", &type_type, &object_type, &dict_type);
149151
let function_type = create_type("function", &type_type, &object_type, &dict_type);
150152
let property_type = create_type("property", &type_type, &object_type, &dict_type);
153+
let super_type = create_type("property", &type_type, &object_type, &dict_type);
151154
let generator_type = create_type("generator", &type_type, &object_type, &dict_type);
152155
let bound_method_type = create_type("method", &type_type, &object_type, &dict_type);
153156
let member_descriptor_type =
@@ -200,6 +203,7 @@ impl PyContext {
200203
str_type: str_type,
201204
object: object_type,
202205
function_type: function_type,
206+
super_type: super_type,
203207
property_type: property_type,
204208
generator_type: generator_type,
205209
module_type: module_type,
@@ -223,6 +227,7 @@ impl PyContext {
223227
objbytearray::init(&context);
224228
objproperty::init(&context);
225229
objstr::init(&context);
230+
objsuper::init(&context);
226231
objtuple::init(&context);
227232
objiter::init(&context);
228233
objbool::init(&context);
@@ -278,6 +283,10 @@ impl PyContext {
278283
self.str_type.clone()
279284
}
280285

286+
pub fn super_type(&self) -> PyObjectRef {
287+
self.super_type.clone()
288+
}
289+
281290
pub fn function_type(&self) -> PyObjectRef {
282291
self.function_type.clone()
283292
}

0 commit comments

Comments
 (0)