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 v2.6.1, a recent version of gcc and Gnu make.

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 compiler, you will now add two constructs to the language: the logical and and the logical or.

The version of predefined.scm that you received contains definitions for two functions called and and or. While these functions do what they are supposed to do, they are not short-cutting. That is, their second argument is always evaluated, even when this is unnecessary.

The easiest way to ensure that these logical constructs are short-cutting is to treat them as syntactic sugar for if expressions. For example, here is the equivalence for and:

        (and e1 e2) = (if e1 e2 0)
      

Modify the compiler so that it performs these transformations, and then remove the definitions in predefined.scm. Then, write a test program that exhibits the short-cutting behaviour of these operators, and check that it works as expected, both with the interpreter and the virtual machine.

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.