Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

comp_id.module #532

Merged
merged 2 commits into from
Sep 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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