5 ms·
LLVM Clojure Bindings
- swannodette 15y agoI was excited to find out that the developer, Jason Jackson, had actually used core.logic (https://github.com/clojure/core.logic https://github.com/clojure/core.logic) to implement a type checker as well as used core.match (https://github.com/clojure/core.match https://github.com/clojure/core.match) for pattern matching in his compiler projects. As these tools mature - I think over time Clojure could provide a pretty sweet library ecosystem for folks looking to design new languages.
- jasonjackson 15y agoJust to clarify I'm actually working on a second compiler project written in Clojure. It's my 2nd project that uses core.logic and core.match extensively. Core.Logic was the perfect abstraction for doing all the type checking -- I'm really grateful for David's work/help. I'll open source this 2nd compiler project in a couple months. This will really show the power of Clojure as David said.
- markokocic 15y agoNative Clojure in Clojure?
- jasonjackson 15y agoThe compiler is written in Clojure. It'll compile Java ~2.0 to native x86. I haven't decided what backend i'm using yet, or just output ASM.
- jared314 15y agoI wonder if a ClojureScript LLVM backend would work.
- swannodette 15y ago! Would love to find out :) It's a open goal to make ClojureScript pluggable.
- moomin 15y agoI think the biggest problem would be writing a garbage collector. It would be huge, though...
- snprbob86 15y agoI'm by no means a Lisper or "compiler guy", but I found the ClojureScript compiler to be extremely hackable. It looks like it would form an excellent basis for Clojure-in-Clojure, which would surely support additional pluggable backends. Seems like that is the plan.
- phren0logy 15y agoI would love to use clojure as a data analysis language. Although incanter is nice, it's slower than I would prefer. Perhaps being able to use a use a non-java linear algebra library would help? If so, this seems like a great first step.
- jasonjackson 15y agoI'm the author of this project. I think of this project as a technology demo. I wanted to how difficult it would be to write a minimalist compiler with LLVM -- it was pretty quick & easy. This is a great educational project as the code is short and to the point. For my parsing code: https://github.com/jasonjckn/llvm-clojure-bindings/blob/master/src/parser.clj https://github.com/jasonjckn/llvm-clojure-bindings/blob/mast... I'm using a combinator parser library. This code both parses and builds the AST in one pass. The AST unsurprisingly looks like LISP code, here's an example AST https://github.com/jasonjckn/llvm-clojure-bindings/blob/master/src/example_ast.clj https://github.com/jasonjckn/llvm-clojure-bindings/blob/mast... After that, all that's left is calling LLVM C API through JNA: https://github.com/jasonjckn/llvm-clojure-bindings/blob/master/src/ast.clj https://github.com/jasonjckn/llvm-clojure-bindings/blob/mast... One advantage of using LLVM is you can leverage the C Standard Library from your code. In the example program, I forward declare 'cos' and 'printf', and LLVM takes care of linking the functions. LLVM also supports JIT compilation, so you could do some really cool stuff. Stay tuned for the next compiler I'm working on which will compile the majority of Java 2.0 to x86.