/clojurescript

Clojure to JS compiler (patched to allow compiling of compiler to ClojureScript)

Primary LanguageClojure

ClojureScript Compiler Compiled with ClojureScript?

This is a patched version of the ClojureScript compiler that compiles to ClojureScript. Normally, the ClojureScript compiler is a pure Clojure program that runs on the JVM. This patched version runs from the compiled JavaScript. This project was kicked off by kanaka and chouser during some intense hacking at Clojure/conj 2012. Kanaka continues to develop the fork towards the goal of being fully self-hosting (i.e. ClojureScript-in-ClojureScript).

Why?

  • Why not?
  • Compilers are only cool once they are self-hosting (can compile their own code). This fork is not self-hosting yet, but that is the goal.
  • You can use ClojureScript without a JVM.
  • You can have a ClojureScript REPL web app that runs locally in your browser (no server involved after loading the page).

Current Caveats

  • JavaScript output is not optimized by the Google Closure Compiler (which is a Java program).
  • The code changes are not all compatible with the normal Clojure ClojureScript (JVM based) compiler. To make it compatible we really need Feature Expressions in Clojure
  • The :nodejs compilation target is currently broken. However, the node/run.js bootstrap script enables compiled CLJS code to be invoked that was not compiled with a :target.
  • Other miscellaneous broken things that have not been tracked down yet.

Bugs

  • namespaced keywords are broken
  • numeric keywords are broken
  • no division ("/" symbol in general is problematic)
  • use of certain regexex causes hard hangs
  • escaping in regexes is broken
  • anonymous functions do not warn about arity
  • non-unicode symbol breakage
  • warnings during compile about unchecked-if

TODOs

  • update to upstream ClojureScript
  • file I/O (at least on the node.js side)
  • misc functionality: require/use, var metadata, defn-, defonce
  • self-hosting (compile ClojureScript compiler using node.js hosted ClojureScript compiler)
  • optional optimizations (single JS file output, etc)

Build

You can build the ClojureScript analyzer and compiler with ClojureScript like this:

bin/cljsc src/cljs/cljs/compiler.cljs > compiler.cljs

However, that is not all that useful because it does not have all the pieces necessary to run it under a JavaScript engine (e.g. browser or node.js).

You can rebuild the ClojureScript analyzer, compiler, reader and browser/node.js bootstrap pieces with a web REPL like this:

cd web
../bin/cljsc ../src/cljs/webrepl.cljs > webrepl.js

Now load the web/jsrepl.html file in a browser.

For a REPL in nodejs, build the src/cljs/noderepl.cljs code:

cd node
../bin/cljsc ../src/cljs/noderepl.cljs > noderepl.js
cp ../src/cljs/goog.js out/

Now use the run.js bootstrap code to launch the repl:

./run.js noderepl.js

For direct *.cljs file compilation/evaluation, build the nodecljs.cljs compiler:

cd node
../bin/cljsc ../src/cljs/nodecljs.cljs > nodecljs.js
cp ../src/cljs/goog.js out/

You can now use a combination of the run.js bootstrap code and nodecljs.js to compile/evaluate the hello.cljs file:

./run.js nodecljs.js hello.cljs

What is ClojureScript?

ClojureScript is a new compiler for Clojure that targets JavaScript. It is designed to emit JavaScript code which is compatible with the advanced compilation mode of the Google Closure optimizing compiler.

Getting Started

Questions, Feedback?

Please point all of your questions and feedback here.

Developers Welcome

ClojureScript operates under the same license as Clojure. All contributors must have a signed CA (Contributor's Agreement) and submit their patch via the appropriate channels. If you're interested in contributing to the project, please see the contributing page on clojure.org.

License

Copyright (c) Rich Hickey. All rights reserved. The use and
distribution terms for this software are covered by the Eclipse
Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
which can be found in the file epl-v10.html at the root of this
distribution. By using this software in any fashion, you are
agreeing to be bound by the terms of this license. You must
not remove this notice, or any other, from this software.