Skip to content

Conversation

0b01
Copy link
Contributor

@0b01 0b01 commented Feb 25, 2019

This enables closure-based mk_module.

        let test = move |vm: &mut VirtualMachine, args: PyFuncArgs| {
            Ok(vm.get_none())
        };
        let mk_module = Box::new(move |ctx: &PyContext| -> PyObjectRef {
            py_module!(ctx, "test", {
                "test" => ctx.new_rustfunc(test),
            })
        });
        self.vm.stdlib_inits.insert("test".to_string(), mk_module);

The dynamic closure dispatch will be monomorphized during compile time so no performance hit.

Note:

    modules.insert("ast".to_string(), Box::new(ast::mk_module) as StdlibInitFunc);

The type cast hint here is required

@coolreader18
Copy link
Member

I think you need to run cargo fmt again for the tests to pass.

@0b01
Copy link
Contributor Author

0b01 commented Feb 26, 2019

I'm using 1.34 nightly so cargo fmt config was different. TODO: rustfmt.toml

@codecov-io
Copy link

Codecov Report

Merging #546 into master will decrease coverage by 0.11%.
The diff coverage is 85%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #546      +/-   ##
=========================================
- Coverage   44.72%   44.6%   -0.12%     
=========================================
  Files          72      72              
  Lines       15536   15575      +39     
  Branches     3964    3977      +13     
=========================================
  Hits         6948    6948              
- Misses       6676    6719      +43     
+ Partials     1912    1908       -4
Impacted Files Coverage Δ
wasm/lib/src/browser_module.rs 0% <0%> (ø) ⬆️
vm/src/stdlib/mod.rs 82.14% <94.44%> (+7.14%) ⬆️
vm/src/stdlib/string.rs 22.95% <0%> (-4.79%) ⬇️
vm/src/compile.rs 45.65% <0%> (-0.52%) ⬇️
vm/src/error.rs 0% <0%> (ø) ⬆️
parser/src/error.rs 14.28% <0%> (ø) ⬆️
vm/src/frame.rs 46.44% <0%> (ø) ⬆️
vm/src/obj/objtype.rs 60.69% <0%> (ø) ⬆️
src/main.rs 14.81% <0%> (+0.09%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 027a684...432b9df. Read the comment docs.

@windelbouwman windelbouwman merged commit 53f54e4 into RustPython:master Feb 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants