11# ## species definition
2- macro plant (name, icon)
3- return esc (_species (name, icon; animal= false ))
4- end
5-
6- macro animal (name, icon)
7- return esc (_species (name, icon; animal= true ))
2+ macro species (typ, name, icon)
3+ esc (_species (typ, name, icon))
84end
95
10- function _species (name, icon; animal = false )
6+ function _species (typ, name, icon)
117 quote
12- abstract type $ name <: $ (animal ? AnimalSpecies : PlantSpecies) end
8+ abstract type $ name <: $ (typ == :Animal ? AnimalSpecies : PlantSpecies) end
139 Base. show (io:: IO , :: Type{$name} ) = print (io, $ (QuoteNode (icon)))
1410 export $ name
1511 end
1612end
1713
14+ macro plant (name, icon)
15+ return :(@species Plant $ name $ icon)
16+ end
1817
19- # ## eating
18+ macro animal (name, icon)
19+ return :(@species Animal $ name $ icon)
20+ end
21+
22+ # ## eating behavior
2023macro eats (species:: Symbol , foodlist:: Expr )
2124 return esc (_eats (species, foodlist))
2225end
2326
24- _parse_eats (ex) = Dict (arg . args[ 2 ] => arg . args[ 3 ] for arg in ex . args if arg . head == :call && arg . args[ 1 ] == :( => ))
27+
2528function _generate_eat (eater:: Type{<:AnimalSpecies} , food:: Type{<:PlantSpecies} , multiplier)
2629 quote
2730 EcosystemCore. eats (:: Animal{$(eater)} , :: Plant{$(food)} ) = true
@@ -44,6 +47,8 @@ function _generate_eat(eater::Type{<:AnimalSpecies}, food::Type{<:AnimalSpecies}
4447 end
4548end
4649
50+ _parse_eats (ex) = Dict (arg. args[2 ] => arg. args[3 ] for arg in ex. args if arg. head == :call && arg. args[1 ] == :(=> ))
51+
4752function _eats (species, foodlist)
4853 cfg = _parse_eats (foodlist)
4954 code = Expr (:block )
0 commit comments