Skip to content

Commit 0b1050e

Browse files
committed
cleanup PyFunction a little bit
1 parent e5b91c2 commit 0b1050e

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

vm/src/builtins.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ pub fn builtin_build_class_(
951951
let cells = vm.ctx.new_dict();
952952

953953
let scope = function
954-
.scope
954+
.scope()
955955
.new_child_scope_with_locals(cells.clone())
956956
.new_child_scope_with_locals(namespace.clone());
957957

vm/src/obj/objfunction.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub type PyFunctionRef = PyRef<PyFunction>;
1515
pub struct PyFunction {
1616
// TODO: these shouldn't be public
1717
pub code: PyCodeRef,
18-
pub scope: Scope,
18+
scope: Scope,
1919
pub defaults: Option<PyTupleRef>,
2020
pub kw_only_defaults: Option<PyDictRef>,
2121
}
@@ -49,6 +49,10 @@ impl PyFunction {
4949
kw_only_defaults,
5050
}
5151
}
52+
53+
pub fn scope(&self) -> &Scope {
54+
&self.scope
55+
}
5256
}
5357

5458
impl PyValue for PyFunction {

vm/src/vm.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::obj::objiter;
3737
use crate::obj::objlist::PyList;
3838
use crate::obj::objmodule::{self, PyModule};
3939
use crate::obj::objstr::{PyString, PyStringRef};
40-
use crate::obj::objtuple::{PyTuple, PyTupleRef};
40+
use crate::obj::objtuple::PyTuple;
4141
use crate::obj::objtype::{self, PyClassRef};
4242
use crate::pyhash;
4343
use crate::pyobject::{
@@ -726,7 +726,7 @@ impl VirtualMachine {
726726
}
727727

728728
pub fn invoke_python_function(&self, func: &PyFunction, func_args: PyFuncArgs) -> PyResult {
729-
self.invoke_python_function_with_scope(func, func_args, &func.scope)
729+
self.invoke_python_function_with_scope(func, func_args, func.scope())
730730
}
731731

732732
pub fn invoke_python_function_with_scope(
@@ -743,13 +743,7 @@ impl VirtualMachine {
743743
scope.clone()
744744
};
745745

746-
self.fill_locals_from_args(
747-
&code,
748-
&scope.get_locals(),
749-
func_args,
750-
&func.defaults,
751-
&func.kw_only_defaults,
752-
)?;
746+
self.fill_locals_from_args(&code, &scope.get_locals(), func_args, func)?;
753747

754748
// Construct frame:
755749
let frame = Frame::new(code.clone(), scope).into_ref(self);
@@ -769,8 +763,7 @@ impl VirtualMachine {
769763
code_object: &bytecode::CodeObject,
770764
locals: &PyDictRef,
771765
func_args: PyFuncArgs,
772-
defaults: &Option<PyTupleRef>,
773-
kw_only_defaults: &Option<PyDictRef>,
766+
func: &PyFunction,
774767
) -> PyResult<()> {
775768
let nargs = func_args.args.len();
776769
let nexpected_args = code_object.arg_names.len();
@@ -849,6 +842,9 @@ impl VirtualMachine {
849842
}
850843
}
851844

845+
let defaults = &func.defaults;
846+
let kw_only_defaults = &func.kw_only_defaults;
847+
852848
// Add missing positional arguments, if we have fewer positional arguments than the
853849
// function definition calls for
854850
if nargs < nexpected_args {

0 commit comments

Comments
 (0)