Getting Scala compiler to work with .NET CLR

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting Scala compiler to work with .NET CLR

Niko Korhonen
I seem to be unable to compile the simplest Scala programs targeting the
.NET CLR. I'm running Windows XP with Scala 1.4.0.4 package.

I have copied mscorlib.dll from .NET CLR v1.1 to Scala's lib directory.
Here is the program I try to compile (it's the example from the Scala
homepage):

<code>
import System.Console;

object test with Application {
   Console.WriteLine("Hello world!");
}
</code>

I use the command line:

scalac -target:msil -r c:\tools\scala\lib CLRTest.scala

The result is:

<code>
c:\tools\Scala\bin\..\src\scala\Application.scala:41: value System is
not a memb er of java.lang
     val executionStart: Long = java.lang.System.currentTimeMillis();
                                         ^
c:\tools\Scala\bin\..\src\scala\Application.scala:46: value System is
not a memb er of java.lang
         if (java.lang.System.getProperty("scala.time") != null)
                      ^
c:\tools\Scala\bin\..\src\scala\Application.scala:47: value System is
not a memb er of java.lang
           java.lang.System.out.println("[total " +
                    ^
c:\tools\Scala\bin\..\src\scala\Application.scala:48: value System is
not a memb er of java.lang
                        (java.lang.System.currentTimeMillis()
                                  ^
four errors found
</code>

I don't think that I should be missing something crucial at my compile
procedure, but in case I am, please enlighten me :)

--
Niko Korhonen
Software engineer


Reply | Threaded
Open this post in threaded view
|

Re: Getting Scala compiler to work with .NET CLR

Nikolay Mihaylov
Hello

Scala 1.4 compiles mixed in classes from sources. Althought there is a
scala.Application class compiled in scala.dll it is of no use as a mixin
(in fact, it is totally useless because even extending it doesn't make
the object executable - Scala 1.4 only creates the appropriate static
method forwarders for methods declared in the object or mixed in). The
problem is that Scala only ships with the sources of the JVM version of
the library. As you can see, scala.Application contains references to
java.lang which does not exist on .NET. You can (1) modify
scala/Application.scala and remove all Java references, (2) write the
main function yourself

object Test {
  def main(args: Array[String]): Unit = {
     Console.WriteLine("Hello world!");
  }
}

or (3) install the J# redistributable package and include references to
vjscor.dll and vjslib.dll with the -r option.

I would do #2. In any case, I consider mixing in scala.Application as
bad style because it forces you to write your code as object-level
statements which are executed in the object constructor. Consequently,
the body of the mixed in main method gets executed only later thus
preventing you from passing any command-line arguments to your object-
level code. Also, all values and variables are effectively fields of the
object instead of local val/vars as one would expect if the same code
resides in the main method.

Hope that helps

Nikolay


On Tue, 2006-01-24 at 10:01 +0200, Niko Korhonen wrote:

> I seem to be unable to compile the simplest Scala programs targeting the
> .NET CLR. I'm running Windows XP with Scala 1.4.0.4 package.
>
> I have copied mscorlib.dll from .NET CLR v1.1 to Scala's lib directory.
> Here is the program I try to compile (it's the example from the Scala
> homepage):
>
> <code>
> import System.Console;
>
> object test with Application {
>    Console.WriteLine("Hello world!");
> }
> </code>
>
> I use the command line:
>
> scalac -target:msil -r c:\tools\scala\lib CLRTest.scala
>
> The result is:
>
> <code>
> c:\tools\Scala\bin\..\src\scala\Application.scala:41: value System is
> not a memb er of java.lang
>      val executionStart: Long = java.lang.System.currentTimeMillis();
>                                          ^
> c:\tools\Scala\bin\..\src\scala\Application.scala:46: value System is
> not a memb er of java.lang
>          if (java.lang.System.getProperty("scala.time") != null)
>                       ^
> c:\tools\Scala\bin\..\src\scala\Application.scala:47: value System is
> not a memb er of java.lang
>            java.lang.System.out.println("[total " +
>                     ^
> c:\tools\Scala\bin\..\src\scala\Application.scala:48: value System is
> not a memb er of java.lang
>                         (java.lang.System.currentTimeMillis()
>                                   ^
> four errors found
> </code>
>
> I don't think that I should be missing something crucial at my compile
> procedure, but in case I am, please enlighten me :)
>
> --
> Niko Korhonen
> Software engineer
>
>