Skip to content

Commit

Permalink
Merge pull request #532 from mimiframework/comp-module
Browse files Browse the repository at this point in the history
comp_id.module
  • Loading branch information
corakingdon authored Sep 9, 2019
2 parents 7881a9c + b84fcb1 commit 75fbdf8
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/core/defcomp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ macro defcomp(comp_name, ex)
# @__MODULE__ is evaluated when the expanded macro is interpreted
result = :(
let current_module = @__MODULE__,
comp_id = Mimi.ComponentId(nameof(current_module), $(QuoteNode(comp_name))),
comp_id = Mimi.ComponentId(current_module, $(QuoteNode(comp_name))),
comp = Mimi.ComponentDef(comp_id)

global $comp_name = comp
Expand Down Expand Up @@ -294,7 +294,7 @@ macro defmodel(model_name, ex)
component(comp_mod_name_.comp_name_, alias_) | component(comp_name_, alias_))

# set local copy of comp_mod_name to the stated or default component module
expr = (comp_mod_name === nothing ? :(comp_mod_name = nameof(calling_module)) : :(comp_mod_name = $(QuoteNode(comp_mod_name))))
expr = (comp_mod_name === nothing ? :(comp_mod_name = calling_module) : :(comp_mod_name = comp_mod_name))
addexpr(expr)

name = (alias === nothing ? comp_name : alias)
Expand Down
4 changes: 1 addition & 3 deletions src/core/defs.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# 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 = get_module(comp_id.module_name)
comp_module = comp_id.module_name
comp_def = getfield(comp_module, comp_id.comp_name)
return comp_def
end
Expand Down
4 changes: 2 additions & 2 deletions src/core/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ end
# whose value is an instance of this type, e.g.
# const global adder = ComponentId(module_name, comp_name)
struct ComponentId
module_name::Symbol
module_name::Module
comp_name::Symbol
end

Expand Down Expand Up @@ -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 = get_module(module_name)
comp_module = module_name

# TBD: use FunctionWrapper here?
function get_func(name)
Expand Down
2 changes: 1 addition & 1 deletion test/test_components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ comps = collect(compdefs(my_model))
@test [compkeys(my_model.md)...] == [:testcomp1, :testcomp2, :testcomp3]
@test hascomp(my_model.md, :testcomp1) == true && hascomp(my_model.md, :testcomp4) == false

@test compmodule(testcomp3) == :TestComponents
@test compmodule(testcomp3) == Main.TestComponents
@test compname(testcomp3) == :testcomp3

@test numcomponents(my_model) == 3
Expand Down
2 changes: 1 addition & 1 deletion test/test_metainfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ c2 = compdef(test_model, :ch4forcing2)
@test c1 == compdef(test_model, :ch4forcing1)
@test_throws KeyError compdef(test_model, :missingcomp)

@test c2.comp_id.module_name == :TestMetaInfo
@test c2.comp_id.module_name == Main.TestMetaInfo
@test c2.comp_id.comp_name == :ch4forcing1
@test c2.name == :ch4forcing2

Expand Down
2 changes: 1 addition & 1 deletion test/test_metainfo_variabletimestep.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ c2 = compdef(test_model, :ch4forcing2)
@test c1 == ch4forcing1
@test_throws KeyError compdef(test_model, :missingcomp)

@test c2.comp_id.module_name == :TestMetaInfo_VariableTimestep
@test c2.comp_id.module_name == Main.TestMetaInfo_VariableTimestep
@test c2.comp_id.comp_name == :ch4forcing1
@test c2.name == :ch4forcing2

Expand Down

0 comments on commit 75fbdf8

Please sign in to comment.