This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Compiling Scala to JavaScript

2 replies
Alex _
Joined: 2011-07-29,
User offline. Last seen 42 years 45 weeks ago.
Hey... I know this has been hashed out various times in the past, but I thought we could hash it out again for old times sake.
The advent of CoffeeScript and now ClojureScript has got me lusting after another more powerful way of saying JavaScript. Although these two are nice, all I really want from a language is delimited continuations and it kills me that I can't have them where I need them most - in Interface Land. The Scala implementation of continuations seems pretty much perfect for JavaScript (as recursive functions), so I'm looking to Scala for a solution.
There have been several attempts in the past which have fallen by the wayside, including a comment some time ago by Martin Odersky suggesting the only feasible route would be to decompile Java bytecode...
I am wondering how practical a JavaScript emitter would be for the current version of Scala. Has anything changed to make this more feasible? Are there any projects I have missed that are have the potential to produce performant code? And would integrating with Google Closure (as with ClosureScript) be the right path to take?
Alex _
Joined: 2011-07-29,
User offline. Last seen 42 years 45 weeks ago.
Re: Compiling Scala to JavaScript

By the way, I know that continuations in Scala are implemented via
selective CPS, I just had the image of shift inside a loop in my mind,
hence 'recursive functions'.

Cheers... Alex =)

On Jul 29, 9:00 pm, Alex _ wrote:
> Hey... I know this has been hashed out various times in the past, but I
> thought we could hash it out again for old times sake.
>
> The advent of CoffeeScript and now ClojureScript has got me lusting after
> another more powerful way of saying JavaScript. Although these two are nice,
> all I really want from a language is delimited continuations and it kills me
> that I can't have them where I need them most - in Interface Land. The Scala
> implementation of continuations seems pretty much perfect for JavaScript (as
> recursive functions), so I'm looking to Scala for a solution.
>
> There have been several attempts in the past which have fallen by the
> wayside, including a comment some time ago by Martin Odersky suggesting the
> only feasible route would be to decompile Java bytecode...
>
> I am wondering how practical a JavaScript emitter would be for the current
> version of Scala. Has anything changed to make this more feasible? Are there
> any projects I have missed that are have the potential to produce performant
> code? And would integrating with Google Closure (as with ClosureScript) be
> the right path to take?

gkossakowski
Joined: 2010-03-11,
User offline. Last seen 33 weeks 5 days ago.
Re: Compiling Scala to JavaScript
On 29 July 2011 14:00, Alex _ <alex [dot] k [dot] goldsmith [at] gmail [dot] com> wrote:
Hey... I know this has been hashed out various times in the past, but I thought we could hash it out again for old times sake.
The advent of CoffeeScript and now ClojureScript has got me lusting after another more powerful way of saying JavaScript. Although these two are nice, all I really want from a language is delimited continuations and it kills me that I can't have them where I need them most - in Interface Land. The Scala implementation of continuations seems pretty much perfect for JavaScript (as recursive functions), so I'm looking to Scala for a solution.
There have been several attempts in the past which have fallen by the wayside, including a comment some time ago by Martin Odersky suggesting the only feasible route would be to decompile Java bytecode...
I am wondering how practical a JavaScript emitter would be for the current version of Scala. Has anything changed to make this more feasible? Are there any projects I have missed that are have the potential to produce performant code? And would integrating with Google Closure (as with ClosureScript) be the right path to take?

One of the challenges of compiling Scala to JavaScript is answering the question: what to do with dependencies on Java's standard library. Everything in Scala's library depends on it either directly or transitively.
One way to tackle this problem is being pursued here: http://scalagwt.github.com/
Our homepage is a bit outdated (we're busy with hacking good stuff) so I'll give a few comments. Couple of days ago we hit a major milestone and compiled 4k+ of Scala code to Javascript using Scala+GWT project, see http://goo.gl/lGAW7 (check "Source code" tab on each screen). Also, Aaron Novstrup managed to get continuations working in our setting, see:
https://groups.google.com/d/topic/scalagwt/muY3Go9oqpo/discussionhttps://groups.google.com/d/msg/scalagwt/Y0jMldD4suw/5moOsNSQg_IJ
and probably some others. Search for "continuations" on scalagwt group to see more discussions around this topic.

--
Grzegorz Kossakowski

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland