Previous Contents Next


Creation of a Toplevel and Standalone Executable

Consider again the Basic interpreter. Modify it to make a new toplevel.
  1. Split the Basic application into 4 files, each with the extension .ml. The files will be organized like this: abstract syntax (, printing (, parsing ( and evaluation of instructions ( The head of each file should contain the open statements to load the modules required for compilation.

  2. Compile all files separately.

  3. Add a file which contains only the statement for calling the main function.

  4. Create a new toplevel with the name topbasic, which starts the Basic interpreter.

  5. Create a standalone executable which runs the Basic interpreter.

Comparison of Performance

Try to compare the performance of code produced by the bytecode compiler and by the native compiler. For this purpose, write an application for sorting lists and arrays.
  1. Write a polymorphic function for sorting lists. The order relation should be passed as an argument to the sort function. The sort algorithm can be selected by the reader. For example: bubble sort, or quick sort. Write this function as

  2. Create the main function in the file, which uses the previous function and applies it to a list of integers by sorting it in increasing order, then in decreasing order.

  3. Create two standalone executables - one with the bytecode compiler, and another with the native compiler. Measure the execution time of these two programs. Choose lists of sufficient size to get a good idea of the time differences.

  4. Rewrite the sort program for arrays. Continue using an order function as argument. Perform the test on arrays filled in the same manner as for the lists.

  5. What can we say about the results of these tests?

Previous Contents Next