3
3
//! Implements functions listed here: https://docs.python.org/3/library/builtins.html
4
4
5
5
// use std::ops::Deref;
6
- use std:: cell:: RefCell ;
7
6
use std:: char;
8
7
use std:: io:: { self , Write } ;
9
8
@@ -15,10 +14,11 @@ use crate::obj::objiter;
15
14
use crate :: obj:: objstr;
16
15
use crate :: obj:: objtype;
17
16
17
+ use crate :: frame:: { Scope , ScopeRef } ;
18
18
use crate :: pyobject:: {
19
- AttributeProtocol , IdProtocol , PyContext , PyFuncArgs , PyObject , PyObjectPayload , PyObjectRef ,
20
- PyResult , Scope , TypeProtocol ,
19
+ AttributeProtocol , IdProtocol , PyContext , PyFuncArgs , PyObjectRef , PyResult , TypeProtocol ,
21
20
} ;
21
+ use std:: rc:: Rc ;
22
22
23
23
#[ cfg( not( target_arch = "wasm32" ) ) ]
24
24
use crate :: stdlib:: io:: io_open;
@@ -258,7 +258,7 @@ fn builtin_exec(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
258
258
vm. run_code_obj ( code_obj, scope)
259
259
}
260
260
261
- fn make_scope ( vm : & mut VirtualMachine , locals : Option < & PyObjectRef > ) -> PyObjectRef {
261
+ fn make_scope ( vm : & mut VirtualMachine , locals : Option < & PyObjectRef > ) -> ScopeRef {
262
262
// handle optional global and locals
263
263
let locals = if let Some ( locals) = locals {
264
264
locals. clone ( )
@@ -268,18 +268,10 @@ fn make_scope(vm: &mut VirtualMachine, locals: Option<&PyObjectRef>) -> PyObject
268
268
269
269
// TODO: handle optional globals
270
270
// Construct new scope:
271
- let scope_inner = Scope {
271
+ Rc :: new ( Scope {
272
272
locals,
273
273
parent : None ,
274
- } ;
275
-
276
- PyObject {
277
- payload : PyObjectPayload :: Scope {
278
- scope : RefCell :: new ( scope_inner) ,
279
- } ,
280
- typ : None ,
281
- }
282
- . into_ref ( )
274
+ } )
283
275
}
284
276
285
277
fn builtin_format ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
@@ -842,13 +834,7 @@ pub fn builtin_build_class_(vm: &mut VirtualMachine, mut args: PyFuncArgs) -> Py
842
834
} ,
843
835
) ?;
844
836
845
- vm. invoke (
846
- function,
847
- PyFuncArgs {
848
- args : vec ! [ namespace. clone( ) ] ,
849
- kwargs : vec ! [ ] ,
850
- } ,
851
- ) ?;
837
+ vm. invoke_with_locals ( function, namespace. clone ( ) ) ?;
852
838
853
839
vm. call_method ( & metaclass, "__call__" , vec ! [ name_arg, bases, namespace] )
854
840
}
0 commit comments