 ;; img  -- 2d matrix of 0's and 1's
 ;; w    -- int, width of output, in chars
 (defn harnify [code img w]
+  ;(.profile js/console "harnify")
   (let [ts (analyze-code code)
         [arranged ts-unused] (arrange-tokens ts img [])
         unused               (arrange-unused ts-unused 160)

    (catch js/Error e
      (println "Parse error: " e))))

;; TODO: add unused tokens

(let [code2     "var a = 42;\nvar b = 43;"
      code      "function skipComment() {
        var ch, start = 'hello world! this is a long line';

        start = (index === 0);
        while (index < length) {
            ch = source.charCodeAt(index);

            if (isWhiteSpace(ch)) {
                ++index;
            } else if (isLineTerminator(ch)) {
                ++index;
                if (ch === 0x0D && source.charCodeAt(index) === 0x0A) {
                    ++index;
                }
                ++lineNumber;
                lineStart = index;
                start = true;
            } else if (ch === 0x2F) { // U+002F is '/'
                ch = source.charCodeAt(index + 1);
                if (ch === 0x2F) {
                    ++index;
                    ++index;
                    skipSingleLineComment(2);
                    start = true;
                } else if (ch === 0x2A) {  // U+002A is '*'
                    ++index;
                    ++index;
                    skipMultiLineComment();
                } else {
                    break;
                }
            } else if (start && ch === 0x2D) { // U+002D is '-'
                // U+003E is '>'
                if ((source.charCodeAt(index + 1) === 0x2D) && (source.charCodeAt(index + 2) === 0x3E)) {
                    // '-->' is a single-line comment
                    index += 3;
                    skipSingleLineComment(3);
                } else {
                    break;
                }
            } else if (ch === 0x3C) { // U+003C is '<'
                if (source.slice(index + 1, index + 4) === '!--') {
                    ++index; // `<`
                    ++index; // `!`
                    ++index; // `-`
                    ++index; // `-`
                    skipSingleLineComment(4);
                } else {
                    break;
                }
            } else {
                break;
            }
        }
    }"
      img @img
      width (count (first img))
      harnocode (harnify code img width)]
  (validate code img width)
  (show-harnocode! harnocode))



(fw/start {
           :load-warninged-code true
           })

(defn redraw! []
  (let [code (.-value (dom/getElement "output"))


(enable-console-print!)

(defn dummy-image [w h]
  (let [ones (concat (repeat 10 0) (repeat w 1))]
    (repeat h ones)))

(defonce img
    (atom (dummy-image 100 200)))

(defn to-clj-array [js-col]
  (-> (clj->js [])
