CS 453 Programming Assignment #2 — MeggyJava and AVR warmup

Due Wednesday February 16th (by 11:59pm)

Introduction

In this assignment you will be writing some medium-sized MeggyJava programs for PA3, PA4, PA5, and PA6. Additionally you will be writing C++ versions of some small examples so you can inspect the AVR assembly code generated by avr-g++ and test the small examples on the Meggy Jr device itself. To read the details about the various assembly instructions see the documentation about the AVR 8-bit Instruction Set Architecture (AVR Assembly Language). The goal of this project is to introduce you to the source and target languages for the MeggyJava compiler that you will be writing for PA3 through PA7.

The Assignment

MeggyJava programs

Implement the PA3Picture.java, PA4Cylon.java, PA5Cylon.java, and PA6Cylon.java in MeggyJava. You can debug the programs by compiling and running them with javac and java and inspecting the text output messages. Additional information about using the meggy.Meggy class for testing in Java-only mode was covered in class February 8th and 10th.

When writing the MeggyJava programs make sure to only use Java language features that are in the MeggyJava grammar for the target programming assignment. You can test this by grabbing a copy of the MJ_PA3.jar, MJ_PA4.jar, MJ_PA5.jar, or MJ_PA6.jar from ~cs453/public and executing the following:
    % cp ~cs453/public/MJ_PA#.jar
    % java -jar MJ_PA#.jar Program.java
The MJ reference compilers generate a bunch of files (Program.java.*). Check them out if you would like, but they are not relevant to this assignment. If the reference compiler for the associated assignment does not parse or type check your program then your program is wrong and needs to be fixed. For example, MJ_PA5.jar should be able to parse PA5Cylon.java. If you run into problems, look at the Meggy Java grammars and determine whether the program you wrote can be generated by the appropriate grammar.

For the Cylon programs, you need to match the following Cylon.out or Cylon-v2.outgiven the following arg_opts file. The PA6Cylon does not require getPixel() calls so it will be different by 2 lines in the output trace.

AVR-G++ versions of MeggyJava programs

The medium-sized MeggyJava programs you are writing in the first part of the assignment probably won't be runnable on your device until you have implemented the corresponding version of your MeggyJava compiler. To start playing with the Meggy Jr device right away and to start learning about the assembly language, this second part of the assignment has you write the AVR-G++ versions of some smaller MeggyJava examples, create the hex files from those AVR-G++ programs with the build process provided, and install those hex files onto your device to demonstrate they work.

The MeggyJava programs that you need to write AVR-G++ versions can be found in ~cs453/public/MJExamples/ with some other examples. The specific list you will be translating to C++ is as follows:

Note that an example AVR-G++ file is provided for PA7rainbow.java called PA7rainbow.cpp. Having all of these smaller examples available should help with the first part of the assignment.

For this part of the assignment, you will need to read the Meggy Jr programming guide. In this class we are using the MeggyJr Simple library, which is defined in the MeggyJrSimple.h and MeggyJrSimple.cpp files provided on the build process page.

Getting Started

Start working on the assignment right away even though partners will not be specified until February 7th. Send your prioritized list of possible partners by Friday, February 4th at 5pm.

First download the Meggy.java, MeggyException.java, and arg_opts files and place them in a subdirectory called meggy/. Then copy some of the examples from ~cs453/public/MJExamples/ into the directory that contains the meggy/ subdirectory and run them by typing the following:

    javac ExampleName.java
    java ExampleName
NOTE that most of the MeggyJava programs contain infinite loops. The run-time library implemented in Meggy.java reads in an arg_opts file with information about how many Meggy methods to execute before exiting the program. It is also possible to specify what buttons are to be considered down between delay() calls so as to test user input in the Java-only version.

Submitting the Assignment

Late Policy

Late assignments will be accepted up to 48 hours past the due date for a 10% deduction. The assignment will not be accepted past this period. Late means anything after 11:59pm on the day the assignment is due, including 12 midnight.


mstrout@cs.colostate.edu .... February 13, 2011