Introduction

The goal of this first assignment is to familiarise yourself with the minischeme language and its implementation. To start, download the minischeme.zip archive and uncompress it in your working directory. Then, run make to build the compiler, interpreter and virtual machine. Notice that this requires Scala 2.7.3, a recent version of gcc and Gnu make.

If you are working on a station in INF 1, a recent Scala distribution is available in the directory /home/iclamp/soft/share/scala. Set up your environment as follows:

        export SCALA_HOME=/home/iclamp/soft/share/scala
        export PATH=$SCALA_HOME/bin:$PATH

Part 1: the tool chain

The minischeme tool chain is composed of three tools: an interpreter for the minischeme language (msi), a compiler (msc) that produces code for the minivm virtual machine, and the virtual machine itself (vm). To get familiar with these tools, you will first write and run a simple "hello, world" program. In minischeme, this program looks as follows:

        (print-string "hello, world")
        (newline)
      

As you know, minischeme is equipped with a set of primitives. However, neither print-string nor newline are primitives. Instead, they are defined in the file libraries/predefined.scm. This file contains a set of predefined functions and values, and as such, it is meant to be included in all projects.

To test your "hello, world" program, save it in a file called hello.scm. Then, execute it using the interpreter, as follows:

        bin/msi libraries/predefined.scm hello.scm
      

If you get the expected output, the next step is to try with the compiler and virtual machine. For this, first compile your program as follows:

        bin/msc libraries/predefined.scm hello.scm -o hello.asm
      

Then, run the virtual machine on the resulting assembly file:

        bin/vm hello.asm
      

Part 2: the minischeme language

The file predefined.scm that you received is unfortunately incomplete: two important functions, print-int and read-int are missing. To familiarise yourself with the minischeme language, your next goal is to write them. Of course, they should be expressed in terms of the two primitives print-char and read-char. Make sure that they can handle negative integers too!

Once you have added these two functions to predefined.scm, write a small test program that reads two integers and displays the first elevated to the power of the second. You can assume that the exponent is not negative.

Part 3: the minischeme compiler

In order to familiarise yourself with the minischeme compiler, take a deep look at its sources. You can go through the code manually, alternatively you can also use the debugger of the Scala eclipse plugin.

Reading the source manually

The source files are located in the directory compiler/minischeme. The Scala distribution provides syntax highlighting plugins for most popular text editors, have a look at the directory misc/scala-tool-support of your scala installation.

Installing eclipse

If you are working on one of the stations in INF 1, a recent version of eclipse with the Scala plugin 2.7.3 is available at the following location:

        /home/iclamp/soft/share/eclipse/eclipse

Do not use the version of eclipse which is available in the PATH, this version is not up to date and does not have the Scala plugin installed.


If you prefer working on your laptop, download eclipse classic 3.4 and install the Scala plugin using the update site:

        http://www.scala-lang.org/scala-eclipse-plugin

Using the eclipse debugger

The follwing steps will create an eclipse project for the minischeme compiler:

  1. Start eclipse, chose any workspace you like (existing or empty). Its location does not matter.
  2. Chose "File" - "New" - "Other", select "Scala Project" in the folder "Scala Wizards"
  3. Enter "minischeme" as project name, and chose as location the folder "minischeme" which was created before by unpacking the zip file
  4. To run the interpreter on hello.scm, create a new run configuration ("Run" - "Run Configurations...") with Main class minischeme.MainInterpreter, add the files libraries/predefined.scm and hello.scm as Arguments to the configuration.

You can then run the same configuration in the debugger. For instance, add a breakpoint in line 98 of Interpreter.scala to break the execution when interpreting a function application.

Tips and tricks

We urge you to use a good version control system to store your code, even when working alone. Moreover, we recommend using a system that is distributed, as this avoids the need for a centralised, always-reachable server. The most popular these days seem to be mercurial and git. Our personal favourite is darcs. Subversion is also popular, but centralised, and we therefore do not recommend it.