Fork me on GitHub
Ivo Horák07:10:23

Hello, I would like to start project which which will interpret Clojure using Truffle. My idea is to reuse some parts of Clojure implementation. The problem is that code is quite hard to read. From what I read on the internat LispReader should accept stream of characters as and input and transform it into Clojure datastructures. Then Compiler class should take those datastructure and convert it into Clojure AST. When I look the code I am not able to find it properly. Anyone could assist please or interested in this project?


I think it's an interesting idea and I've also looked into Truffle + Clojure myself. If I may ask, what would be your major reason to run Clojure on Truffle?

Ivo Horák07:10:33

Well the main benefit would be hopefully performance. Also Truffle(here I mean graal compiler) is trying to improve their optimization regularly so in the future in could improve even more.


There is a thesis from 2015 which also has built a Clojure Truffle interpreter. Have you found that?


I am trying to keep some resources around this topic here:

Ivo Horák07:10:33

Yeah I foudn the thesis and from there I took an inspiration (using parts of Clojure official implementation)

Ivo Horák07:10:35

I found you repo before but I could grasp where is parser and lexer?


There is none yet. But you should be able to use LispReader. Are you trying to use it from Java?

Ivo Horák07:10:43

Yeah, I am trying to use LispReader but no luck to get something meaningful

Ivo Horák07:10:37

And if I am not wrong, then LispReader should be call from Compiler class and this class is responsible for building Clojure AST and convert it to the bytecode. WHat I want to try is to remove the bytecode part and usign the Clojure AST and convert it into Truffle AST


user=> (clojure.lang.LispReader/read ( ( "(+ 1 2 3)")) nil)
(+ 1 2 3)


yes, this should be possible

Ivo Horák07:10:05

Interesting I tried to do that from Java. Like copying the class from the original project


Do we actually know how much better is graal's jit against bare hotspot? I don't want to make any false claims but I think Clojure compiler produces code that's fairly close to what Java is doing. So benefits from graal going to be more on side of escape analysis and aggressive hot path inlining than anything else. My personal guess is 20 % maximum. No two fold numbers like in case of Truffleruby.