Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite3000e2

Browse files
committed
Add super object type skeleton.
1 parent0045d74 commite3000e2

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
pubmod objsequence;
1717
pubmod objset;
1818
pubmod objstr;
19+
pubmod objsuper;
1920
pubmod objtuple;
2021
pubmod 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+
usesuper::super::pyobject::{
6+
AttributeProtocol,PyContext,PyFuncArgs,PyObjectRef,PyResult,TypeProtocol,
7+
};
8+
usesuper::super::vm::VirtualMachine;
9+
usesuper::objtype;
10+
11+
pubfninit(context:&PyContext){
12+
letref super_type = context.super_type;
13+
super_type.set_attr("__init__", context.new_rustfunc(super_init));
14+
}
15+
16+
fnsuper_init(vm:&mutVirtualMachine,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
usesuper::obj::objproperty;
1717
usesuper::obj::objset;
1818
usesuper::obj::objstr;
19+
usesuper::obj::objsuper;
1920
usesuper::obj::objtuple;
2021
usesuper::obj::objtype;
2122
usesuper::vm::VirtualMachine;
@@ -88,6 +89,7 @@ pub struct PyContext {
8889
pubtuple_type:PyObjectRef,
8990
pubset_type:PyObjectRef,
9091
pubiter_type:PyObjectRef,
92+
pubsuper_type:PyObjectRef,
9193
pubstr_type:PyObjectRef,
9294
pubfunction_type:PyObjectRef,
9395
pubproperty_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+
pubfnsuper_type(&self) ->PyObjectRef{
287+
self.super_type.clone()
288+
}
289+
281290
pubfnfunction_type(&self) ->PyObjectRef{
282291
self.function_type.clone()
283292
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp