@@ -526,7 +526,7 @@ function register_single_loop!(ls::LoopSet, looprange::Expr)
526
526
U = add_loop_bound! (ls, itersym, Expr (:call , lv (:maybestaticlast ), N), true )
527
527
loop = Loop (itersym, L, U)
528
528
else
529
- throw (" Unrecognized loop range type: $r ." )
529
+ throw (LoopError ( " Unrecognized loop range type: $r ." ) )
530
530
end
531
531
add_loop! (ls, loop, itersym)
532
532
nothing
@@ -621,8 +621,7 @@ function add_operation!(
621
621
elseif RHS. head === :block
622
622
add_operation! (ls, LHS, strip_op_linenumber_nodes (RHS), elementbytes, position)
623
623
else
624
- println (RHS)
625
- throw (" Expression not recognized." )
624
+ throw (LoopError (" Expression not recognized." , RHS))
626
625
end
627
626
end
628
627
add_operation! (ls:: LoopSet , RHS:: Expr , elementbytes:: Int , position:: Int ) = add_operation! (ls, gensym (:LHS ), RHS, elementbytes, position)
@@ -657,8 +656,7 @@ function add_operation!(
657
656
elseif RHS. head === :block
658
657
add_operation! (ls, LHS, strip_op_linenumber_nodes (RHS), elementbytes, position)
659
658
else
660
- println (RHS)
661
- throw (" Expression not recognized." )
659
+ throw (LoopError (" Expression not recognized." , RHS))
662
660
end
663
661
end
664
662
@@ -722,18 +720,15 @@ function Base.push!(ls::LoopSet, ex::Expr, elementbytes::Int, position::Int)
722
720
add_compute! (ls, tempunpacksym, f, vparents, elementbytes)
723
721
add_store_ref! (ls, tempunpacksym, lhsi, elementbytes)
724
722
else
725
- println (lhsi)
726
- throw (" Unpacking the above expression in the left hand side was not understood/supported." )
723
+ throw (LoopError (" Unpacking the above expression in the left hand side was not understood/supported." , lhsi))
727
724
end
728
725
end
729
726
first (vparents)
730
727
else
731
- println (LHS)
732
- throw (" LHS not understood; only `:ref`s and `:tuple`s are currently supported." )
728
+ throw (LoopError (" LHS not understood; only `:ref`s and `:tuple`s are currently supported." , LHS))
733
729
end
734
730
else
735
- println (LHS)
736
- throw (" LHS not understood." )
731
+ throw (LoopError (" LHS not understood." , LHS))
737
732
end
738
733
elseif ex. head === :block
739
734
add_block! (ls, ex, elementbytes, position)
@@ -756,8 +751,7 @@ function Base.push!(ls::LoopSet, ex::Expr, elementbytes::Int, position::Int)
756
751
add_compute! (ls, LHS, :identity , [RHS], elementbytes)
757
752
end
758
753
else
759
- println (ex)
760
- throw (" Don't know how to handle expression." )
754
+ throw (LoopError (" Don't know how to handle expression." , ex))
761
755
end
762
756
end
763
757
817
811
# order[u₁loopnum], order[u₂loopnum]
818
812
# end
819
813
814
+
815
+ struct LoopError <: Exception
816
+ msg
817
+ ex
818
+ LoopError (msg, ex= nothing ) = new (msg, ex)
819
+ end
820
+
821
+ function Base. showerror (io:: IO , err:: LoopError )
822
+ printstyled (io, err. msg; color = :red )
823
+ isnothing (err. ex) || printstyled (io, ' \n ' , err. ex)
824
+ end
0 commit comments