Skip to content
Merged

Next #171

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion www/assignments.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@include-section{assignments/1.scrbl}
@include-section{assignments/2.scrbl}
@;include-section{assignments/3.scrbl}
@include-section{assignments/3.scrbl}
@;include-section{assignments/4.scrbl}
@;include-section{assignments/5.scrbl}
@;include-section{assignments/6.scrbl}
Expand Down
203 changes: 96 additions & 107 deletions www/assignments/3.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -5,78 +5,54 @@
@(require "../../langs/con-plus/semantics.rkt")
@(require redex/pict)

@bold{Due: @elem[#:style "strike"]{Friday, September 29, 11:59PM}
Monday, October 2, 11:59PM}
@bold{Part 1 Due: Wednesday, February 21, 11:59PM}

The goal of this assignment is to extend the parser, interpreter, and
compiler with some simple unary numeric and boolean operations and two
forms of control flow expressions: @racket[cond]-expressions and
@racket[case]-expressions.
@bold{Part 2 Due: Wednesday, February 28, 11:59PM}


You are given a file @tt{dupe-plus.zip} on ELMS with a starter
compiler based on the @secref{Dupe} language we studied in class.
The goal of this assignment is to extend the language developed in
@secref{Dupe} with some simple unary numeric and boolean operations
and two forms of control flow expressions: @racket[cond]-expressions
and @racket[case]-expressions.

This assignment consists of two parts. Part 1 asks you to write a
number of programs in the extended language. Part 2 asks you to
implement the language.

You are tasked with extending the language in a number of
ways:
@section[#:tag-prefix "a3-" #:style 'unnumbered]{Part 1}

For this part of the assignment, you must write a number of programs
in the Dupe+ language. These programs should be syntactically
well-formed and @bold{produce a value} when evaluated, i.e. these should
be programs that do not cause run-time errors.

This exercise will help you understand the features you will be
implementing in the second part of the assignment and can be used to
test your compiler. In fact, we will use the programs you write to
run against a collection of existing Dupe+ compilers to see if they
uncover any bugs. The more bugs you can uncover, the better.

The Dupe+ language extends Dupe in the follow ways:

@itemlist[
@item{adding new primitive operations,}
@item{adding @racket[cond], and}
@item{adding @racket[case].}
]

You may use any a86 instructions you'd like, however it is possible to
complete the assignment using @racket[Cmp], @racket[Je], @racket[Jg],
@racket[Jmp], @racket[Label], @racket[Mov], and @racket[Sub].

@section[#:tag-prefix "a3-" #:style 'unnumbered]{More primitives}
@subsection[#:tag-prefix "a3-" #:style 'unnumbered]{Primitives}

Add the following forms of expression to the language:
The following new primitves are included in Dupe+:

@itemlist[
@item{@racket[(abs _e)]: compute the absolute value of @racket[_e],}
@item{@racket[(- _e)]: flips the sign of @racket[_e], i.e. compute @math{0-@racket[_e]}, and}
@item{@racket[(not _e)]: compute the logical negation of @racket[_e]; note that the negation of @emph{any} value other than @racket[#f] is @racket[#f] and the negation of @racket[#f] is @racket[#t].}
]

There are many ways to implement these at the assembly level. You should try implementing
these using the limited a86 instruction set.

To do this, you should:
@itemlist[
@item{Study @tt{ast.rkt} and the new forms of expression (i.e. new AST nodes)
then update the comment at the top describing what the grammmar should look like.}

@item{Study @tt{parse.rkt} and add support for parsing these
expressions. (See @secref[#:tag-prefixes '("a3-")]{parse} for guidance.)}

@item{Update @tt{interp-prim.rkt} and @tt{interp.rkt} to correctly interpret these expressions.}

@item{Make examples of these primitives and potential translations of them
to assembly.}

@item{Update @tt{compile.rkt} to correctly compile these expressions.}

@item{Check your implementation by running the tests in @tt{test/all.rkt}.}
]

@section[#:tag-prefix "a3-" #:style 'unnumbered]{Conditional Evaluation with Cond}

The Dupe language we studied included a simple form of performing
conditional evaluation of sub-expressions:

@racketblock[
(if _e0 _e1 _e2)
]
@subsection[#:tag-prefix "a3-" #:style 'unnumbered]{Conditional expressions}

However, in the original paper on Lisp,
@link["http://jmc.stanford.edu/articles/recursive.html"]{@emph{Recursive
Functions of Symbolic Expressions and Their Computation by Machine,
Part I}}, John McCarthy introduced a generalization of @racket[if]
called ``conditional expressions,'' which we could add to our
language with the following syntax:
The following new conditional form is included in Dupe+:

@racketblock[
(cond [_e-p1 _e-a1]
Expand All @@ -99,59 +75,9 @@ does not evaluate to @racket[#f] is found, in which case, the corresponding expr
@racket[cond] expression. If no such @racket[_e-pi] exists, the
expression @racket[_e-an]'s value is the value of the @racket[cond].

@;{
The formal semantics can be defined as:

@(define ((rewrite s) lws)
(define lhs (list-ref lws 2))
(define rhs (list-ref lws 3))
(list "" lhs (string-append " " (symbol->string s) " ") rhs ""))

@(require (only-in racket add-between))
@(define-syntax-rule (show-judgment name i j)
(with-unquote-rewriter
(lambda (lw)
(build-lw (lw-e lw) (lw-line lw) (lw-line-span lw) (lw-column lw) (lw-column-span lw)))
(with-compound-rewriters (['+ (rewrite '+)]
['- (rewrite '–)]
['= (rewrite '=)]
['!= (rewrite '≠)])
(apply centered
(add-between
(build-list (- j i)
(λ (n) (begin (judgment-form-cases (list (+ n i)))
(render-judgment-form name))))
(hspace 4))))))

@(show-judgment 𝑪 0 1)
@(show-judgment 𝑪 1 2)
}

Your task is to extend Dupe with this (restricted) form of @racket[cond].

To do this, you should:

@itemlist[
@item{Study @tt{ast.rkt} to add appropriate AST nodes.}
@item{Extend @tt{parse.rkt} to parse such expressions. (See @secref[#:tag-prefixes '("a3-")]{parse} for guidance.)}
@item{Update @tt{interp-prim.rkt} and @tt{interp.rkt} to correctly interpret @racket[cond] expressions.}

@item{Make examples of @racket[cond]-expressions and potential translations of them
to assembly.}

@item{Update @tt{compile.rkt} to correctly compile @racket[cond]
expressions based on your examples.}

@item{Check your implementation by running the tests in @tt{test/all.rkt}.}
]

@section[#:tag-prefix "a3-" #:style 'unnumbered]{Dispatching Evaluation with Case}

@subsection[#:tag-prefix "a3-" #:style 'unnumbered]{Case expressions}

Racket has a mechanism for dispatching between a number of possible
expressions based on a value, much like C's notion of a
@tt{switch}-statement. This is the @racket[case]-expression, which we
could add to our language with the following syntax:
The following new case form is included in Dupe+:

@racketblock[
(case _ev
Expand All @@ -160,6 +86,10 @@ could add to our language with the following syntax:
[else _en])
]

The @racket[case] expression form is a mechanism for dispatching
between a number of possible expressions based on a value, much like
C's notion of a @tt{switch}-statement.

The meaning of a @racket[case] expression is computed by evaluating
the expression @racket[_ev] and then proceeding in order through each
clause until one is found that has a datum @racket[_di] equal to
Expand All @@ -173,8 +103,65 @@ Note that each clause consists of a parenthesized list of
@emph{datums}, which in the setting of Dupe means either integer or
boolean literals.

Your task is to extend Dupe with this (restricted) form of @racket[case].

@section[#:tag-prefix "a3-" #:style 'unnumbered]{Part 2}

For this part of the assignment, you must extend the parser,
interpreter, and compiler to implement Dupe+. You are given a file
@tt{dupe-plus.zip} on ELMS with a starter compiler based on the
@secref{Dupe} language we studied in class.

You may use any a86 instructions you'd like, however it is possible to
complete the assignment using @racket[Cmp], @racket[Je], @racket[Jg],
@racket[Jmp], @racket[Label], @racket[Mov], and @racket[Sub].

@subsection[#:tag-prefix "a3-" #:style 'unnumbered]{Implementing primitives}

Implement the primitives as described earlier.

There are many ways to implement these at the assembly level. You should try implementing
these using the limited a86 instruction set.

To do this, you should:
@itemlist[
@item{Study @tt{ast.rkt} and the new forms of expression (i.e. new AST nodes)
then update the comment at the top describing what the grammmar should look like.}

@item{Study @tt{parse.rkt} and add support for parsing these
expressions. (See @secref[#:tag-prefixes '("a3-")]{parse} for guidance.)}

@item{Update @tt{interp-prim.rkt} and @tt{interp.rkt} to correctly interpret these expressions.}

@item{Make examples of these primitives and potential translations of them
to assembly.}

@item{Update @tt{compile.rkt} to correctly compile these expressions.}

@item{Check your implementation by running the tests in @tt{test/all.rkt}.}
]

@section[#:tag-prefix "a3-" #:style 'unnumbered]{Implementing cond}

Implement the @racket[cond] expression form as described earlier.
To do this, you should:

@itemlist[
@item{Study @tt{ast.rkt} to add appropriate AST nodes.}
@item{Extend @tt{parse.rkt} to parse such expressions. (See @secref[#:tag-prefixes '("a3-")]{parse} for guidance.)}
@item{Update @tt{interp-prim.rkt} and @tt{interp.rkt} to correctly interpret @racket[cond] expressions.}

@item{Make examples of @racket[cond]-expressions and potential translations of them
to assembly.}

@item{Update @tt{compile.rkt} to correctly compile @racket[cond]
expressions based on your examples.}

@item{Check your implementation by running the tests in @tt{test/all.rkt}.}
]

@section[#:tag-prefix "a3-" #:style 'unnumbered]{Implementing case}

Implement the @racket[case] expression form as described earlier.
To do this, you should:

@itemlist[
Expand Down Expand Up @@ -292,6 +279,8 @@ write additional test cases.

@section[#:tag-prefix "a3-" #:style 'unnumbered]{Submitting}

Submit a zip file containing your work to Gradescope. Use @tt{make
submit.zip} from within the @tt{dupe-plus} directory to create a zip
file with the proper structure.
For part 1, submit to Gradescope a zip file containing well-formed
Racket files that use the @tt{.rkt} file extension.

For part 2, use @tt{make} from within the @tt{dupe-plus} directory to
create a zip file containing your work and submit it to Gradescope.
2 changes: 1 addition & 1 deletion www/midterms.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@title[#:style '(toc unnumbered)]{Midterms}

There will be two midterm examinations, which will be @bold{take-home}
exams. Exams will be distributed at least 48 hours before the due
exams. Exams will be distributed at least @midterm-hours hours before the due
date of the midterm.

@itemlist[
Expand Down
21 changes: 14 additions & 7 deletions www/midterms/1.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
Midterm 1 will be released at least @midterm-hours hours prior to
its due date.

@;{
@section{Practice}

There is a practice midterm from Summer 2023 available on ELMS as
@tt{m1-summer-2023.zip}. You may submit to the Practice Midterm 1 -
Summer 2023 assignment on Gradescope to get feedback on your solution.
However during the real midterm, you will not get this level of
feedback from the autograder.

@section{Instructions}

The midterm will be released as a zip file @tt{m1.zip} on ELMS.
Expand All @@ -22,14 +29,14 @@ midterm.

@section{Communications}

If you have questions about the exam, send a DM to ModMail on Discord.
This will go to the entire course staff.
If you have questions about the exam, send a @bold{private} message on
Piazza.

Answers to common clarifying questions will be posted to the
@tt{#midterm1} channel on Discord.
Answers to common clarifying questions will be posted to
Piazza.

If you have trouble reaching the course staff via Discord, email
@tt{@prof-email}.
@tt{@prof1-email}.

You may not communicate with anyone outside of the course staff about
the midterm.
Expand All @@ -47,4 +54,4 @@ If you fail these tests, we will not be able to grade your submission.
Passing these tests only means your submission is well-formed. Your
actual grade will be computed after the deadline.

You are encouraged to check your own work.}
You are encouraged to check your own work.
17 changes: 17 additions & 0 deletions www/schedule.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@
@itemlist[@item{@secref["Con"]}
@item{@secref["Dupe"]}])

(list @wk{2/19}
@elem{@seclink["Assignment 2"]{A3} P1}
@itemlist[@item{@secref["Dodger"]}
@item{@secref["Evildoer"]}]
@secref["Extort"])

(list @wk{2/26}
@elem{@seclink["Assignment 2"]{A3} P2}
@secref{Fraud}
@secref{Fraud})

(list @wk{3/4}
""
@secref{Hustle}
@secref["Midterm_1"])


#|
(list @wk{9/25}
@seclink["Assignment 3"]{A3}
Expand Down