@@ -42,7 +42,8 @@ type ModuleImpl struct {
4242 Code * Code // Module code body
4343}
4444
45- type Store struct {
45+ // ModuleStore is a container of Module imported into an owning py.Ctx.
46+ type ModuleStore struct {
4647 // Registry of installed modules
4748 modules map [string ]* Module
4849 // Builtin module
@@ -78,13 +79,13 @@ func (rt *Runtime) RegisterModule(impl *ModuleImpl) {
7879 rt .ModuleImpls [impl .Info .Name ] = impl
7980}
8081
81- func NewStore () * Store {
82- return & Store {
82+ func NewModuleStore () * ModuleStore {
83+ return & ModuleStore {
8384 modules : make (map [string ]* Module ),
8485 }
8586}
8687
87- // Module is a runtime instance of a ModuleImpl bound the py.Ctx that imported it.
88+ // Module is a runtime instance of a ModuleImpl bound to the py.Ctx that imported it.
8889type Module struct {
8990 ModuleInfo
9091
@@ -108,8 +109,10 @@ func (m *Module) GetDict() StringDict {
108109 return m .Globals
109110}
110111
111- // Define a new module
112- func (store * Store ) NewModule (ctx Ctx , info ModuleInfo , methods []* Method , globals StringDict ) (* Module , error ) {
112+ // NewModule adds a new Module instance to this ModuleStore.
113+ // Each given Method prototype is used to create a new "live" Method bound this the newly created Module.
114+ // This func also sets appropriate module global attribs based on the given ModuleInfo (e.g. __name__).
115+ func (store * ModuleStore ) NewModule (ctx Ctx , info ModuleInfo , methods []* Method , globals StringDict ) (* Module , error ) {
113116 if info .Name == "" {
114117 info .Name = MainModuleName
115118 }
@@ -147,7 +150,7 @@ func (store *Store) NewModule(ctx Ctx, info ModuleInfo, methods []*Method, globa
147150}
148151
149152// Gets a module
150- func (store * Store ) GetModule (name string ) (* Module , error ) {
153+ func (store * ModuleStore ) GetModule (name string ) (* Module , error ) {
151154 m , ok := store .modules [name ]
152155 if ! ok {
153156 return nil , ExceptionNewf (ImportError , "Module '%s' not found" , name )
@@ -156,7 +159,7 @@ func (store *Store) GetModule(name string) (*Module, error) {
156159}
157160
158161// Gets a module or panics
159- func (store * Store ) MustGetModule (name string ) * Module {
162+ func (store * ModuleStore ) MustGetModule (name string ) * Module {
160163 m , err := store .GetModule (name )
161164 if err != nil {
162165 panic (err )
0 commit comments