 (defn remove-eseq-commute
   "(BinaryOp op e1 (ExpSeq s2 e2)) -> [s2 (BinaryOp op e1 e2)]"
   [tree]
-  (let [e1 (get tree :exp1)
-        s2 (get-in tree [:exp2 :seqs])
-        e2 (get-in tree [:exp2 :exp])]
+  (let [e1 (canon (get tree :exp1))
+        s2 (canon (get-in tree [:exp2 :seqs]))
+        e2 (canon (get-in tree [:exp2 :exp]))]
     (conj (vec s2)
           (merge tree [:exp2 e2]))))
 

  "(BinaryOp op e1 (ExpSeq s2 e2))
     -> [(Move e1 (Temp t)) s2 (BinaryOp op (Temp t e2))]"
  [tree]
  (let [e1 (get tree :exp1)
        s1 (get-in tree [:exp2 :seqs])
        e2 (get-in tree [:exp2 :exp])
        t  (tm/temp)]
    (concat [(Move e1 (Temp t))]
            s1

        clojure.contrib.seq)
  (:require [minijava.temp :as tm]))

(declare canon)

(defn remove-double-eseq
  "(ExpSeq s1 (ExpSeq s2 e)) -> [s1 s2 e]"
  [tree]
  (let [s1 (canon (:seqs tree ))
        s2 (canon (get-in tree [:exp :seqs]))
        e  (canon  (get-in tree [:exp :exp]))]
    (conj (vec (concat s1 s2))
          e)))

(defn remove-eseq-left
  "(BinaryOp op (ExpSeq stmt expr) e2) -> [stmt (BinaryOp op expr e2)]"
  [tree] 
  (let [stmt (canon (get-in tree [:exp1 :seqs]))
        expr (canon (get-in tree [:exp1 :exp]))]
    (conj (vec stmt)
          (merge tree [:exp1 expr]))))

