- val sorted = sortWeights weights
- val (chosen, w) = List.hd sorted (* Grab the temp with the highest weight. *)
- val () = print (" Chose "^(Temp.name chosen)^" with weight "^(Int.toString w)^"\n");
- val remaining = List.tl sorted
- val neighbors = (* Grab all the neighbors for some given temp. *)
- List.hd
- (List.map (fn (_, neighbors) => neighbors)
- (List.filter (fn (t, _) => T.compare (t, chosen) = EQUAL) graph))
- val () = List.app
- (fn (X.TEMP t) => (print (" Neighbor "^(Temp.name t)^"\n"))
- | (X.REG X.EAX) => (print " Fixed color EAX\n")
- | (X.REG X.EDX) => (print " Fixed color EDX\n")
- | _ => raise ErrorMsg.InternalError "Unknown neighbor type -- const?"
- ) neighbors;
+ val (chosen, w) =
+ foldr
+ (fn ((t1, w1), (t2, w2)) =>
+ if (w2 > w1)
+ then (t2, w2)
+ else (t1, w1))
+ (Temp.new "emarnus", ~9999)
+ weights
+
+ fun ditchOne f nil = nil (* Special case of filter, which bails out after it removes one. *)
+ | ditchOne f (h::l) =
+ if f h
+ then l
+ else h::(ditchOne f l)
+ val remaining = ditchOne (fn (t, w) => Temp.eq (t, chosen)) weights
+
+ val neighbors = (* Grab all the neighbors for some given temp. *)
+ (OperSet.listItems
+ (valOf (TempMap.find (graph, chosen))))