12/14/22, 3:02 AM Project
https://www.cs.umd.edu/class/fall2022/cmsc430/Project.html 1/9
Copyright By PowCoder代写 加微信 powcoder
The final assessment for this course consists of an individually completed project.
Final deliverables are due by the end of the time schedule for the class’s final exam as set by the registrar.
There are several projects to choose from, described below.
Compared to assignments, the project is more open-ended. You will need to select from a project description
below and then select which language you’d like to target with your project. As starter code, you can use the
source code of any of the course languages. How you implement your project is up to you. It may involve
changes to all aspects of the language implementation: the parser, the compiler, and the run-time system
(however, we do not require an interpreter implementation). No tests are provided, so we recommend you write
your own and suggest focusing on tests before trying to implement these features.
In addition to the source code for your project, you must write a 2-page document in PDF format, which gives a
summary of your work and describes how your project is implemented.
1 Multiple return values
1.1 Returning multiple values to the run-time system or asm-interp
2 Exceptions and exception handling
3 Garbage collection
4 Design your own
5 Submitting
1 Multiple return values
Racket, Scheme, and even x86 support returning more than one value from a function call. Implement Racket’s
let-values and values forms to add multiple return values.
You may choose to implement this feature for any language that is Iniquity or later for a maximum 95% of the
possible points. For 100% you’ll need to implement the feature for Loot or later.
Here are the key features that need to be added:
http://docs.racket-lang.org/reference/let.html#%28form._%28%28quote._~23~25kernel%29._let-values%29%29
http://docs.racket-lang.org/reference/values.html#%28def._%28%28quote._~23~25kernel%29._values%29%29
https://www.cs.umd.edu/class/fall2022/cmsc430/Iniquity.html
12/14/22, 3:02 AM Project
https://www.cs.umd.edu/class/fall2022/cmsc430/Project.html 2/9
(values … ) will evaluate through and then “return” all of their values.
(let-values ([( … ) ]) ) will evaluate , which is expected to be an expression that produces
values, which are bound to through in the body expression .
Here are some examples to help illustrate:
> (let-values ([(x y) (values 1 2)]) (+ x y))
> (let-values ([(x) (values 1)]) (add1 x))
> (let-values ([() (values)]) 7)
> (define (f x)
(values x (+ x 1) (+ x 2)))
> (let-values ([(x y z) (f 5)])
(cons x (cons y (cons z ‘()))))
> (add1 (values 5))
> (let ((x (values 5)))
Any time an expression produces a number of values that doesn’t match what the surrounding context expects,
an error should be signaled.
> (add1 (values 1 2))
result arity mismatch;
expected number of values not received
expected: 1
received: 2
> (let-values ([(x y) 2]) x)
result arity mismatch;
expected number of values not received
e1 en e1 en
x1 xn e e0 e n
http://docs.racket-lang.org/reference/values.html#%28def._%28%28quote._~23~25kernel%29._values%29%29
http://docs.racket-lang.org/reference/let.html#%28form._%28%28quote._~23~25kernel%29._let-values%29%29
http://docs.racket-lang.org/reference/let.html#%28form._%28%28quote._~23~25kernel%29._let-values%29%29
http://docs.racket-lang.org/reference/values.html#%28def._%28%28quote._~23~25kernel%29._values%29%29
http://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._%2B%29%29
http://docs.racket-lang.org/reference/let.html#%28form._%28%28quote._~23~25kernel%29._let-values%29%29
http://docs.racket-lang.org/reference/values.html#%28def._%28%28quote._~23~25kernel%29._values%29%29
http://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._add1%29%29
http://docs.racket-lang.org/reference/let.html#%28form._%28%28quote._~23~25kernel%29._let-values%29%29
http://docs.racket-lang.org/reference/values.html#%28def._%28%28quote._~23~25kernel%29._values%29%29
http://docs.racket-lang.org/reference/define.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29
http://docs.racket-lang.org/reference/values.html#%28def._%28%28quote._~23~25kernel%29._values%29%29
http://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._%2B%29%29
http://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._%2B%29%29
http://docs.racket-lang.org/reference/let.html#%28form._%28%28quote._~23~25kernel%29._let-values%29%29
http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._~23~25kernel%29._cons%29%29
http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._~23~25kernel%29._cons%29%29
http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._~23~25kernel%29._cons%29%29
http://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._add1%29%29
http://docs.racket-lang.org/reference/values.html#%28def._%28%28quote._~23~25kernel%29._values%29%29
http://docs.racket-lang.org/reference/let.html#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._let%29%29
http://docs.racket-lang.org/reference/values.html#%28def._%28%28quote._~23~25kernel%29._values%29%29
http://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._add1%29%29
http://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._add1%29%29
http://docs.racket-lang.org/reference/values.html#%28def._%28%28quote._~23~25kernel%29._values%29%29
http://docs.racket-lang.org/reference/let.html#%28form._%28%28quote._~23~25kernel%29._let-values%29%29
12/14/22, 3:02 AM Project
https://www.cs.umd.edu/class/fall2022/cmsc430/Project.html 3/9
expected: 2
received: 1
in: local-binding form
arguments…:
The top-level expression may produce any number of values and the run-time system should print each of them
out, followed by a newline:
> (values 1 2 3)
Note there is some symmetry here between function arity checking where we make sure the number of
arguments matches the number of parameters of the function being called and the “result arity” checking that is
required to implement this feature. This suggests a similar approach to implementing this feature, namely
designating a register to communicate the arity of the result, which should be checked by the surrounding
You will also need to design an alternative mechanism for communicating return values. Using a single register
(‘rax) works when every expression produces a single result, but now expressions may produce an arbitrary
number of results and using registers will no longer suffice. (Although you may want to continue to use ‘rax for
the common case of a single result.) The solution for this problem with function parameters was to use the stack
and a similar approach can work for results too.
1.1 Returning multiple values to the run-time system or asm-interp
In implementing values, there are two design decisions you have to make:
1. How are values going to be represented during the execution of a program?
2. How are values going to be communicated back to the run-time system and/or asm-interp when the program
completes?
http://docs.racket-lang.org/reference/values.html#%28def._%28%28quote._~23~25kernel%29._values%29%29
https://www.cs.umd.edu/class/fall2022/cmsc430/a86.html#%28def._%28%28lib._a86%2Finterp..rkt%29._asm-interp%29%29
http://docs.racket-lang.org/reference/values.html#%28def._%28%28quote._~23~25kernel%29._values%29%29
12/14/22, 3:02 AM Project
https://www.cs.umd.edu/class/fall2022/cmsc430/Project.html 4/9
The answers to (1) and (2) don’t necessarily have to be the same.
Note that you can go a long way working on (1) without making any changes to the run-time system or unload-
bits-asm.rkt (which is how the result of asm-interp is converted back to a Racket value). You can basically
punt on (2) and work on (1) by writing tests that use multiple values within a computation, but ultimately
return a single value, e.g. (let-values ([(x y) (values 1 2)] (cons x y))).
As for (2), here is a suggestion that you are free to adopt, although you can implement (2) however you’d like so
long as when running an executable that returns multiple values it prints the results in a way consistent with
how Racket prints and that if using asm-interp, your version of unload/free produces multiple values whenever
the program does.
You can return a vector of results at the end of entry. This means after the instructions for the program,
whatever values are produced are converted from the internal representation of values (i.e., your design for (1))
to a vector and the address (untagged) is put into rax to be returned to the run-time system and/or asm-interp.
Now both the run-time system and unload-bits-asm.rkt need to be updated to deal with this change in
representation for the result.
In main.c, the part that gets the result and prints it:
can be changed to getting the vector and printing each element:
You’ll also need to update the signature of entry in runtime.h to:
You’ll also need to make a similar change to unload/free in unload-bits-asm.rkt, which plays the role of the
run-time system when writing tests that use asm-interp.
val_t result = entry(heap);
print_result(result);
if (val_typeof(result) != T_VOID)
putchar(‘\n’);
val_vect_t *result = entry(heap);
for (int i = 0; i < result->len; ++i) {
print_result(result->elems[i]);
if (val_typeof(result->elems[i]) != T_VOID)
putchar(‘\n’);
val_vect_t* entry();
https://www.cs.umd.edu/class/fall2022/cmsc430/a86.html#%28def._%28%28lib._a86%2Finterp..rkt%29._asm-interp%29%29
http://docs.racket-lang.org/reference/let.html#%28form._%28%28quote._~23~25kernel%29._let-values%29%29
http://docs.racket-lang.org/reference/values.html#%28def._%28%28quote._~23~25kernel%29._values%29%29
http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._~23~25kernel%29._cons%29%29
https://www.cs.umd.edu/class/fall2022/cmsc430/a86.html#%28def._%28%28lib._a86%2Finterp..rkt%29._asm-interp%29%29
https://www.cs.umd.edu/class/fall2022/cmsc430/a86.html#%28def._%28%28lib._a86%2Finterp..rkt%29._asm-interp%29%29
https://www.cs.umd.edu/class/fall2022/cmsc430/a86.html#%28def._%28%28lib._a86%2Finterp..rkt%29._asm-interp%29%29
12/14/22, 3:02 AM Project
https://www.cs.umd.edu/class/fall2022/cmsc430/Project.html 5/9
Instead of:
; Answer* -> Answer
(define (unload/free a)
[‘err ‘err]
[(cons h v) (begin0 (unload-value v)
(free h))]))
You’ll want:
; Answer* -> Answer
(define (unload/free a)
[‘err ‘err]
[(cons h vs) (begin0 (unload-values vs)
(free h))]))
(define (unload-values vs)
(let ((vec (unload-value (bitwise-xor vs type-vect))))
(apply values (vector->list vec))))
Let’s say you make these changes to the run-time system and unload/free before you make any changes to the
compiler and now you want to adapt the compiler to work with the new set up (before trying to do anything
with values). You can add the following at the end of entry, just before the (Ret):
; Create and return unary vector holding the result
(Mov r8 1)
(Mov (Offset rbx 0) r8) ; write size of vector, 1
(Mov (Offset rbx 8) rax) ; write rax as single element of vector
(Mov rax rbx) ; return the pointer to the vector
In order to return more values, you’d construct a larger vector.
2 Exceptions and exception handling
http://docs.racket-lang.org/reference/define.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29
http://docs.racket-lang.org/reference/match.html#%28form._%28%28lib._racket%2Fmatch..rkt%29._match%29%29
http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._~23~25kernel%29._cons%29%29
http://docs.racket-lang.org/reference/begin.html#%28form._%28%28quote._~23~25kernel%29._begin0%29%29
http://docs.racket-lang.org/reference/define.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29
http://docs.racket-lang.org/reference/match.html#%28form._%28%28lib._racket%2Fmatch..rkt%29._match%29%29
http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._~23~25kernel%29._cons%29%29
http://docs.racket-lang.org/reference/begin.html#%28form._%28%28quote._~23~25kernel%29._begin0%29%29
http://docs.racket-lang.org/reference/define.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29
http://docs.racket-lang.org/reference/let.html#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._let%29%29
http://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._bitwise-xor%29%29
http://docs.racket-lang.org/reference/procedures.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._apply%29%29
http://docs.racket-lang.org/reference/values.html#%28def._%28%28quote._~23~25kernel%29._values%29%29
http://docs.racket-lang.org/reference/vectors.html#%28def._%28%28quote._~23~25kernel%29._vector-~3elist%29%29
http://docs.racket-lang.org/reference/values.html#%28def._%28%28quote._~23~25kernel%29._values%29%29
https://www.cs.umd.edu/class/fall2022/cmsc430/a86.html#%28def._%28%28lib._a86%2Fast..rkt%29._.Ret%29%29
https://www.cs.umd.edu/class/fall2022/cmsc430/a86.html#%28def._%28%28lib._a86%2Fast..rkt%29._.Mov%29%29
https://www.cs.umd.edu/class/fall2022/cmsc430/a86.html#%28def._%28%28lib._a86%2Fast..rkt%29._.Mov%29%29
https://www.cs.umd.edu/class/fall2022/cmsc430/a86.html#%28def._%28%28lib._a86%2Fast..rkt%29._.Offset%29%29
https://www.cs.umd.edu/class/fall2022/cmsc430/a86.html#%28def._%28%28lib._a86%2Fast..rkt%29._.Mov%29%29
https://www.cs.umd.edu/class/fall2022/cmsc430/a86.html#%28def._%28%28lib._a86%2Fast..rkt%29._.Offset%29%29
https://www.cs.umd.edu/class/fall2022/cmsc430/a86.html#%28def._%28%28lib._a86%2Fast..rkt%29._.Mov%29%29
12/14/22, 3:02 AM Project
https://www.cs.umd.edu/class/fall2022/cmsc430/Project.html 6/9
Exceptions and exception handling mechanisms are widely used in modern programming languages. Implement
Racket’s raise and with-handlers forms to add exception handling.
You may choose to implement this feature for any language that is Iniquity or later for a maximum 95% of the
possible points. For 100% you’ll need to implement the feature for Loot or later.
Here are the key features that need to be added:
(raise ) will evaluate and then “raise” the value, side-stepping the usual flow of control and instead jump
to the most recently installed exception handler.
(with-handlers ([ ] …) ) will install a new exception handler during the evaluation of . If raises
an exception that is not caught, the predicates should be applied to the raised value until finding the first
that returns true, at which point the corresponding function is called with the raised value and the result of
that application is the result of the entire with-handlers expression. If does not raise an error, its value is
the value of the with-handler expression.
Here are some examples to help illustrate:
> (with-handlers ([string? (λ (s) (cons “got” s))])
(raise “a string!”))
‘(“got” . “a string!”)
> (with-handlers ([string? (λ (s) (cons “got” s))]
[number? (λ (n) (+ n n))])
(raise 10))
> (with-handlers ([string? (λ (s) (cons “got” s))]
[number? (λ (n) (+ n n))])
(+ (raise 10) 30))
> (let ((f (λ (x) (raise 10))))
(with-handlers ([string? (λ (s) (cons “got” s))]
[number? (λ (n) (+ n n))])
(+ (f 10) 30)))
> (with-handlers ([string? (λ (s) (cons “got” s))]
p1 f1 e e e
http://docs.racket-lang.org/reference/exns.html#%28def._%28%28quote._~23~25kernel%29._raise%29%29
http://docs.racket-lang.org/reference/exns.html#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._with-handlers%29%29
https://www.cs.umd.edu/class/fall2022/cmsc430/Iniquity.html
http://docs.racket-lang.org/reference/exns.html#%28def._%28%28quote._~23~25kernel%29._raise%29%29
http://docs.racket-lang.org/reference/exns.html#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._with-handlers%29%29
http://docs.racket-lang.org/reference/exns.html#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._with-handlers%29%29
http://docs.racket-lang.org/reference/exns.html#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._with-handlers%29%29
http://docs.racket-lang.org/reference/strings.html#%28def._%28%28quote._~23~25kernel%29._string~3f%29%29
http://docs.racket-lang.org/reference/lambda.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._~ce~bb%29%29
http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._~23~25kernel%29._cons%29%29
http://docs.racket-lang.org/reference/exns.html#%28def._%28%28quote._~23~25kernel%29._raise%29%29
http://docs.racket-lang.org/reference/exns.html#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._with-handlers%29%29
http://docs.racket-lang.org/reference/strings.html#%28def._%28%28quote._~23~25kernel%29._string~3f%29%29
http://docs.racket-lang.org/reference/lambda.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._~ce~bb%29%29
http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._~23~25kernel%29._cons%29%29
http://docs.racket-lang.org/reference/number-types.html#%28def._%28%28quote._~23~25kernel%29._number~3f%29%29
http://docs.racket-lang.org/reference/lambda.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._~ce~bb%29%29
http://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._%2B%29%29
http://docs.racket-lang.org/reference/exns.html#%28def._%28%28quote._~23~25kernel%29._raise%29%29
http://docs.racket-lang.org/reference/exns.html#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._with-handlers%29%29
http://docs.racket-lang.org/reference/strings.html#%28def._%28%28quote._~23~25kernel%29._string~3f%29%29
http://docs.racket-lang.org/reference/lambda.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._~ce~bb%29%29
http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._~23~25kernel%29._cons%29%29
http://docs.racket-lang.org/reference/number-types.html#%28def._%28%28quote._~23~25kernel%29._number~3f%29%29
http://docs.racket-lang.org/reference/lambda.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._~ce~bb%29%29
http://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._%2B%29%29
http://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._%2B%29%29
http://docs.racket-lang.org/reference/exns.html#%28def._%28%28quote._~23~25kernel%29._raise%29%29
http://docs.racket-lang.org/reference/let.html#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._let%29%29
http://docs.racket-lang.org/reference/lambda.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._~ce~bb%29%29
http://docs.racket-lang.org/reference/exns.html#%28def._%28%28quote._~23~25kernel%29._raise%29%29
http://docs.racket-lang.org/reference/exns.html#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._with-handlers%29%29
http://docs.racket-lang.org/reference/strings.html#%28def._%28%28quote._~23~25kernel%29._string~3f%29%29
http://docs.racket-lang.org/reference/lambda.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._~ce~bb%29%29
http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._~23~25kernel%29._cons%29%29
http://docs.racket-lang.org/reference/number-types.html#%28def._%28%28quote._~23~25kernel%29._number~3f%29%29
http://docs.racket-lang.org/reference/lambda.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._~ce~bb%29%29
http://docs.racket-lang.org/referenc
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com