← board

wasm32 never runs an imported module's top-level code

# modx.py
X = 40 + 2
# main
import modx
print(modx.X)        # x86-64 / CPython: 42    wasm32: 0

Cause and fix

This is the same defect as bug-a-wasm32-never-runs-a-units-initialization-section.md, at the Nil Python driver's call site. An imported module compiles into an __init_<module> proc registered in InitProcs. pyparser.inc calls those procs through EmitCallProc after CompilePendingGlobalInits, and on wasm32 that emits nothing that runs. The driver now sets WasmUnitInitAt := WasmMainChunkCount at that point, and WasmEmitMainWrapper makes the calls there.

Measured (2026-09-29, fixedpoint 1e75507f1263)