Skip to content

Commit 4a82c8f

Browse files
committed
Rename AttributeProtocol2 -> NameProtocol with method name changes.
1 parent 15aaa6d commit 4a82c8f

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

vm/src/frame.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,14 @@ impl Scope {
117117
}
118118
}
119119

120-
// TODO: Merge with existing Attribute protocol.
121-
pub trait AttributeProtocol2 {
122-
fn get_attr(&self, vm: &VirtualMachine, name: &str) -> Option<PyObjectRef>;
123-
fn set_attr(&self, vm: &VirtualMachine, name: &str, value: PyObjectRef);
124-
fn del_attr(&self, vm: &VirtualMachine, name: &str);
120+
pub trait NameProtocol {
121+
fn load_name(&self, vm: &VirtualMachine, name: &str) -> Option<PyObjectRef>;
122+
fn store_name(&self, vm: &VirtualMachine, name: &str, value: PyObjectRef);
123+
fn delete_name(&self, vm: &VirtualMachine, name: &str);
125124
}
126125

127-
impl AttributeProtocol2 for Scope {
128-
fn get_attr(&self, vm: &VirtualMachine, name: &str) -> Option<PyObjectRef> {
126+
impl NameProtocol for Scope {
127+
fn load_name(&self, vm: &VirtualMachine, name: &str) -> Option<PyObjectRef> {
129128
for dict in self.locals.iter() {
130129
if let Some(value) = dict.get_item(name) {
131130
return Some(value);
@@ -139,11 +138,11 @@ impl AttributeProtocol2 for Scope {
139138
vm.builtins.get_item(name)
140139
}
141140

142-
fn set_attr(&self, vm: &VirtualMachine, key: &str, value: PyObjectRef) {
141+
fn store_name(&self, vm: &VirtualMachine, key: &str, value: PyObjectRef) {
143142
self.get_locals().set_item(&vm.ctx, key, value)
144143
}
145144

146-
fn del_attr(&self, _vm: &VirtualMachine, key: &str) {
145+
fn delete_name(&self, _vm: &VirtualMachine, key: &str) {
147146
self.get_locals().del_item(key)
148147
}
149148
}
@@ -846,7 +845,7 @@ impl Frame {
846845
let obj = import_module(vm, current_path, module)?;
847846

848847
for (k, v) in obj.get_key_value_pairs().iter() {
849-
self.scope.set_attr(&vm, &objstr::get_value(k), v.clone());
848+
self.scope.store_name(&vm, &objstr::get_value(k), v.clone());
850849
}
851850
Ok(None)
852851
}
@@ -968,17 +967,17 @@ impl Frame {
968967

969968
fn store_name(&self, vm: &mut VirtualMachine, name: &str) -> FrameResult {
970969
let obj = self.pop_value();
971-
self.scope.set_attr(&vm, name, obj);
970+
self.scope.store_name(&vm, name, obj);
972971
Ok(None)
973972
}
974973

975974
fn delete_name(&self, vm: &mut VirtualMachine, name: &str) -> FrameResult {
976-
self.scope.del_attr(vm, name);
975+
self.scope.delete_name(vm, name);
977976
Ok(None)
978977
}
979978

980979
fn load_name(&self, vm: &mut VirtualMachine, name: &str) -> FrameResult {
981-
match self.scope.get_attr(&vm, name) {
980+
match self.scope.load_name(&vm, name) {
982981
Some(value) => {
983982
self.push_value(value);
984983
Ok(None)

wasm/lib/src/vm_class.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::wasm_builtins;
44
use js_sys::{Object, SyntaxError, TypeError};
55
use rustpython_vm::{
66
compile,
7-
frame::{AttributeProtocol2, Scope},
7+
frame::{NameProtocol, Scope},
88
pyobject::{PyContext, PyFuncArgs, PyObjectRef, PyResult},
99
VirtualMachine,
1010
};
@@ -258,7 +258,7 @@ impl WASMVirtualMachine {
258258
..
259259
}| {
260260
let value = convert::js_to_py(vm, value);
261-
scope.set_attr(&vm, &name, value);
261+
scope.store_name(&vm, &name, value);
262262
},
263263
)
264264
}
@@ -298,7 +298,7 @@ impl WASMVirtualMachine {
298298
)
299299
.into());
300300
};
301-
scope.set_attr(&vm, "print", vm.ctx.new_rustfunc(print_fn));
301+
scope.store_name(&vm, "print", vm.ctx.new_rustfunc(print_fn));
302302
Ok(())
303303
},
304304
)?

0 commit comments

Comments
 (0)