Skip to content

Commit

Permalink
🚧 Start fixing tests, find how to inject _hook::System with @method.
Browse files Browse the repository at this point in the history
  • Loading branch information
iago-lito committed Jul 30, 2024
1 parent 566f101 commit 31c7d43
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 71 deletions.
11 changes: 8 additions & 3 deletions src/Framework/blueprint_macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export Brought
# The code checking macro invocation consistency requires
# that pre-requisites (methods implementations) be specified *prior* to invocation.
macro blueprint(input...)
blueprint_macro(__module__, __source__, input...)
end
export @blueprint

# Extract function to ease debugging with Revise.
function blueprint_macro(__module__, __source__, input...)

# Push resulting generated code to this variable.
res = quote end
Expand Down Expand Up @@ -120,7 +126,7 @@ macro blueprint(input...)
fieldtype <: BroughtField || continue
C = componentof(fieldtype)
TC = Type{C}
applicable(implied_blueprint_for, (NewBlueprint, TC)) ||
hasmethod(implied_blueprint_for, Tuple{NewBlueprint,TC}) ||
xerr("Method $implied_blueprint_for($NewBlueprint, $TC) unspecified.")

# Triangular-check against redundancies.
Expand Down Expand Up @@ -155,7 +161,7 @@ macro blueprint(input...)
imap = Iterators.map
ifilter = Iterators.filter
Framework.brought(b::NewBlueprint) =
imap(ifilter(!isnothing, imap(f -> getfield(b, f), keys(brought)))) do f
imap(ifilter(!isnothing, imap(f -> getfield(b, f), keys(broughts)))) do f
f isa Component ? typeof(f) : f
end
end,
Expand Down Expand Up @@ -292,7 +298,6 @@ macro blueprint(input...)

res
end
export @blueprint

specified_as_blueprint(B::Type{<:Blueprint}) = false

Expand Down
2 changes: 1 addition & 1 deletion src/Framework/blueprints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Base.copy(b::Blueprint) = deepcopy(b)
# Return non-empty list if components are required
# for this blueprint to expand,
# even though the corresponding component itself would make sense without these.
expands_from(B::Blueprint{V}) where {V} = throw("Unspecified requirements for $B.")
expands_from(::Blueprint{V}) where {V} = () # Require nothing by default.
# The above is specialized by hand by framework users,
# so make its return type flexible,
# guarded by the below.
Expand Down
2 changes: 1 addition & 1 deletion src/Framework/component.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const Reason = Option{String}
const CompsReasons{V} = OrderedDict{CompType{V},Reason}

# Specify which components are needed for the focal one to make sense.
requires(C::CompType{V}) where {V} = throw("Unspecified requirements for $C.")
requires(::CompType{V}) where {V} = () # Require nothing by default.
requires(c::Component) = requires(typeof(c))

# List all possible blueprints types providing the component.
Expand Down
9 changes: 7 additions & 2 deletions src/Framework/component_macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
# The code checking macro invocation consistency requires
# that these pre-requisites be specified *prior* to invocation.
macro component(input...)
component_macro(__module__, __source__, input...)
end
export @component

# Extract function to ease debugging with Revise.
function component_macro(__module__, __source__, input...)

# Push resulting generated code to this variable.
res = quote end
Expand Down Expand Up @@ -276,7 +282,7 @@ macro component(input...)
push_res!(quote
for (_, B) in base_blueprints
$__module__.eval(quote
$Framework.componentsof(::$B) = $($etys,)
$Framework.componentsof(::$B) = $($ety,)
end)
end
end)
Expand Down Expand Up @@ -311,7 +317,6 @@ macro component(input...)

res
end
export @component

#-------------------------------------------------------------------------------------------
# The 'conflicts_' mapping entries are either abstract or concrete component,
Expand Down
9 changes: 7 additions & 2 deletions src/Framework/conflicts_macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
#
# Minimal use: @conflicts(A, B, C)
macro conflicts(input...)
conflicts_macro(__module__, __source__, input...)
end
export @conflicts

# Extract function to ease debugging with Revise.
function conflicts_macro(__module__, __source__, input...)

# Push resulting generated code to this variable.
res = quote end
Expand Down Expand Up @@ -52,7 +58,7 @@ macro conflicts(input...)
entries = :([])
for entry in input

comp, conf, invalid, reasons, mess = repeat(nothing, 5) # (help JuliaLS)
comp, conf, invalid, reasons, mess = repeat([nothing], 5) # (help JuliaLS)
#! format: off
@capture(entry,
(comp_ => (reasons__,)) |
Expand Down Expand Up @@ -124,4 +130,3 @@ macro conflicts(input...)
res

end
export @conflicts
Loading

0 comments on commit 31c7d43

Please sign in to comment.