4
4
5
5
use crate :: frame:: { ExecutionResult , Frame } ;
6
6
use crate :: pyobject:: {
7
- PyContext , PyFuncArgs , PyObject , PyObjectPayload , PyObjectRef , PyResult , TypeProtocol ,
7
+ PyContext , PyFuncArgs , PyObject , PyObjectPayload , PyObjectPayload2 , PyObjectRef , PyResult ,
8
+ TypeProtocol ,
8
9
} ;
9
10
use crate :: vm:: VirtualMachine ;
10
11
12
+ #[ derive( Debug ) ]
13
+ pub struct PyGenerator {
14
+ frame : PyObjectRef ,
15
+ }
16
+
17
+ impl PyObjectPayload2 for PyGenerator {
18
+ fn required_type ( ctx : & PyContext ) -> PyObjectRef {
19
+ ctx. generator_type ( )
20
+ }
21
+ }
22
+
11
23
pub fn init ( context : & PyContext ) {
12
24
let generator_type = & context. generator_type ;
13
25
context. set_attr (
@@ -29,7 +41,9 @@ pub fn init(context: &PyContext) {
29
41
30
42
pub fn new_generator ( vm : & mut VirtualMachine , frame : PyObjectRef ) -> PyResult {
31
43
Ok ( PyObject :: new (
32
- PyObjectPayload :: Generator { frame } ,
44
+ PyObjectPayload :: AnyRustValue {
45
+ value : Box :: new ( PyGenerator { frame } ) ,
46
+ } ,
33
47
vm. ctx . generator_type . clone ( ) ,
34
48
) )
35
49
}
@@ -55,7 +69,7 @@ fn generator_send(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
55
69
}
56
70
57
71
fn send ( vm : & mut VirtualMachine , gen : & PyObjectRef , value : & PyObjectRef ) -> PyResult {
58
- if let PyObjectPayload :: Generator { ref frame } = gen. payload {
72
+ if let Some ( PyGenerator { ref frame } ) = gen. payload ( ) {
59
73
if let Some ( frame) = frame. payload :: < Frame > ( ) {
60
74
frame. push_value ( value. clone ( ) ) ;
61
75
} else {
0 commit comments