Re: Re: Questions about JVM to Scala.js IR compiler (GSOC project)

Sébastien Doeraene <[email protected]> Wed, 2 Mar 2016 09:54:10 +0100
Newsgroups gmane.comp.lang.scala
Message-ID <CAJwkOg6ZBE9WsWb6pLzFL=vqmeXj3UV0LTcQw9KXjYGccUUfnQ@mail.gmail.com>
Hi,

1)
> This means the GSOC project should parse the JVM code and generate the IR
AST: then it can use the printers and serializers already existing.

You are correct. You basically need to build an ir.Trees.ClassDef. From
there, you can generate the .sjsir file very easily as done at
https://github.com/scala-js/scala-js/blob/v0.6.7/compiler/src/main/scala/org/scalajs/core/compiler/GenJSFiles.scala#L28-L34
No need to reimplement serialization or printing yourself, obviously.

> Obviously the “generate” phase is not this straightforward because it
seems to me that the IR is much more “high level” than the JVM bytecode.

Yes, that is one of the reasons I expect going from source code/typed AST
would be easier. But they are techniques to do it. Everything but loop
recovery is *relatively* simple. It's mostly turning the stack-based model
of the bytecode into the expression-based model of the IR, but that's not
so terrible. Loop recovery is harder.

2) The "back-end", which is the Linker/Optimizer/Emitter to JS, does not
need .class files, indeed. It only uses .sjsir files it finds on the
classpath. .class files are useful for separate compilation, IDEs, sbt's
incremental compilation, and so on.

3) On loop recovery:
http://stackoverflow.com/questions/6792305/identify-loops-in-java-byte-code
seems to be a nice introduction.

Cheers,
Sébastien

On Wed, Mar 2, 2016 at 8:55 AM, Andrea Francesco Iuorio <
[email protected]> wrote:

> Hi, in the last few days I played a little with Scala.js building it and
> understanding the IR format and compilation. I've some new questions:
>
> 1) Am I correct to assume that the .sjsir file is structured with an
> "header" (containing things like the Scala.js version ecc. ecc.) and the
> serialization of the IR AST ? This means the GSOC project should parse the
> JVM code and generate the IR AST: then it can use the printers and
> serializers already existing. Obviously the “generate” phase is not this
> straightforward because it seems to me that the IR is much more “high
> level” than the JVM bytecode.
> 2) I don't really understand why the JS backend needs the .class files. At
> this phase I thought we don't have any dependency to the compiled Scala
> code and, while exploring a .sjsir file with scalajsp, it seems to me that
> all the necessary informations are already present.
> 3) Any suggestions about anything that I should look at ?
>
> Il giorno lunedì 22 febbraio 2016 19:43:29 UTC+1, Andrea Francesco Iuorio
> ha scritto:
>>
>> Hi, I'm currently a MSc student in Computer Science. I would like to try
>> to submit a proposal for this year's GSOC under Scala, more precisely for
>> the JVM -> Scala IR Compiler (for my BSc. thesis I had to develop a JVM
>> compiler for a toy language, so I kinda know the JVM bytecode), however I
>> have some questions:
>>
>> 1) Do you require, as an organization, any prerequisite for apply ?
>> 2) If I understand correctly, the purpose of the project is writing a
>> compiler in Scala that compile JVM bytecode (or, maybe better, a .class
>> file ?) into Scala.js IR. Correct or there is something that I've missed ?
>> 3) There is some kind of documentation about the IR that I can read for
>> getting an idea about its complexity ?
>>
> --
> You received this message because you are subscribed to the Google Groups
> "scala-language" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.