Fork me on GitHub
#clojurescript
<
2018-01-07
>
qqq00:01:09

(moving over question from #clojure) is there some restricted subset of cljs that can be used to write ultrafast wasm ?

darwin00:01:30

@qqq there is a subset of ClojureScript which can be compiled into WASM, it is called Clojure šŸ˜‰ look into http://teavm.org, but Iā€™m not sure if it can run ultrafast, I doubt it šŸ™‚

darwin00:01:51

another option would be to use Ferret, https://ferret-lang.org and compile resulting C++ to WASM

qqq00:01:54

@darwin: I was really looking for a DSL rather than compile entire JVM to wasm šŸ™‚

qqq01:01:09

isn't wasm scheme syntax? I can't believe ther'es no direct route

darwin01:01:22

AFAIK, WASM is designed as compilation target, it would be PITA to write anything directly in it (no matter of source code notation)

qqq01:01:40

let NumClojure = NumPY rewritten in Clojure. I suspect it would be straight forward to write a NumClojure -> WASM compiler, reading in sexp and outputting sexp

akiroz01:01:06

Yeah, wasm is pretty low level... it's aimed as a compilation target for C/C++/Rust

akiroz01:01:03

But GC and native exception handling is on the roadmap so.... maybe it will be a suitable target for Clojure in the future?

akiroz02:01:08

not sure if the performance gains will be worth the development cost though.

aklein02:01:01

Hey everyone, is there a recommended tool that can help me track down why my ClojureScript build (using lein-cljsbuild) with advanced optimizations is way bigger than it should be? Or are there know pitfalls?

qqq02:01:41

my point (but never explicitly stated) is that if you're just doing tensor math, you don't need a gc

dnolen13:01:25

@qqq: Iā€™m not aware of any wasm DSLs, sounds like a fun project though

qqq13:01:57

I don't know enough wasm, so I'm currently going the clojure dsl -> c -> llvm -> wasm route

qqq13:01:08

but I do think cljs -> wasm directly is much more elegant

tbaldridge13:01:11

@qqq the problem with CLJ -> wasm is the same with CLJ -> C . No GC, no polymorpism, no object system, etc.

kennytilton17:01:54

@kenrestivo I am using cljs-http. I have no idea if that is current best practice, however.

qqq20:01:39

@tbaldridge: sorry, by "CLJ -> wasm" I mean "some data struture in CLJ -> wasm", not "clj itself -> wasm"

qqq20:01:16

@tbaldridge: in fact, here's what I have so far:

(do ;; expr->str
    (def expr->str            (let [f #(apply a/strf %1 (map expr->str %2))]
                                (fn [expr]
                                  (a/ctl expr
                                    [[::var ::vname] vname]
                                    [[::arr ::base ::index] (f "(%s[%s])" [base index])]
                                    [[::add ::lhs ::rhs] (f "(%s+%s)" [lhs rhs])]
                                    [[::sub ::lhs ::rhs] (f "(%s-%s)" [lhs rhs])]
                                    [[::mul ::lhs ::rhs] (f "(%s*%s)" [lhs rhs])]
                                    [[::div ::lhs ::rhs] (f "(%s/%s)" [lhs rhs])]))))
    (ct/is                    (= "a" (expr->str (var-raw {::vname "a"}))))
    (ct/is                    (= "(a[b])" (expr->str (arr-raw {::base  (var-raw {::vname "a"})
                                                               ::index (var-raw {::vname "b"})})))) 
    (ct/is                    (= "(a+b)" (expr->str (add-raw {::lhs (var-raw {::vname "a"})
                                                              ::rhs (var-raw {::vname "b"})}))))
    (ct/is                    (= "(a-b)" (expr->str (sub-raw {::lhs (var-raw {::vname "a"})
                                                              ::rhs (var-raw {::vname "b"})}))))
    (ct/is                    (= "(a*b)" (expr->str (mul-raw {::lhs (var-raw {::vname "a"})
                                                              ::rhs (var-raw {::vname "b"})}))))
    (ct/is                    (= "(a/b)" (expr->str (div-raw {::lhs (var-raw {::vname "a"})
                                                              ::rhs (var-raw {::vname "b"})})))))
it translates "clojure data" representing a C program into a string, which is corresponding C code; currently it only does exprs, no statements yet