Skip to content

Commit

Permalink
🚧 Inject _hook::System with @method macro, start fixing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
iago-lito committed Aug 1, 2024
1 parent 566f101 commit 7d66085
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 100 deletions.
15 changes: 11 additions & 4 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,9 @@ 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).value, keys(broughts))),
) do f
f isa Component ? typeof(f) : f
end
end,
Expand Down Expand Up @@ -259,7 +267,7 @@ macro blueprint(input...)

function Framework.display_long(io::IO, bp::NewBlueprint; level = 0)
comps = provided_comps_display(bp)
print(io, "blueprint for $C: $(nameof(NewBlueprint)) {")
print(io, "blueprint for $comps: $(nameof(NewBlueprint)) {")
preindent = repeat(" ", level)
level += 1
indent = repeat(" ", level)
Expand Down Expand Up @@ -292,7 +300,6 @@ macro blueprint(input...)

res
end
export @blueprint

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

Expand Down
6 changes: 3 additions & 3 deletions 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 Expand Up @@ -180,12 +180,12 @@ export BlueprintCheckFailure, checkfails

# ==========================================================================================
# Explicit terminal display.
function Base.show(io::IO, ::MIME"text/plain", B::Type{<:Blueprint})
function Base.show(io::IO, ::MIME"text/plain", B::Type{<:Blueprint{V}}) where {V}
print(
io,
"$B \
$(crayon"black")\
(blueprint type for component '$(componentsof(B))')\
(blueprint type for $(nameof(System)){$V})\
$(crayon"reset")",
)
end
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 7d66085

Please sign in to comment.