55 */
66
77use std:: cell:: RefMut ;
8- use std:: collections:: HashMap ;
98use std:: ops:: Deref ;
109
1110use super :: builtins;
@@ -18,13 +17,16 @@ use super::objtuple;
1817use super :: pyobject:: { DictProtocol , PyContext , PyObject , PyObjectKind , PyObjectRef ,
1918 PyResult , ParentProtocol , Scope , IdProtocol , PyFuncArgs } ;
2019
20+ use super :: sysmodule;
21+
2122// use objects::objects;
2223
2324// Objects are live when they are on stack, or referenced by a name (for now)
2425
2526pub struct VirtualMachine {
2627 frames : Vec < Frame > ,
2728 builtins : PyObjectRef ,
29+ pub sys_module : PyObjectRef ,
2830 ctx : PyContext ,
2931}
3032
@@ -53,15 +55,6 @@ impl VirtualMachine {
5355 self . ctx . new_dict ( )
5456 }
5557
56- pub fn new_scope ( & self , parent : Option < PyObjectRef > ) -> PyObjectRef {
57- let locals = self . ctx . new_dict ( ) ;
58- let scope = Scope {
59- locals : locals,
60- parent : parent,
61- } ;
62- PyObject { kind : PyObjectKind :: Scope { scope : scope } , typ : None } . into_ref ( )
63- }
64-
6558 pub fn new_exception ( & self , msg : String ) -> PyObjectRef {
6659 self . new_str ( msg)
6760 }
@@ -93,9 +86,11 @@ impl VirtualMachine {
9386 pub fn new ( ) -> VirtualMachine {
9487 let ctx = PyContext :: new ( ) ;
9588 let builtins = builtins:: make_module ( & ctx) ;
89+ let sysmod = sysmodule:: mk_module ( & ctx) ;
9690 VirtualMachine {
9791 frames : vec ! [ ] ,
9892 builtins : builtins,
93+ sys_module : sysmod,
9994 ctx : ctx,
10095 }
10196 }
@@ -467,7 +462,7 @@ impl VirtualMachine {
467462 match f. kind {
468463 PyObjectKind :: RustFunction { ref function } => f. call ( self , args) ,
469464 PyObjectKind :: Function { ref code, ref scope } => {
470- let mut scope = self . new_scope ( Some ( scope. clone ( ) ) ) ;
465+ let mut scope = self . ctx . new_scope ( Some ( scope. clone ( ) ) ) ;
471466 let code_object = copy_code ( code. clone ( ) ) ;
472467 for ( name, value) in code_object. arg_names . iter ( ) . zip ( args. args ) {
473468 scope. set_item ( name, value) ;
0 commit comments