Visitar URL original
Py module by cthulahoops · Pull Request #520 · RustPython/RustPython · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
sys - use py_module.
  • Loading branch information
cthulahoops committed Feb 21, 2019
commit 2c97a50e6e3435b9316b1c0bea4579375a9b439d
27 changes: 13 additions & 14 deletions vm/src/sysmodule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
};
let path = ctx.new_list(path_list);

let modules = ctx.new_dict();

let sys_name = "sys";
let sys_doc = "This module provides access to some objects used or maintained by the
interpreter and to functions that interact strongly with the interpreter.

Expand Down Expand Up @@ -121,20 +118,22 @@ setprofile() -- set the global profiling function
setrecursionlimit() -- set the max recursion depth for the interpreter
settrace() -- set the global debug tracing function
";
let sys_mod = ctx.new_module(&sys_name, ctx.new_scope(None));
let modules = ctx.new_dict();
let sys_name = "sys";
let sys_mod = py_module!(ctx, sys_name, {
"argv" => argv(ctx),
"getrefcount" => ctx.new_rustfunc(sys_getrefcount),
"getsizeof" => ctx.new_rustfunc(sys_getsizeof),
"maxsize" => ctx.new_int(std::usize::MAX),
"path" => path,
"ps1" => ctx.new_str(">>>>> ".to_string()),
"ps2" => ctx.new_str("..... ".to_string()),
"__doc__" => ctx.new_str(sys_doc.to_string()),
"_getframe" => ctx.new_rustfunc(getframe),
});

ctx.set_item(&modules, sys_name, sys_mod.clone());

ctx.set_attr(&sys_mod, "modules", modules);
ctx.set_attr(&sys_mod, "argv", argv(ctx));
ctx.set_attr(&sys_mod, "getrefcount", ctx.new_rustfunc(sys_getrefcount));
ctx.set_attr(&sys_mod, "getsizeof", ctx.new_rustfunc(sys_getsizeof));
ctx.set_attr(&sys_mod, "maxsize", ctx.new_int(std::usize::MAX));
ctx.set_attr(&sys_mod, "path", path);
ctx.set_attr(&sys_mod, "ps1", ctx.new_str(">>>>> ".to_string()));
ctx.set_attr(&sys_mod, "ps2", ctx.new_str("..... ".to_string()));
ctx.set_attr(&sys_mod, "__doc__", ctx.new_str(sys_doc.to_string()));
ctx.set_attr(&sys_mod, "_getframe", ctx.new_rustfunc(getframe));

sys_mod
}