diff --git a/www/assignments/6.scrbl b/www/assignments/6.scrbl index 3d092889..f82ed9a1 100644 --- a/www/assignments/6.scrbl +++ b/www/assignments/6.scrbl @@ -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 diff --git a/www/notes/iniquity.scrbl b/www/notes/iniquity.scrbl index 8577f0bb..47ffc7fe 100644 --- a/www/notes/iniquity.scrbl +++ b/www/notes/iniquity.scrbl @@ -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")]) @@ -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 @@ -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: