Skip to content

Commit 23c964f

Browse files
authored
Merge pull request #206 from cmsc430/fall-2025
Fall 2025
2 parents e0ee456 + 98d6110 commit 23c964f

File tree

2 files changed

+27
-40
lines changed

2 files changed

+27
-40
lines changed

www/assignments/6.scrbl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99

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

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

1814
The goal of this assignment is to gain proficiency with our
1915
representation of memory-allocated values by implementing a number of

www/notes/iniquity.scrbl

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@
1111

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

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

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

7470
@racketblock[
75-
(define (_f0 _x00 ...) _e0)
76-
(define (_f1 _x10 ...) _e1)
71+
(define (_f₀ _x₀₀ ...) _e₀)
72+
(define (_f₁ _x₁₀ ...) _e₁)
7773
...
78-
e
74+
_e
7975
]
8076

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

8379
@racketblock[
84-
(_fi _e0 ...)
80+
(_fᵢ _e₀ ...)
8581
]
8682

87-
where @racket[_fi] is one of the function names defined in the program.
83+
where @racket[_fᵢ] is one of the function names defined in the program.
8884

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

654650
@ex[
655-
(asm-display
656-
(compile
657-
(parse '(define (double x) (+ x x)) '(double 5))))
651+
(compile (parse '(define (double x) (+ x x))
652+
'(double 5)))
658653
]
659654

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

663658
@ex[
664-
(current-objs '("runtime.o"))
665-
(define (run . p)
666-
(bits->value (asm-interp (compile (apply parse p)))))
667-
668-
(run '(define (double x) (+ x x))
669-
'(double 5))
670-
671-
(run '(define (tri x)
672-
(if (zero? x)
673-
0
674-
(+ x (tri (sub1 x)))))
675-
'(tri 9))
676-
677-
(run '(define (even? x)
678-
(if (zero? x)
679-
#t
680-
(odd? (sub1 x))))
681-
'(define (odd? x)
682-
(if (zero? x)
683-
#f
684-
(even? (sub1 x))))
685-
'(even? 101))
659+
(exec (parse '(define (double x) (+ x x))
660+
'(double 5)))
661+
662+
(exec (parse '(define (tri x)
663+
(if (zero? x)
664+
0
665+
(+ x (tri (sub1 x)))))
666+
'(tri 9)))
667+
668+
(exec (parse '(define (even? x)
669+
(if (zero? x)
670+
#t
671+
(odd? (sub1 x))))
672+
'(define (odd? x)
673+
(if (zero? x)
674+
#f
675+
(even? (sub1 x))))
676+
'(even? 101)))
686677
]
687678

688679
The complete compiler code:

0 commit comments

Comments
 (0)