Skip to content

Use py_module at more places. #641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions vm/src/stdlib/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,8 @@ fn ast_parse(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
py_module!(ctx, "ast", {
"parse" => ctx.new_rustfunc(ast_parse),
"Module" => ctx.new_class("_ast.Module", ctx.object()),
"FunctionDef" =>ctx.new_class("_ast.FunctionDef", ctx.object()),
"Call" => ctx.new_class("_ast.Call", ctx.object())
"Module" => py_class!(ctx, "_ast.Module", ctx.object(), {}),
"FunctionDef" => py_class!(ctx, "_ast.FunctionDef", ctx.object(), {}),
"Call" => py_class!(ctx, "_ast.Call", ctx.object(), {})
})
}
4 changes: 2 additions & 2 deletions vm/src/stdlib/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,10 @@ pub fn io_open(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {

pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
//IOBase the abstract base class of the IO Module
let io_base = ctx.new_class("IOBase", ctx.object());
let io_base = py_class!(ctx, "IOBase", ctx.object(), {});

// IOBase Subclasses
let raw_io_base = ctx.new_class("RawIOBase", ctx.object());
let raw_io_base = py_class!(ctx, "RawIOBase", ctx.object(), {});

let buffered_io_base = py_class!(ctx, "BufferedIOBase", io_base.clone(), {
"__init__" => ctx.new_rustfunc(buffered_io_base_init)
Expand Down
22 changes: 11 additions & 11 deletions vm/src/stdlib/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,17 @@ fn os_error(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
}

pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
let py_mod = ctx.new_module(&"os".to_string(), ctx.new_scope(None));
ctx.set_attr(&py_mod, "open", ctx.new_rustfunc(os_open));
ctx.set_attr(&py_mod, "close", ctx.new_rustfunc(os_close));
ctx.set_attr(&py_mod, "error", ctx.new_rustfunc(os_error));

ctx.set_attr(&py_mod, "O_RDONLY", ctx.new_int(0));
ctx.set_attr(&py_mod, "O_WRONLY", ctx.new_int(1));
ctx.set_attr(&py_mod, "O_RDWR", ctx.new_int(2));
ctx.set_attr(&py_mod, "O_NONBLOCK", ctx.new_int(4));
ctx.set_attr(&py_mod, "O_APPEND", ctx.new_int(8));
ctx.set_attr(&py_mod, "O_CREAT", ctx.new_int(512));
let py_mod = py_module!(ctx, "os", {
"open" => ctx.new_rustfunc(os_open),
"close" => ctx.new_rustfunc(os_close),
"error" => ctx.new_rustfunc(os_error),
"O_RDONLY" => ctx.new_int(0),
"O_WRONLY" => ctx.new_int(1),
"O_RDWR" => ctx.new_int(2),
"O_NONBLOCK" => ctx.new_int(4),
"O_APPEND" => ctx.new_int(8),
"O_CREAT" => ctx.new_int(512)
});

if cfg!(windows) {
ctx.set_attr(&py_mod, "name", ctx.new_str("nt".to_string()));
Expand Down
13 changes: 7 additions & 6 deletions vm/src/stdlib/weakref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ use crate::VirtualMachine;
use std::rc::Rc;

pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
let py_mod = ctx.new_module("_weakref", ctx.new_scope(None));
let py_ref_class = py_class!(ctx, "ref", ctx.object(), {
"__new__" => ctx.new_rustfunc(ref_new),
"__call__" => ctx.new_rustfunc(ref_call)
});

let py_ref_class = ctx.new_class("ref", ctx.object());
ctx.set_attr(&py_ref_class, "__new__", ctx.new_rustfunc(ref_new));
ctx.set_attr(&py_ref_class, "__call__", ctx.new_rustfunc(ref_call));
ctx.set_attr(&py_mod, "ref", py_ref_class);
py_mod
py_module!(ctx, "_weakref", {
"ref" => py_ref_class
})
}

fn ref_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
Expand Down
10 changes: 4 additions & 6 deletions wasm/lib/src/browser_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,10 @@ fn browser_prompt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
const BROWSER_NAME: &str = "browser";

pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
let promise = {
let promise = ctx.new_class("Promise", ctx.object());
ctx.set_attr(&promise, "then", ctx.new_rustfunc(promise_then));
ctx.set_attr(&promise, "catch", ctx.new_rustfunc(promise_catch));
promise
};
let promise = py_class!(ctx, "Promise", ctx.object(), {
"then" => ctx.new_rustfunc(promise_then),
"catch" => ctx.new_rustfunc(promise_catch)
});

py_module!(ctx, BROWSER_NAME, {
"fetch" => ctx.new_rustfunc(browser_fetch),
Expand Down