Skip to content

Commit e44ea3f

Browse files
committed
Fix wasm
1 parent a665edc commit e44ea3f

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

vm/src/frozen.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,28 @@ use crate::builtins::code;
33
use crate::bytecode;
44
use std::collections::HashMap;
55

6+
pub fn map_frozen<'a>(
7+
ctx: &'a PyContext,
8+
i: impl IntoIterator<Item = (String, bytecode::FrozenModule)> + 'a,
9+
) -> impl Iterator<Item = (String, code::FrozenModule)> + 'a {
10+
i.into_iter()
11+
.map(move |(k, bytecode::FrozenModule { code, package })| {
12+
(
13+
k,
14+
code::FrozenModule {
15+
code: ctx.map_codeobj(code),
16+
package,
17+
},
18+
)
19+
})
20+
}
21+
622
pub fn get_module_inits(ctx: &PyContext) -> HashMap<String, code::FrozenModule> {
723
let mut modules = HashMap::new();
824

9-
let map_freeze = |m: HashMap<String, bytecode::FrozenModule>| {
10-
m.into_iter()
11-
.map(|(k, bytecode::FrozenModule { code, package })| {
12-
(
13-
k,
14-
code::FrozenModule {
15-
code: ctx.map_codeobj(code),
16-
package,
17-
},
18-
)
19-
})
20-
};
21-
2225
macro_rules! ext_modules {
2326
($($t:tt)*) => {
24-
modules.extend(map_freeze(py_freeze!($($t)*)));
27+
modules.extend(map_frozen(ctx, py_freeze!($($t)*)));
2528
};
2629
}
2730

@@ -45,7 +48,7 @@ pub fn get_module_inits(ctx: &PyContext) -> HashMap<String, code::FrozenModule>
4548
// if we're on freeze-stdlib, the core stdlib modules will be included anyway
4649
#[cfg(feature = "freeze-stdlib")]
4750
{
48-
modules.extend(map_freeze(rustpython_pylib::frozen_stdlib()));
51+
modules.extend(map_frozen(ctx, rustpython_pylib::frozen_stdlib()));
4952
}
5053

5154
modules

vm/src/vm.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use arr_macro::arr;
1313
use crossbeam_utils::atomic::AtomicCell;
1414
use num_traits::{Signed, ToPrimitive};
1515

16-
use crate::builtins;
1716
use crate::builtins::code::{self, PyCode, PyCodeRef};
1817
use crate::builtins::dict::PyDictRef;
1918
use crate::builtins::int::{PyInt, PyIntRef};
@@ -27,18 +26,14 @@ use crate::builtins::tuple::PyTuple;
2726
use crate::common::{hash::HashSecret, lock::PyMutex, rc::PyRc};
2827
use crate::exceptions::{self, PyBaseException, PyBaseExceptionRef};
2928
use crate::frame::{ExecutionResult, Frame, FrameRef};
30-
use crate::frozen;
3129
use crate::function::{FuncArgs, IntoFuncArgs};
32-
use crate::import;
33-
use crate::iterator;
3430
use crate::pyobject::{
3531
BorrowValue, Either, IdProtocol, IntoPyObject, ItemProtocol, PyArithmaticValue, PyContext,
3632
PyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TryIntoRef, TypeProtocol,
3733
};
3834
use crate::scope::Scope;
3935
use crate::slots::PyComparisonOp;
40-
use crate::stdlib;
41-
use crate::sysmodule;
36+
use crate::{builtins, bytecode, frozen, import, iterator, stdlib, sysmodule};
4237
#[cfg(feature = "rustpython-compiler")]
4338
use rustpython_compiler::{
4439
compile::{self, CompileOpts},
@@ -126,6 +121,15 @@ pub struct PyGlobalState {
126121
pub atexit_funcs: PyMutex<Vec<(PyObjectRef, FuncArgs)>>,
127122
}
128123

124+
impl PyGlobalState {
125+
pub fn add_frozen<I>(&mut self, ctx: &PyContext, frozen: I)
126+
where
127+
I: IntoIterator<Item = (String, bytecode::FrozenModule)>,
128+
{
129+
self.frozen.extend(frozen::map_frozen(ctx, frozen))
130+
}
131+
}
132+
129133
pub const NSIG: usize = 64;
130134

131135
#[derive(Copy, Clone, PartialEq, Eq)]

wasm/lib/src/browser_module.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ pub fn setup_browser_module(vm: &mut VirtualMachine) {
280280
state
281281
.stdlib_inits
282282
.insert("_browser".to_owned(), Box::new(make_module));
283-
state
284-
.frozen
285-
.extend(py_freeze!(file = "src/browser.py", module_name = "browser",));
283+
state.add_frozen(
284+
&vm.ctx,
285+
py_freeze!(file = "src/browser.py", module_name = "browser"),
286+
);
286287
}

0 commit comments

Comments
 (0)