diff --git a/cl/compile.go b/cl/compile.go index a786981b..771f3029 100644 --- a/cl/compile.go +++ b/cl/compile.go @@ -347,20 +347,22 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, do if pyModInit = p.pyMod != ""; pyModInit { last = len(instrs) - 1 instrs = instrs[:last] + } else { + // TODO(xsw): confirm pyMod don't need to call LoadPyModSyms + p.inits = append(p.inits, func() { + if objs := pkg.PyObjs(); len(objs) > 0 { + mods := make(map[string][]llssa.PyObjRef) + for name, obj := range objs { + modName := modOf(name) + mods[modName] = append(mods[modName], obj) + } + b.SetBlockEx(ret, llssa.AfterInit) + for modName, objs := range mods { + b.LoadPyModSyms(modName, objs...) + } + } + }) } - p.inits = append(p.inits, func() { - if objs := pkg.PyObjs(); len(objs) > 0 { - mods := make(map[string][]llssa.PyObjRef) - for name, obj := range objs { - modName := modOf(name) - mods[modName] = append(mods[modName], obj) - } - b.SetBlockEx(ret, llssa.AfterInit) - for modName, objs := range mods { - b.LoadPyModSyms(modName, objs...) - } - } - }) } else if doMainInit { fn := p.fn argc := pkg.NewVar("__llgo_argc", types.NewPointer(types.Typ[types.Int32]), llssa.InC) diff --git a/py/math/llgo_autogen.lla b/py/math/llgo_autogen.lla index 8eaa159b..44b7ad79 100644 Binary files a/py/math/llgo_autogen.lla and b/py/math/llgo_autogen.lla differ diff --git a/py/os/llgo_autogen.lla b/py/os/llgo_autogen.lla index d9ad409c..e88a4ffa 100644 Binary files a/py/os/llgo_autogen.lla and b/py/os/llgo_autogen.lla differ