Skip to content

Commit 61c7830

Browse files
author
Drew O'Meara
committed
renamed Store to ModuleStore + docs
1 parent 6242836 commit 61c7830

3 files changed

Lines changed: 15 additions & 12 deletions

File tree

modules/runtime.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func init() {
2929

3030
// ctx implements py.Ctx
3131
type ctx struct {
32-
store *py.Store
32+
store *py.ModuleStore
3333
opts py.CtxOpts
3434
}
3535

@@ -39,7 +39,7 @@ func NewCtx(opts py.CtxOpts) py.Ctx {
3939
opts: opts,
4040
}
4141

42-
ctx.store = py.NewStore()
42+
ctx.store = py.NewModuleStore()
4343

4444
py.Import(ctx, "builtins", "sys")
4545

@@ -224,6 +224,6 @@ func (ctx *ctx) GetModule(moduleName string) (*py.Module, error) {
224224
return ctx.store.GetModule(moduleName)
225225
}
226226

227-
func (ctx *ctx) Store() *py.Store {
227+
func (ctx *ctx) Store() *py.ModuleStore {
228228
return ctx.store
229229
}

py/module.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
8889
type 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)

py/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type Ctx interface {
4141
GetModule(moduleName string) (*Module, error)
4242

4343
// Gereric access to this context's modules / state.
44-
Store() *Store
44+
Store() *ModuleStore
4545
}
4646

4747
// CompileOpts specifies options for high-level compilation.

0 commit comments

Comments
 (0)