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

Calling Scala compiler in memory without a file system

3 replies
dvydra
Joined: 2009-05-10,
User offline. Last seen 42 years 45 weeks ago.

Is it possible to call the Scala compiler programmatically and get back
bytecodes all in memory without writing to the filesystem?

Thanks
David

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Calling Scala compiler in memory without a file system

On Sat, May 09, 2009 at 04:29:34PM -0700, dvydra wrote:
> Is it possible to call the Scala compiler programmatically and get
> back bytecodes all in memory without writing to the filesystem?

Look at what the interpreter does:

val virtualDirectory = new VirtualDirectory("(memory)", None)
[...]
val comp = new nsc.Global(settings, reporter)
comp.genJVM.outputDir = virtualDirectory

dvydra
Joined: 2009-05-10,
User offline. Last seen 42 years 45 weeks ago.
Re: Calling Scala compiler in memory without a file system

Thanks! Thats what I was looking for. I'll give it a shot, but if anyone has
a working example they can share that would help.
-d

Paul Phillips wrote:
>
> On Sat, May 09, 2009 at 04:29:34PM -0700, dvydra wrote:
>> Is it possible to call the Scala compiler programmatically and get
>> back bytecodes all in memory without writing to the filesystem?
>
> Look at what the interpreter does:
>
> val virtualDirectory = new VirtualDirectory("(memory)", None)
> [...]
> val comp = new nsc.Global(settings, reporter)
> comp.genJVM.outputDir = virtualDirectory
>

dvydra
Joined: 2009-05-10,
User offline. Last seen 42 years 45 weeks ago.
Re: Calling Scala compiler in memory without a file system

I've made some progress, but for some reason my virtualDirectory is empty. I
checked in code here: http://github.com/vydra/gae-scala/tree/master You can
run the tests with ant test after setting up the appropriate env vars.

When running in verbose mode the compiler seems to write into the right
place, so I am confused.

Thanks
David

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