 (ns computer-build.vhdl
-  (:use clojure.contrib.str-utils)
-  (:require [clojure.core :as core]))
+  (:use clojure.contrib.str-utils))
 
-(def entity)
-(def process)
-(def port)
-(def case)
-(def assign)
 
 (defn indented-lines [strings] (map (partial str "  ") strings))
 


(defn quoted-str [string] (str \" string \"))

(defmulti to-vhdl first)
(defmethod to-vhdl :default [arg] (str "###UNIMPLEMENTED: " (first arg) "###"))
(defmethod to-vhdl 'computer-build.vhdl/entity [[type name ports & architecture]]
  (apply str (interpose "\n" (indent-lines
  (list
    (spaces "entity" name "is")
    "port("
    (commaify (map to-vhdl (map (partial cons 'computer-build.vhdl/port) ports)))
    ");"
    (str "end " name ";")

    (str "architecture arch_" name " of " name " is")
    "begin"
    (map to-vhdl architecture)
    (str "end arch_" name ";"))))))

; does not generate lines like block-level methods do
(defmethod to-vhdl 'computer-build.vhdl/port [[type id direction type]]
  (str (keyword-to-str id) ": " (keyword-to-str direction) " " type))

(defmethod to-vhdl 'computer-build.vhdl/process [[type ports & definition]]
  (list
    (str "process(" (str-join "," (map keyword-to-str ports)) ")")
    "begin"
    (map to-vhdl definition)
    "end process;"))

(defmethod to-vhdl 'computer-build.vhdl/case [[type target & cases]]
  (list
    (spaces "case" (keyword-to-str target) "is")
    (map #(str (spaces "when" (quoted-str (first %)) "=>" (to-vhdl (second %))) \;)

    "end case;"))

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

(defn generate-vhdl [& entities]
