 (defmethod to-vhdl :default [arg] "unimplemented")
 (defmethod to-vhdl 'entity [entity]
   (let [[type name ports & architecture] entity]
-    (lines
+    (apply str (interpose "\n" (indent-lines
+    (list
       (spaces "entity" name "is")
       "port("
-      ;(spaces (concat '(port) (first ports)))
-      ;(interpose " " (concat '(port) (first ports)))
-      (apply str (interpose ";\n" (map to-vhdl (map #(cons 'port %) ports))))
+      (map #(apply str %)
+           (partition 2 (concat (interpose ";" 
+               (map to-vhdl (map #(cons 'port %) ports))) [""])))
       ");"
       (str "end " name ";")
 
       (str "architecture arch_" name " of " name " is")
       "begin"
-      (apply lines (map to-vhdl architecture))
+      (map to-vhdl architecture)
       (str "end arch_" name ";")
+  ))))))
 
-      ;(lines (map to-vhdl (map ports #(concat '(port) %))))
-  )))
+; does not generate lines like block-level methods do
 (defmethod to-vhdl 'port [port]
   (let [[type id direction type] port]
     (str "  " (keyword-to-str id) ": " (keyword-to-str direction) " " type)

(ns computer_build.vhdl)

(defn lines [& strings]
  (apply str (interpose "\n" strings))
  )

(defn indented-lines [indent & strings]
  (apply lines (map #(str "  " %) strings))
  )

(defn spaces [& strings]
  (apply str (interpose " " strings))


(defmethod to-vhdl 'process [process]
  (let [[type ports & definition] process]
    (list
      (str "process(" (apply str (interpose "," (map keyword-to-str ports))) ")")
      "begin"
      (map to-vhdl definition)
      "end process;"
      )))

(defmethod to-vhdl 'case [statement]
  (let [[type target & cases] statement]
    (list
      (spaces "case" (keyword-to-str target) "is")
      (map #(str "when \"" (first %) "\" => " (to-vhdl (second %)) \;)
           (partition 2 cases))
      "end case;"
    )))

; does not generate lines like block-level methods do
(defmethod to-vhdl '<= [statement]
  (let [[type target expression] statement]
    (str (keyword-to-str target) " <= " (keyword-to-str expression))
