Skip to content

Commit

Permalink
Start making macro
Browse files Browse the repository at this point in the history
  • Loading branch information
ptiede committed Aug 5, 2024
1 parent 1cf8303 commit b838fec
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LogDensityProblems = "6fdf6af0-433a-55f7-b3ed-c6c6e0b8df7c"
LogDensityProblemsAD = "996a588d-648d-4e1f-a8f0-a84b347e47b1"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
NamedTupleTools = "d9ec5142-1e00-5aa0-9d6a-321866360f50"
PaddedViews = "5432bcbf-9aad-5242-b902-cca2824c8663"
ParameterHandling = "2412ca09-6db7-441c-8e3a-88d5709968c5"
Expand Down Expand Up @@ -62,8 +63,8 @@ ComradePigeonsExt = "Pigeons"
ComradePyehtimExt = "Pyehtim"

[compat]
Accessors = "0.1"
AbstractMCMC = "3, 4, 5"
Accessors = "0.1"
AdvancedHMC = "0.6"
ArgCheck = "2"
AstroTime = "0.6,0.7"
Expand All @@ -80,8 +81,8 @@ FillArrays = "0.12, 0.13, 1"
ForwardDiff = "0.9, 0.10"
HypercubeTransform = "0.4"
IntervalSets = "0.6, 0.7"
LogDensityProblemsAD = "1"
LogDensityProblems = "2"
LogDensityProblemsAD = "1"
Makie = "0.21"
NamedTupleTools = "0.13,0.14"
NestedSamplers = "0.8"
Expand Down
38 changes: 38 additions & 0 deletions src/skymodels/macro.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using MacroTools
using NamedTupleTools


# Idea
# 1. capture all tilde statements and convert them to a NamedTupleDist
# 2. capture all equals signs and convert make a function with a gensym name
# 3. capture all arguments and make a named tuple with them as metadata


macro sky(expr)
# println(expr)
def = splitdef(expr)
name = def[:name]
args = def[:args]
kwargs = def[:kwargs]
body = def[:body]

g = args[1]
gexpr = Expr(:kw, g, esc(g))
metadata = build_metadata([kwargs...,gexpr])
prior = build_prior(metadata, body)
# skym = build_sky(args, kwargs, body)
return quote
$metadata
# $(esc(name)) = SkyModel($skym, $prior, $g; metadata=$metadata)
# $name = SkyModel($skym, $prior, $g; metadata=$metadata)
end
end

function build_metadata(kwargs)
isempty(kwargs) && return nothing
return Expr(:tuple, Expr(:parameters, kwargs..., (:)))
end

function build_prior(metadata, body)

end

0 comments on commit b838fec

Please sign in to comment.