@@ -10,8 +10,9 @@ use std::collections::hash_map::HashMap;
10
10
11
11
use super :: builtins;
12
12
use super :: bytecode;
13
- use super :: frame:: Frame ;
13
+ use super :: frame:: { ExecutionResult , Frame } ;
14
14
use super :: obj:: objcode:: copy_code;
15
+ use super :: obj:: objframe;
15
16
use super :: obj:: objgenerator;
16
17
use super :: obj:: objiter;
17
18
use super :: obj:: objsequence;
@@ -35,7 +36,7 @@ pub struct VirtualMachine {
35
36
pub sys_module : PyObjectRef ,
36
37
pub stdlib_inits : HashMap < String , stdlib:: StdlibInitFunc > ,
37
38
pub ctx : PyContext ,
38
- pub current_frame : Option < PyObjectRef > ,
39
+ pub frames : Vec < PyObjectRef > ,
39
40
}
40
41
41
42
impl VirtualMachine {
@@ -52,13 +53,28 @@ impl VirtualMachine {
52
53
sys_module : sysmod,
53
54
stdlib_inits,
54
55
ctx : ctx,
55
- current_frame : None ,
56
+ frames : vec ! [ ] ,
56
57
}
57
58
}
58
59
59
60
pub fn run_code_obj ( & mut self , code : PyObjectRef , scope : PyObjectRef ) -> PyResult {
60
- let mut frame = Frame :: new ( code, scope) ;
61
- frame. run_frame_full ( self )
61
+ self . run_frame_full ( Frame :: new ( code, scope) )
62
+ }
63
+
64
+ pub fn run_frame_full ( & mut self , frame : Frame ) -> PyResult {
65
+ match self . run_frame ( frame) ? {
66
+ ExecutionResult :: Return ( value) => Ok ( value) ,
67
+ _ => panic ! ( "Got unexpected result from function" ) ,
68
+ }
69
+ }
70
+
71
+ pub fn run_frame ( & mut self , frame : Frame ) -> Result < ExecutionResult , PyObjectRef > {
72
+ let frame = self . ctx . new_frame ( frame) ;
73
+ self . frames . push ( frame. clone ( ) ) ;
74
+ let mut frame = objframe:: get_value ( & frame) ;
75
+ let result = frame. run ( self ) ;
76
+ self . frames . pop ( ) ;
77
+ result
62
78
}
63
79
64
80
/// Create a new python string object.
@@ -260,13 +276,13 @@ impl VirtualMachine {
260
276
self . fill_scope_from_args ( & code_object, & scope, args, defaults) ?;
261
277
262
278
// Construct frame:
263
- let mut frame = Frame :: new ( code. clone ( ) , scope) ;
279
+ let frame = Frame :: new ( code. clone ( ) , scope) ;
264
280
265
281
// If we have a generator, create a new generator
266
282
if code_object. is_generator {
267
283
objgenerator:: new_generator ( self , frame)
268
284
} else {
269
- frame . run_frame_full ( self )
285
+ self . run_frame_full ( frame )
270
286
}
271
287
}
272
288
0 commit comments