Skip to content

Commit

Permalink
more toexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
shashi committed Jan 26, 2021
1 parent 81fa1dd commit 0d8f28c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/code.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,33 @@ end
elems # Either iterator of Pairs or just an iterator
end

@matchable struct AtIndex
i::Int
elem
end

function toexpr(a::AtIndex)
toexpr(a.elem)
end

function toexpr(s::SetArray)
quote
$([$(toexpr(s.arr))[$(ex isa AtIndex ? ex.i : i)] = $(toexpr(ex))
for (i, ex) in enumerate(s.elems)]...)
nothing
end
end

@matchable struct MakeArray{A<:AbstractArray} # Could be StaticArray
elems::A
end

function toexpr(a::MakeArray)
:([$(toexpr.(a.elems)...)])
end

## We use a separate type for Sparse Arrays to sidestep the need for
## iszero to be defined on the expression type
@matchable struct MakeSparseArray
I
J
Expand All @@ -116,3 +139,7 @@ end
@matchable struct MakeTuple
elems
end

function toexpr(a::MakeTuple)
:(($(toexpr.(a.elems)...),))
end

0 comments on commit 0d8f28c

Please sign in to comment.