From ae7031db95b60342fc7a1b10a5555dd6f1aac176 Mon Sep 17 00:00:00 2001 From: Richard Plevin Date: Wed, 22 May 2019 21:48:40 -0700 Subject: [PATCH 1/3] This is a partial fix for module lookup problem that might suffice for the workshop. --- src/core/defs.jl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/core/defs.jl b/src/core/defs.jl index 23905bb24..f58eab08f 100644 --- a/src/core/defs.jl +++ b/src/core/defs.jl @@ -1,4 +1,14 @@ -compdef(comp_id::ComponentId) = getfield(getfield(Main, comp_id.module_name), comp_id.comp_name) +function compdef(comp_id::ComponentId) + module_name = comp_id.module_name + curr_module = @__MODULE__ + # @info "@__MODULE__ is $(@__MODULE__)" + + lookup_module = isdefined(curr_module, module_name) ? curr_module : Main + comp_module = getfield(lookup_module, module_name) + + comp_def = getfield(comp_module, comp_id.comp_name) + return comp_def +end compdefs(md::ModelDef) = values(md.comp_defs) From 974b31b13155a3d7f02f34c7b67bd4bbfacbbe88 Mon Sep 17 00:00:00 2001 From: Richard Plevin Date: Wed, 22 May 2019 22:06:58 -0700 Subject: [PATCH 2/3] Simplified fix for module lookup issue --- src/core/defs.jl | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/core/defs.jl b/src/core/defs.jl index f58eab08f..bf85cb2bb 100644 --- a/src/core/defs.jl +++ b/src/core/defs.jl @@ -1,11 +1,5 @@ function compdef(comp_id::ComponentId) - module_name = comp_id.module_name - curr_module = @__MODULE__ - # @info "@__MODULE__ is $(@__MODULE__)" - - lookup_module = isdefined(curr_module, module_name) ? curr_module : Main - comp_module = getfield(lookup_module, module_name) - + comp_module = (comp_id.module_name == :Mimi ? Mimi : getfield(Main, comp_id.module_name)) comp_def = getfield(comp_module, comp_id.comp_name) return comp_def end From 1b43132acd07bc44e3206291d03e6961cc50b102 Mon Sep 17 00:00:00 2001 From: Richard Plevin Date: Thu, 23 May 2019 08:00:13 -0700 Subject: [PATCH 3/3] Further fix for module lookup --- src/core/defs.jl | 5 ++++- src/core/types.jl | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/core/defs.jl b/src/core/defs.jl index bf85cb2bb..15e5eeb5e 100644 --- a/src/core/defs.jl +++ b/src/core/defs.jl @@ -1,5 +1,8 @@ +# Try to locate a module object by its symbolic name +get_module(name::Symbol) = (name == :Mimi ? Mimi : getfield(Mimi.Main, name)) + function compdef(comp_id::ComponentId) - comp_module = (comp_id.module_name == :Mimi ? Mimi : getfield(Main, comp_id.module_name)) + comp_module = get_module(comp_id.module_name) comp_def = getfield(comp_module, comp_id.comp_name) return comp_def end diff --git a/src/core/types.jl b/src/core/types.jl index 2860a679f..8ed4d68c3 100644 --- a/src/core/types.jl +++ b/src/core/types.jl @@ -357,7 +357,7 @@ mutable struct ComponentInstance{TV <: ComponentInstanceVariables, TP <: Compone comp_name = comp_id.comp_name module_name = comp_id.module_name - comp_module = getfield(Main, module_name) + comp_module = get_module(module_name) # TBD: use FunctionWrapper here? function get_func(name)