gamma icon indicating copy to clipboard operation
gamma copied to clipboard

new emitter not based on fipp

Open kovasb opened this issue 10 years ago • 8 comments

Want a trivial emitter so we can port this to clojureclr

kovasb avatar Aug 05 '15 02:08 kovasb

I haven't tried it, but fipp should be able to run on ClojureCLR with the exception of the ednize namespace, which you don't need, right? The ednize namespace should be easy to port too, it's already the intentionally duplicated part for jvm and js targets.

brandonbloom avatar Aug 05 '15 18:08 brandonbloom

Oh, except maybe rrb vectors need to be ported too?

brandonbloom avatar Aug 05 '15 18:08 brandonbloom

Yes the rrb vectors are the culprit

kovasb avatar Aug 05 '15 18:08 kovasb

We are gonna keep the fipp emitter on the side but need another option for clr and other platforms

kovasb avatar Aug 05 '15 19:08 kovasb

@michalmarczyk: Would rrb on clr be difficult? Seems like it would require yet another full fork :-/

@kovasb: Are 2-3 finger trees available on clr? Can easily shadow deque.cljc to support that.

brandonbloom avatar Aug 05 '15 19:08 brandonbloom

Hey, sorry for the delay.

Not sure how much effort that would be, but looking at gvec.clj in clojure-clr makes me cautiously optimistic. If things work out really well, it might even be possible to share a good chunk, possibly most of the code. I don't even have Mono set up atm, so not sure when I'll be able to experiment with that, though…

deque.cljc sounds like a simple solution, though, and data.finger-tree seems very portable. Might be worth porting that first to see how much hassle that is and how much code sharing is possible.

michalmarczyk avatar Aug 08 '15 08:08 michalmarczyk

@kovasb If you want to take a crack at porting finger-trees, here's the old fipp deque impl that used it: https://github.com/brandonbloom/fipp/commit/a2bd18a92a8480bd84a0410ae9041ed6f2fedcf0

brandonbloom avatar Aug 12 '15 02:08 brandonbloom

I'm using Gamma in Arcadia.

Rather than porting fipp I stripped it out, and am using a janky little formatter function to make its output vaguely readable.

gvec on clojure-clr is hella broken, also probably redundant, or at least in need of a fundamental rethink since the clr has real generics. We just commented it out for the Arcadia compiler, I think David Miller wants to gut or scrap it. He said it was one of, if not the, most difficult parts of the Clojure compiler to port. Need to check up on the latest development with all that but we're getting along fine without it; not sure if that has implications for rrb-vector tho.

Here's the main modification I made to Gamma to get it working in Arcadia:

(ns gamma.program ...)

...

(defn unfipp [x]
  (->> x
    (clojure.walk/prewalk
      (fn [x]
        (if (and (vector? x) (= (first x) :nest))
          (drop 2 x)
          x)))
    flatten
    (remove keyword?)
    (apply str)))

(defn glsl [shader precision]
  (let [p precision]
    (str
      (precision-defaults p)
      (unfipp
        (emit/emit (:ir shader) shader)))))

...

and then for prettification:

(defn- format-program [x]
  (let [lines (-> x
                (clojure.string/replace ";" ";\n")
                (clojure.string/replace "{" "{\n")
                (clojure.string/replace "}" "\n}\n")
                clojure.string/split-lines)
        indent-f (fn [indent s]
                   (-> (apply str (repeat indent "\t"))
                     (str s)))]
    (first
      (reduce
        (fn [[bldg, indent] line]
          (cond
            (re-matches #"^\s*}.*" line)
            [(str bldg (indent-f (dec indent) line) "\n")
             (dec indent)]

            (re-matches #".*{$" line)
            [(str bldg (indent-f indent line) "\n")
             (inc indent)]

            :else
            [(str bldg (indent-f indent line) "\n")
             indent]))
        ["" 0]
        lines))))

Works well enough so far as a stopgap, though I'm sure hugely composed terms would get nasty.

timsgardner avatar Aug 17 '15 05:08 timsgardner