Reference

Contents

Index

ModuleMixins.substitute_top_level — Method
substitute_top_level(var, val, mod, expr)

Takes a syntax object expr and substitutes every occurence of module var for val, only if the resulting object is actually present in module mod. The mod module should correspond with a lookup of val in the caller's namespace.

source
ModuleMixins.@compose — Macro
@compose module Name
    [@mixin Parents, ...]
    ...
end

Creates a new composable module Name. Structs inside this module are merged with those of the same name in Parents.

source
ModuleMixins.@for_each — Macro
@for_each(M -> M.method(), lst::Vector{Symbol})

Calls method() for each module in lst that actually implements that method. Here lst should be a vector of symbols that are all in the current module's namespace.

source
ModuleMixins.Passes.pass — Method
pass(x::CompositePass, expr)

Tries all passes in a composite pass in order, and returns with the first that succeeds (i.e. doesn't return no_match). You may create a CompositePass by adding passes with the + operator.

source
ModuleMixins.Passes.pass — Method
pass(x::Pass, expr)

Interface. An implementation of the pass function should take a Pass object and an expression (or symbol), and return no_match if the expression did not match the pattern.

You can use the given Pass object to store information about this pass, return syntax that should replace the current expression, or nothing if it should be removed.

source
ModuleMixins.Passes.walk — Method
walk(x::Pass, expr_list)

Calls MacroTools.prewalk with the given Pass. If no_match is returned, the expression stays untouched.

source
ModuleMixins.Spec.@spec — Macro
@spec module *name*
    *body*...
end

Create a spec. The @spec macro itself doesn't perform any operations other than creating a module and storing its own AST as const *name*.AST.

This macro is only here for teaching purposes.

source
ModuleMixins.Common.eval_to_expression — Method
eval_to_expression(mod::Module, obj)

Generic function for converting syntax data objects to expressions, where parts of expressions need to be evaluated in a given module.

Defaults to calling to_expression, dropping the mod argument.

source
ModuleMixins.Common.strip_syntax_version — Method
strip_syntax_version(expr)

From Julia 1.14, a module expression may carry the syntax version of the code it was parsed from as its first argument: Expr(:module, v"1.14.0", true, name, body). Whether it does depends on the project the code lives in, not on the Julia version alone. Remove the version, so that @capture patterns of the form module name_ body__ end match either way.

source
Core.Type — Method
Composite{T, R}(; kwargs...)

Construct a composite from flat keyword arguments. Each keyword goes to the part that has a field of that name.

source
ModuleMixins.Procedural.Composite — Type
Composite{T <: Tuple, R <: Tuple}

A value composed of parts, one per component. Properties are forwarded to the part that has a field of that name, so c.x works for any field x of any part. R is a tuple of RoleMap markers, recording which part fills each role.

source
ModuleMixins.Procedural.closure — Method
closure(roots::Module...)

Compute all components needed by roots, in dependency order (dependencies first), each component appearing once. Roles are resolved to a component implementing them: one of the roots if any, otherwise default_implementation.

source
ModuleMixins.Procedural.component — Method
component(c::Composite, ::Val{M})
component(c::Composite, M::Module)
component(c::Composite, T::Type)

The part of c contributed by component M, the part of type T, or, if T is a role (an abstract type), the part contributed by the component that implements T. Pass a module as Val(M) for a type-stable lookup.

source
ModuleMixins.Procedural.record_type — Method
record_type(name::Symbol, roots::Module...)

The Composite type of record name, for the closure of roots. It has one part for every component that defines a type name, in dependency order.

source
ModuleMixins.Procedural.requires — Method
requires(::Val{M})

The components (modules) or roles (abstract types) that component M depends on. Extend this for every component that has dependencies.

source
ModuleMixins.Procedural.resolve — Method
resolve(R, roots)

The component that fills requirement R. A module is a component and resolves to itself. A role resolves to the one component in roots that implements it, or else to its default_implementation.

source
ModuleMixins.Syntactic.declaration — Method
declaration(expr)

If expr is one of the declarations @mixin, @requires or @implements, return the declaration name and its arguments. Otherwise return nothing. Arguments may be separated by spaces or by commas.

source
ModuleMixins.Syntactic.map_struct — Method
map_struct(f, expr)

Apply f to the struct definition in expr, looking through macro calls like @kwdef and docstrings. Returns expr unchanged if it doesn't define a struct.

source
ModuleMixins.Syntactic.parameterize — Method
parameterize(expr, struct_names)

Rewrite the struct defined in expr (if any), so that every other struct in struct_names that is mentioned in a field type becomes a type parameter.

source
ModuleMixins.Syntactic.@component — Macro
@component module Name
    [@mixin Components...]
    [@requires Requirements...]
    [@implements Roles...]
    ...
end

Define a component module. The declarations expand into methods of ModuleMixins.Procedural:

  • @mixin A, B: import A and B from the parent module (if they are plain names), and require them as components.
  • @requires R: require role or component R.
  • @implements R: the component implements role R.

If a field type of a struct mentions another struct S of the same module, the struct gets a type parameter S, which record_type fills with the composite of all parts of record S.

source