::Myco::FileToplevel << {

# TODO: don't use instance_variable_get
dirname:  component.instance_variable_get("@dirname")
basename: component.instance_variable_get("@basename")
filename: component.instance_variable_get("@filename")

[decorators]

# Run the code in the given file, ignoring the return value but
# importing the constants defined therein into the current namespace.
const import: Decorator {
  apply: |meme| {
    load_paths = [meme.target.instance.dirname]
    scope = meme.target.constant_scope
    component = Myco.eval_file(meme.name.to_s, load_paths, false, scope)

    const_name = meme.metadata[:as]
    const_name &? (
      meme.target.const_set(const_name, component)
    ) ?? (
      meme.target.include(component)
    )
  }
}
# Force an import to assign to a constant in the current namespace
# instead of being included into the current namespace.
const as: Decorator {
  apply: |meme, given| meme.metadata[:as] = given
}

}