Wednesday, June 2, 2010

Scala tokenizer

Today I found out that scala compiler allows to print stats about tokens used in code with command line tokenizer. To use it from eclipse:
  1. create debug configuration and point Main class to scala.tools.cmd.program.Tokens
  2. on program arguments set HelloWorld.scala --verbose –freq
  3. add standard scala classpath for scala debuging you can find it: here
On the output you will see tokens stats like below:
Tokenizing: HelloWorld.scala
2 '}'
2 '{'
1 '['
1 '='
1 args
1 main
1 ':'
1 'def'
1 'object'
1 '('
1 ']'
1 Hello
1 String
1 Array
1 ')'
Rather simple but sometimes useful.

Tuesday, May 25, 2010

Mini how-to for building Scala from SVN

Steps to setup development environment for Scala compiler with Eclipse Scala plug-in:
  1. Install JDK 1.6.0 or above (e.g. Sun JDK 6.0 version 1.6.0_19):
    • JDK is available on http://java.sun.com/.
    • Remember to set the JAVA_HOME environment variable after installation.
    • (Optional) Add JAVA_HOME/bin to PATH for executing Java commands.
  2. If you want to use Eclipse then install Eclipse 3.5 or above (e.g. Eclipse 3.5.2): 
  3. Install Scala plug-in for Eclipse
  4. Extract Scala source, either:
    • If using Eclipse:
      • Decide where your workspace is (will be reference later), switch to the SVN perspective. If you are not familiar with Eclipse, in menu Help -> Welcome may help you a lot.
      • Browse SVN to know SVN information.
      • Create a new repository, extract scala source
    • If not using Eclipse then from command line: svn co http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk scala
  5. Build Scala compiler source
    • If you want to build from the command line with ANT check link: http://www.scala-lang.org/node/217
    • For Eclipse:
      • Open in any text editor file .classpath from root folder and add after tag <classpath>
      <classpathentry kind="con" path="ch.epfl.lamp.sdt.launching.SCALA_CONTAINER"/>
      • Close File
      • Import src catalog to eclipse workspace
      • Right click on build.xml and select Run As -> Ant Build optionally you can just use shortcut Alt+Shift+X,Q
  6. Debug Compiler
    • Add new deconfiguration by click on and selecting from menu Debug Configuration…
    • Add new item under Scala Application
    • create HelloWorld.scala file under root folder and paste sample Scala code
    • under Main tab set Main class to: scala.tools.nsc.Main
    • under Arguments tab (Remember to replace {PathToSrc} with path to Scala src) set
      • Program arguments: HelloWorld.scala -target:jvm-1.5 -d bin
      • VM arguments: -Xbootclasspath/a:{PathToSrc}\build\pack\lib\scala-compiler.jar;{PathToSrc}\build\pack\lib\scala-library.jar;{PathToSrc}\build\pack\lib\fjbg.jar;{PathToSrc}\build\pack\lib\msil.jar;{PathToSrc}\lib\original_msil.jar
  7. Done!
In case of any problems please let me know.

Thursday, May 6, 2010

Warm up: mini-project with Scala

During next few days I am going to start implementing enhancement Optimize simple for loops.  During this warm up project I would like to gain more practice with Scala.Net which can be later useful with main GSoC project.

This project was suggested to me by Miguel because it is almost self-contained and also important to the community.

I will keep you informed about progress :).

Initial Schedule

I would like to share with you my initial schedule from project proposal. It is not yet finished but I will be later modifying it to express changes. As you can see I have some time reserved for changes on further point of schedule.
March 30. I have already started gathering information on how I can approach this idea:
  • Downloaded sources from Scala SVN repository
  • Finished environment setup
  • Debugged the NSC parser and GenMSIL.scala with simple Scala program and ran it as .Net program.
  • Wrote a simple plugin for NSC following with a tutorial on webpage
  • Reading “Programming in Scala” by Martin Odersky, Lex Spoon, and Bill Venners
April 26. I am fully aware of time limitations - 3 months it is not a long time for completing such GSoC project. For this reason, I am planning to start as soon as possible especially during community-bonding-period. During this time, my aim is to revise my approach of implementation and prepare proof-of-concept prototype, which can later be improved or changed during actual GSoC timeline. In the meantime, I would like to review some of LINQ implementation attempts for .Net, as well as for Java. Also my aim is to get better knowledge in backend of LINQ in .Net such as Expression Trees and SQO and how they look from parser side on C# ANTLR parser another good source to find more answers will be Object-oriented LINQ for Scala.

During this time I am also planning to finish some mini projects to better understand Scala compiler. I will post more information about this projects during next few days.

May 24. During this week I will have discussed with a mentor chosen way to go with prototype basic LINQ queries this means in C# transformed to invocations on IEnumerable. This should be finished within max 2 weeks and parser should allows to parse basic LINQ expressions.

May 31. I will finish several of SQO such as where, order by and move forward joins, grouping/aggregation/partitioning.

June 7. On this week I will start implementing test for LINQ in Scala based on compiler tests for LINQ from Mono mcs (gtest-linq*, gtest-etree*). After this date I should have list of required tests post on blog. Later with introducing some new functionality I will always introduce corresponding before that bunch of unit-tests to fallow rules from TDD.

June 14. I will start implementing Expression Trees this should takes 2 up to 3 weeks of full work.

June 21. Here I should have fallowing expressions class parameter/binary/constatnt and also mathemathical expressions e.g. subtract.

June 28. On this week Expression Trees should be finished and building advanced queries with lambda expressions pares by Scala compiler should be possible.

July 5. Final polishing prototype and fixing bugs before midterm evaluation.

July 12 midterm evaluation. Due this date I should have a working prototype with all requirements fulfilled. I should be possible to input any type of LINQ queries and they should be translated into corresponding Scala Structure or newly implemented Expression Trees.

July 16 19:00 UTC midterm evaluation deadline.

July 19. Start creating project documentation during free time. Also after first evaluation I would like to start filling gaps in prototype to make it fully functional.

July 26. On this week I should have discussed with mentor possible problems and solutions to nail it before the deadlines.

August 2. Finishing documentation and fixing left bugs. After this date no new features should be added.

August 9. Suggested 'pencils down' date. From this point I am planning to polish the project documentation and improve comments in code structure. It will also be the time to prepare first compiler release e with LINQ-awareness.

August 16. Prior to this time, both the project code and documentation should be submitted to SVN without any exceptions on separate branch.

August 20.Final evaluation.

August 30. Deadline for code submission to Google.

Tuesday, May 4, 2010

Good News: GSoC 2010 with Scala.Net

My application "Adding LINQ-awareness to Scala.Net" to Google Summer of Code 2010 was accepted thanks for countless help to Miguel Garcia.

Project aim is to add support for LINQ to Scala.Net compiler. To provide this feature to Scala.Net requires modification in parser and adding transformation to verify SQO expressions for data sources which type enables to indicate support for this capability. Once the proposed extension has been implemented, making use of it requires no additional expertise beyond familiarity with the same .NET tools for LINQ.The idea was proposed by Miguel Garcia on Scala Compiler Corner.

Few words about the program: "Google Summer of Code (GSoC) is a global program that offers student developers stipends to write code for various open source software projects."
Linkt to site: http://socghop.appspot.com/

During next few months on this blog I will be posting progress of this project so stay tuned.