Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new emitter not based on fipp #25

Open
kovasb opened this issue Aug 5, 2015 · 8 comments
Open

new emitter not based on fipp #25

kovasb opened this issue Aug 5, 2015 · 8 comments

Comments

@kovasb
Copy link
Owner

kovasb commented Aug 5, 2015

Want a trivial emitter so we can port this to clojureclr

@brandonbloom
Copy link

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
Copy link

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

@kovasb
Copy link
Owner Author

kovasb commented Aug 5, 2015

Yes the rrb vectors are the culprit

@kovasb
Copy link
Owner Author

kovasb commented Aug 5, 2015

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

@brandonbloom
Copy link

@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.

@michalmarczyk
Copy link

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.

@brandonbloom
Copy link

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

@timsgardner
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants