Skip to content

Commit 9d6e9ac

Browse files
committed
Move Scope from pyobject to frame.
1 parent c2e2441 commit 9d6e9ac

8 files changed

Lines changed: 26 additions & 21 deletions

File tree

src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ use rustpython_parser::error::ParseError;
1212
use rustpython_vm::{
1313
compile,
1414
error::CompileError,
15+
frame::ScopeRef,
1516
import,
1617
obj::objstr,
1718
print_exception,
18-
pyobject::{AttributeProtocol, PyResult, ScopeRef},
19+
pyobject::{AttributeProtocol, PyResult},
1920
util, VirtualMachine,
2021
};
2122
use rustyline::{error::ReadlineError, Editor};

vm/src/builtins.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ use crate::obj::objiter;
1414
use crate::obj::objstr;
1515
use crate::obj::objtype;
1616

17+
use crate::frame::{Scope, ScopeRef};
1718
use crate::pyobject::{
18-
AttributeProtocol, IdProtocol, PyContext, PyFuncArgs, PyObjectRef, PyResult, Scope, ScopeRef,
19-
TypeProtocol,
19+
AttributeProtocol, IdProtocol, PyContext, PyFuncArgs, PyObjectRef, PyResult, TypeProtocol,
2020
};
2121
use std::rc::Rc;
2222

vm/src/eval.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ extern crate rustpython_parser;
33
use std::error::Error;
44

55
use crate::compile;
6-
use crate::pyobject::{PyResult, ScopeRef};
6+
use crate::frame::ScopeRef;
7+
use crate::pyobject::PyResult;
78
use crate::vm::VirtualMachine;
89

910
pub fn eval(vm: &mut VirtualMachine, source: &str, scope: ScopeRef, source_path: &str) -> PyResult {

vm/src/frame.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,23 @@ use crate::obj::objstr;
1717
use crate::obj::objtype;
1818
use crate::pyobject::{
1919
DictProtocol, IdProtocol, PyFuncArgs, PyObject, PyObjectPayload, PyObjectRef, PyResult,
20-
ScopeRef, TypeProtocol,
20+
TypeProtocol,
2121
};
2222
use crate::vm::VirtualMachine;
2323
use num_bigint::BigInt;
24+
use std::rc::Rc;
25+
26+
/*
27+
* So a scope is a linked list of scopes.
28+
* When a name is looked up, it is check in its scope.
29+
*/
30+
#[derive(Debug)]
31+
pub struct Scope {
32+
pub locals: PyObjectRef, // Variables
33+
// TODO: pub locals: RefCell<PyAttributes>, // Variables
34+
pub parent: Option<Rc<Scope>>, // Parent scope
35+
}
36+
pub type ScopeRef = Rc<Scope>;
2437

2538
#[derive(Clone, Debug)]
2639
struct Block {

vm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub mod error;
3737
pub mod eval;
3838
mod exceptions;
3939
pub mod format;
40-
mod frame;
40+
pub mod frame;
4141
pub mod import;
4242
pub mod obj;
4343
pub mod pyobject;

vm/src/pyobject.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::bytecode;
22
use crate::exceptions;
3-
use crate::frame::Frame;
3+
use crate::frame::{Frame, Scope, ScopeRef};
44
use crate::obj::objbool;
55
use crate::obj::objbytearray;
66
use crate::obj::objbytes;
@@ -147,18 +147,6 @@ pub struct PyContext {
147147
pub exceptions: exceptions::ExceptionZoo,
148148
}
149149

150-
/*
151-
* So a scope is a linked list of scopes.
152-
* When a name is looked up, it is check in its scope.
153-
*/
154-
#[derive(Debug)]
155-
pub struct Scope {
156-
pub locals: PyObjectRef, // Variables
157-
// TODO: pub locals: RefCell<PyAttributes>, // Variables
158-
pub parent: Option<Rc<Scope>>, // Parent scope
159-
}
160-
pub type ScopeRef = Rc<Scope>;
161-
162150
fn _nothing() -> PyObjectRef {
163151
PyObject {
164152
payload: PyObjectPayload::None,

vm/src/vm.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::sync::{Mutex, MutexGuard};
1414
use crate::builtins;
1515
use crate::bytecode;
1616
use crate::frame::ExecutionResult;
17+
use crate::frame::{Scope, ScopeRef};
1718
use crate::obj::objbool;
1819
use crate::obj::objcode;
1920
use crate::obj::objframe;
@@ -24,7 +25,7 @@ use crate::obj::objstr;
2425
use crate::obj::objtype;
2526
use crate::pyobject::{
2627
AttributeProtocol, DictProtocol, IdProtocol, PyContext, PyFuncArgs, PyObjectPayload,
27-
PyObjectRef, PyResult, Scope, ScopeRef, TypeProtocol,
28+
PyObjectRef, PyResult, TypeProtocol,
2829
};
2930
use crate::stdlib;
3031
use crate::sysmodule;

wasm/lib/src/vm_class.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use crate::wasm_builtins;
44
use js_sys::{Object, SyntaxError, TypeError};
55
use rustpython_vm::{
66
compile,
7-
pyobject::{DictProtocol, PyContext, PyFuncArgs, PyObjectRef, PyResult, ScopeRef},
7+
frame::ScopeRef,
8+
pyobject::{DictProtocol, PyContext, PyFuncArgs, PyObjectRef, PyResult},
89
VirtualMachine,
910
};
1011
use std::cell::RefCell;

0 commit comments

Comments
 (0)