Skip to content
Merged
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
6 changes: 1 addition & 5 deletions www/assignments/6.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@

@bold{Due: @assign-deadline[6]}

@;{ All this to silence some Makefile output on Linux -- should probably be taken care of at the Makefile level }
@(ev '(begin (define p (current-output-port))
(current-output-port (open-output-string))
(require hoax-plus)
(current-output-port p)))
@(ev '(require hoax-plus))

The goal of this assignment is to gain proficiency with our
representation of memory-allocated values by implementing a number of
Expand Down
61 changes: 26 additions & 35 deletions www/notes/iniquity.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@

@(define codeblock-include (make-codeblock-include #'h))

@(ev '(require rackunit a86))
@(ev `(current-directory ,(path->string (build-path langs "iniquity"))))
@(void (ev '(with-output-to-string (thunk (system "make runtime.o")))))
@(for-each (λ (f) (ev `(require (file ,f))))
'("interp.rkt" "compile.rkt" "ast.rkt" "parse.rkt" "types.rkt"))
@(ev '(require rackunit a86 iniquity))

@(define (shellbox . s)
(parameterize ([current-directory (build-path langs "iniquity")])
Expand Down Expand Up @@ -72,19 +68,19 @@ We will extend the syntax by introducing a new syntactic category of
followed by an expression:

@racketblock[
(define (_f0 _x00 ...) _e0)
(define (_f1 _x10 ...) _e1)
(define (_f₀ _x₀₀ ...) _e₀)
(define (_f₁ _x₁₀ ...) _e₁)
...
e
_e
]

And the syntax of expressions will be extended to include function calls:

@racketblock[
(_fi _e0 ...)
(_fᵢ _e₀ ...)
]

where @racket[_fi] is one of the function names defined in the program.
where @racket[_fᵢ] is one of the function names defined in the program.

Note that functions can have any number of parameters and,
symmetrically, calls can have any number of arguments. A program
Expand Down Expand Up @@ -652,37 +648,32 @@ single list:
Here's an example of the code this compiler emits:

@ex[
(asm-display
(compile
(parse '(define (double x) (+ x x)) '(double 5))))
(compile (parse '(define (double x) (+ x x))
'(double 5)))
]

And we can confirm running the code produces results consistent with
the interpreter:

@ex[
(current-objs '("runtime.o"))
(define (run . p)
(bits->value (asm-interp (compile (apply parse p)))))

(run '(define (double x) (+ x x))
'(double 5))

(run '(define (tri x)
(if (zero? x)
0
(+ x (tri (sub1 x)))))
'(tri 9))

(run '(define (even? x)
(if (zero? x)
#t
(odd? (sub1 x))))
'(define (odd? x)
(if (zero? x)
#f
(even? (sub1 x))))
'(even? 101))
(exec (parse '(define (double x) (+ x x))
'(double 5)))

(exec (parse '(define (tri x)
(if (zero? x)
0
(+ x (tri (sub1 x)))))
'(tri 9)))

(exec (parse '(define (even? x)
(if (zero? x)
#t
(odd? (sub1 x))))
'(define (odd? x)
(if (zero? x)
#f
(even? (sub1 x))))
'(even? 101)))
]

The complete compiler code:
Expand Down