@@ -1192,6 +1192,44 @@ function prepare_rhs_for_storage!(ls::LoopSet, RHS::Union{Symbol,Expr}, array, r
1192
1192
return op
1193
1193
end
1194
1194
1195
+ function unpack_tuple! (ls:: LoopSet , LHS:: Expr , RHS, elementbytes:: Int , position:: Int )
1196
+ if Meta. isexpr (RHS, :tuple )
1197
+ for i ∈ eachindex (LHS. args)
1198
+ add_assignment! (ls, LHS. args[i], RHS. args[i], elementbytes, position)
1199
+ end
1200
+ return last (operations (ls)) # FIXME : dummy
1201
+ end
1202
+ @assert length (LHS. args) ≤ 14 " Functions returning more than 9 values aren't currently supported."
1203
+ lhstemp = gensym! (ls, " lhstuple" )
1204
+ vparents = Operation[maybe_const_compute! (ls, lhstemp, add_operation! (ls, lhstemp, RHS, elementbytes, position), elementbytes, position)]
1205
+ unpack_tuple! (ls, LHS, vparents, elementbytes, position)
1206
+ end
1207
+
1208
+ function unpack_tuple! (ls:: LoopSet , LHS:: Expr , vparents:: Vector{Operation} , elementbytes:: Int , position:: Int )
1209
+ for i ∈ eachindex (LHS. args)
1210
+ f = (:first ,:second ,:third ,:fourth ,:fifth ,:sixth ,:seventh ,:eighth ,:ninth ,:tenth ,:eleventh ,:twelfth ,:thirteenth ,:last )[i]
1211
+ lhsi = LHS. args[i]
1212
+ if lhsi isa Symbol
1213
+ add_compute! (ls, lhsi, f, vparents, elementbytes)
1214
+ continue
1215
+ elseif lhsi isa Expr
1216
+ if lhsi. head === :ref
1217
+ tempunpacksym = gensym! (ls, " tempunpack" )
1218
+ add_compute! (ls, tempunpacksym, f, vparents, elementbytes)
1219
+ add_store_ref! (ls, tempunpacksym, lhsi, elementbytes)
1220
+ continue
1221
+ elseif lhsi. head === :tuple
1222
+ lhstemp = gensym! (ls, " lhstuple" )
1223
+ op = add_compute! (ls, lhstemp, f, vparents, elementbytes)
1224
+ unpack_tuple! (ls, lhsi, [op], elementbytes, position)
1225
+ continue
1226
+ end
1227
+ end
1228
+ throw (LoopError (" Unpacking the above expression in the left hand side was not understood/supported." , lhsi))
1229
+ end
1230
+ first (vparents)
1231
+ end
1232
+
1195
1233
function add_assignment! (ls:: LoopSet , LHS, RHS, elementbytes:: Int , position:: Int )
1196
1234
if LHS isa Symbol
1197
1235
if RHS isa Expr
@@ -1212,29 +1250,7 @@ function add_assignment!(ls::LoopSet, LHS, RHS, elementbytes::Int, position::Int
1212
1250
add_store_ref! (ls, RHS, LHS, elementbytes) # is this necessary? (Extension API?)
1213
1251
end
1214
1252
elseif LHS. head === :tuple
1215
- if RHS. head === :tuple
1216
- for i ∈ eachindex (LHS. args)
1217
- add_assignment! (ls, LHS. args[i], RHS. args[i], elementbytes, position)
1218
- end
1219
- return last (operations (ls)) # FIXME : dummy
1220
- end
1221
- @assert length (LHS. args) ≤ 14 " Functions returning more than 9 values aren't currently supported."
1222
- lhstemp = gensym! (ls, " lhstuple" )
1223
- vparents = Operation[maybe_const_compute! (ls, lhstemp, add_operation! (ls, lhstemp, RHS, elementbytes, position), elementbytes, position)]
1224
- for i ∈ eachindex (LHS. args)
1225
- f = (:first ,:second ,:third ,:fourth ,:fifth ,:sixth ,:seventh ,:eighth ,:ninth ,:tenth ,:eleventh ,:twelfth ,:thirteenth ,:last )[i]
1226
- lhsi = LHS. args[i]
1227
- if lhsi isa Symbol
1228
- add_compute! (ls, lhsi, f, vparents, elementbytes)
1229
- elseif lhsi isa Expr && lhsi. head === :ref
1230
- tempunpacksym = gensym! (ls, " tempunpack" )
1231
- add_compute! (ls, tempunpacksym, f, vparents, elementbytes)
1232
- add_store_ref! (ls, tempunpacksym, lhsi, elementbytes)
1233
- else
1234
- throw (LoopError (" Unpacking the above expression in the left hand side was not understood/supported." , lhsi))
1235
- end
1236
- end
1237
- first (vparents)
1253
+ unpack_tuple! (ls, LHS, RHS, elementbytes, position)
1238
1254
else
1239
1255
throw (LoopError (" LHS not understood; only `:ref`s and `:tuple`s are currently supported." , LHS))
1240
1256
end
0 commit comments