Assignment 1: Getting started
Due: Thursday, June 4, 11:59PM
Starter code: blackmail-plus.zip
The goal of this assignment is to extend the language developed in Blackmail: incrementing and decrementing with another simple unary numeric operation. This is a conceptually straightforward assignment, designed primarily to make you familiar with the structure of the Blackmail language implementation and the tools we will be using for the remainder of the course. It should not take long to complete, but may involve working out some set-up issues.
Blackmail+
The Blackmail+ language extends Blackmail in the following ways:
adding a new primitive operation add2.
Note: typically all of our languages are subsets of Racket, but this is one of the exceptions since Racket doesn’t actually have a built-in add2 function.
Primitives
The following new primitive is included in Blackmail+:
(add2 e): add 2 to the value of e.
Implementing Blackmail+
You must extend the interpreter and compiler to implement Blackmail+. (The parser for Blackmail+ is given to you.) Use the starter code in blackmail-plus.zip, which is based on the Blackmail: incrementing and decrementing language we studied in class.
You may use any a86 instructions you’d like, however it is possible to complete the assignment using just Add.
Parsing Blackmail+
The AST type and parser for Blackmail+ are given to you.
Here’s the AST definition for the added primitive:
; type Expr = ; ... ; type Op = ; ... ; | 'add2
There are no new kinds of expression constructors, but there is a new Op construtor: 'add2.
Here are some examples of how concrete expressions are parsed into ASTs using this representation:
(add2 1) parses as (Prim1 'add2 (Lit 1)),
(add2 (add2 1)) parses as (Prim1 'add2 (Prim1 'add2 (Lit 1))),
(add2 (add1 1)) parses as (Prim1 'add2 (Prim1 'add1 (Lit 1))).
Steps toward Blackmail+
Implement the new forms as described earlier, both for the interpreter and compiler.
To do this, you should:
Study syntax/ast.rkt to understand how these new forms of expression are represented.
Add test cases to test/define-tests.rkt. These will be tested with both the interpreter and compiler.
Update interpreter/interp-prim.rkt to correctly interpret the new primitives. (You don’t need to update interpreter/interp.rkt, but it would be a good idea to familiarize yourself with this file.)
Test your interpreter with raco test test/run-interp-tests.rkt.
Make examples of the new primitive expressions and potential translations of them to assembly.
Update compiler/compile-ops.rkt to correctly compile these expressions based on your examples. (You don’t need to update compiler/compile.rkt, but again, it would be good to study this file.)
Test your compiler with raco test test/run-compile-tests.rkt.
Submitting
To submit, use make from within the blackmail-plus directory to create a zip file containing your work and submit it to Gradescope.