|[ANN] clojure-scheme - Compiling Clojure to Scheme to C||Nathan Sorenson||3/14/12 2:08 PM|
I've modified the output of the ClojureScript compiler to emit Scheme code. At this point the core library is successfully compiled by Gambit Scheme. A nice advantage of this is that Gambit compiles code via C, meaning that stand-alone Clojure executables are now available for any platform with a suitable gcc compiler!
Gambit, notably, also compiles to iOS. Just recently I've confirmed that Clojure's core library runs on the iPad simulator.
There is a ton of yak-shaving required at this point---compilation consists of a combination of shell commands, Clojure-interpreted commands and Gambit-interpreted commands. Hopefully this will soon be streamlined.
|Re: [ANN] clojure-scheme - Compiling Clojure to Scheme to C||David Nolen||3/14/12 2:08 PM|
|Re: [ANN] clojure-scheme - Compiling Clojure to Scheme to C||Herwig Hochleitner||3/14/12 6:04 PM|
|Re: [ANN] clojure-scheme - Compiling Clojure to Scheme to C||Chip Collier||3/14/12 3:53 PM|
Holy excellent development Batman!
|Re: [ANN] clojure-scheme - Compiling Clojure to Scheme to C||Ambrose Bonnaire-Sergeant||3/15/12 7:13 PM|
Wow, nice work Nathan!
|Re: clojure-scheme - Compiling Clojure to Scheme to C||Paulo Pinto||3/18/12 5:28 AM|
Just a question, why Clojure->Scheme->C, instead of Clojure->Clozure?
That way there would no be any C compiler dependency.
|Re: clojure-scheme - Compiling Clojure to Scheme to C||Nathan Sorenson||3/21/12 12:46 AM|
I see the C code generation as an advantage, in that it becomes possible to target any platform with a C compiler.
Can Clozure compile to iOS?
|Re: clojure-scheme - Compiling Clojure to Scheme to C||Patrick Logan||3/22/12 2:19 PM|
Gambit Scheme especially has a great interface to C/C++/Objective-C. I've been happily using Gambit quite a bit for 20+ years, when it originated as gambit-68k for the Motorola 68000.
Gambit-C's been ported to iOS, Nintendo DS, etc.
In addition to the great C interface, it also has a great Unix/Posix interface, a great threads and message passing library (in the neighborhood of Erlang's performance for numbers of threads and messages per second), etc. It comes with Termite which is an Erlang-like programming model with mobile continuations.
So porting to Gambit provides some good avenues to explore.
|Re: clojure-scheme - Compiling Clojure to Scheme to C||Devin Walters (devn)||3/26/12 2:19 PM|
I've been itching to try this out. I pulled down the repo, grabbed gambit-scheme, and started to look around, but I'm a little lost as to how I can get it working. Could you provide the magic required to make one pass from cljs to scm to c? I would be happy to contribute to the project, but I'm in need of a bit of hand-holding to get started.
Thanks in advance,
|Re: clojure-scheme - Compiling Clojure to Scheme to C||Nathan Sorenson||3/27/12 11:41 PM|
ClojureScript has plenty of sharp edges, and this project is a bit rougher than even ClojureScript at the moment so you'll have to pardon the mess.
The magic happens in the cljs.compiler namespace. Load up a clojure repl and do something along the lines of:
(do (require 'cljs.compiler) (require 'cljs.core) (in-ns 'cljs.compiler) )
after that, you'll be able to compile .cljs files to .scm files via (compile-file "/Users/nathansorenson/src/c-clojure/src/cljs/cljs/core.cljs")
Note how I'm having to be real obvious about the filename right now. You should get an .scm file in the same directory. At that point you can compile it to an .o file with gambit, or just load it in the interpreter to play with
gsc-repl> (load "core.scm" ;interpreted
$ gsc core.scm ;outputs core.o
gsc-repl> (load "core") ; loads the compiled .o