Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit84ef6e3

Browse files
committed
Add Frame.f_code.
1 parenta1b7c61 commit84ef6e3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

‎vm/src/obj/objframe.rs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ pub fn init(context: &PyContext) {
1313
letref frame_type = context.frame_type;
1414
frame_type.set_attr("__new__", context.new_rustfunc(frame_new));
1515
frame_type.set_attr("__repr__", context.new_rustfunc(frame_repr));
16-
frame_type.set_attr("f_locals", context.new_property(frame_locals));
16+
frame_type.set_attr("f_locals", context.new_property(frame_flocals));
17+
frame_type.set_attr("f_code", context.new_property(frame_fcode));
1718
}
1819

1920
fnframe_new(vm:&mutVirtualMachine,args:PyFuncArgs) ->PyResult{
@@ -27,7 +28,7 @@ fn frame_repr(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
2728
Ok(vm.new_str(repr))
2829
}
2930

30-
fnframe_locals(vm:&mutVirtualMachine,args:PyFuncArgs) ->PyResult{
31+
fnframe_flocals(vm:&mutVirtualMachine,args:PyFuncArgs) ->PyResult{
3132
arg_check!(vm, args, required =[(frame,Some(vm.ctx.frame_type()))]);
3233
let frame =get_value(frame);
3334
let py_scope = frame.locals.clone();
@@ -40,6 +41,11 @@ fn frame_locals(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
4041
}
4142
}
4243

44+
fnframe_fcode(vm:&mutVirtualMachine,args:PyFuncArgs) ->PyResult{
45+
arg_check!(vm, args, required =[(frame,Some(vm.ctx.frame_type()))]);
46+
Ok(vm.ctx.new_code_object(get_value(frame).code))
47+
}
48+
4349
pubfnget_value(obj:&PyObjectRef) ->Frame{
4450
ifletPyObjectKind::Frame{ frame} =&obj.borrow().kind{
4551
frame.clone()

‎vm/src/pyobject.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,10 @@ impl PyContext {
475475
py_obj
476476
}
477477

478+
pubfnnew_code_object(&self,code: bytecode::CodeObject) ->PyObjectRef{
479+
PyObject::new(PyObjectKind::Code{ code},self.code_type())
480+
}
481+
478482
pubfnnew_function(
479483
&self,
480484
code_obj:PyObjectRef,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp