Skip to content

Commit e5ab6a1

Browse files
committed
Rework www to use langs package.
1 parent 41395ca commit e5ab6a1

24 files changed

Lines changed: 157 additions & 110 deletions

www/assignments/3.scrbl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
@title[#:tag "Assignment 3" #:style 'unnumbered]{Assignment 3: Primitives, Conditionals, and Dispatch}
33

44
@(require (for-label a86 (except-in racket ...)))
5-
@(require "../../langs/con-plus/semantics.rkt")
6-
@(require redex/pict)
75

86
@bold{Due: Thursday, October 3, 11:59PM}
97

www/notes/1/ocaml-to-racket.scrbl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
(apply fancyverbatim "ocaml" s)))
2727

2828
@(define (shellbox . s)
29-
(parameterize ([current-directory (build-path notes "intro")])
29+
(parameterize ([current-directory (build-path langs "intro")])
3030
(filebox (emph "shell")
3131
(fancyverbatim "fish" (apply shell s)))))
3232

@@ -1260,7 +1260,8 @@ Putting it all together, we can write the following code and save it
12601260
in a file called @tt{bt.rkt}. (You can right-click the file name and
12611261
save the code to try it out.)
12621262

1263-
@codeblock-include["intro/bt.rkt"]
1263+
@;{FIXME: Fix this!}
1264+
@;codeblock-include["intro/bt.rkt"]
12641265

12651266
This code follows a coding style that we will use in this course:
12661267
@itemlist[
@@ -1275,11 +1276,11 @@ This code follows a coding style that we will use in this course:
12751276
From the command line, you can run a module's tests using the Racket
12761277
command line testing tool @tt{raco test}:
12771278

1278-
@shellbox["raco test bt.rkt"]
1279+
@tt{raco test bt.rkt} @;{FIXME: make this a shellbox}
12791280

12801281
Or simply give a directory name and test everything within that directory:
12811282

1282-
@shellbox["raco test ."]
1283+
@tt{raco test .} @;{FIXME: make this a shellbox}
12831284

12841285

12851286

www/notes/a86.scrbl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616
@(ev '(require rackunit a86))
1717

18-
@(ev `(current-directory ,(path->string (build-path notes "a86"))))
18+
@(ev `(current-directory ,(path->string a86)))
1919

2020
@(define (shellbox . s)
21-
(parameterize ([current-directory (build-path notes "a86")])
21+
(parameterize ([current-directory a86])
2222
(filebox (emph "shell")
2323
(fancyverbatim "fish" (apply shell s)))))
2424

@@ -68,7 +68,7 @@ int gcd(int n1, int n2) {
6868
HERE
6969
)
7070

71-
(parameterize ([current-directory (build-path notes "a86")])
71+
(parameterize ([current-directory a86])
7272
(save-file "tri.s" (asm-string (tri 36)))
7373
(save-file "main.c" main.c)
7474
(save-file "gcd.c" gcd.c)))
@@ -147,7 +147,7 @@ This example is shown using the @(if (eq? (system-type 'os) 'macosx)
147147
"MacOS" "Linux") naming convention, because that's what operating
148148
system was used when this web page was built.}
149149

150-
@filebox-include[fancy-nasm "a86/tri.s"]
150+
@filebox-include[fancy-nasm a86 "tri.s"]
151151

152152
The @math{n}th triangular number is the sum of the integers
153153
from 0 to @math{n}, so the @math{36}th triangular number is
@@ -258,7 +258,7 @@ To run the object file, we will need to link with a small C program
258258
that can call the @tt{entry} label of our assembly code and then
259259
print the result:
260260

261-
@filebox-include[fancy-c "a86/main.c"]
261+
@filebox-include[fancy-c a86 "main.c"]
262262

263263
Notice that from the C program's perspective, the assembly
264264
code defines what looks like a C function called @tt{entry}
@@ -1982,7 +1982,7 @@ assembly code when running @racket[asm-interp].
19821982

19831983
For example, let's implement a GCD function in C:
19841984

1985-
@filebox-include[fancy-c "a86/gcd.c"]
1985+
@filebox-include[fancy-c a86 "gcd.c"]
19861986

19871987
First, compile the program to an object file:
19881988

www/notes/abscond.scrbl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@
1414
@(define codeblock-include (make-codeblock-include #'here))
1515

1616
@(ev '(require rackunit a86))
17-
@(for-each (λ (f) (ev `(require (file ,(path->string (build-path notes "abscond" f))))))
17+
@(for-each (λ (f) (ev `(require (file ,(path->string (build-path langs "abscond" f))))))
1818
'("interp.rkt" "ast.rkt" "compile.rkt"))
1919

2020
@(define (shellbox . s)
21-
(parameterize ([current-directory (build-path notes "abscond")])
21+
(parameterize ([current-directory (build-path langs "abscond")])
2222
(filebox (emph "shell")
2323
(fancyverbatim "fish" (apply shell s)))))
2424

2525
@(require (for-syntax "../utils.rkt" racket/base "utils.rkt"))
2626
@(define-syntax (shell-expand stx)
2727
(syntax-case stx ()
2828
[(_ s ...)
29-
(parameterize ([current-directory (build-path notes "abscond")])
29+
(parameterize ([current-directory (build-path langs "abscond")])
3030
(begin (apply shell (syntax->datum #'(s ...)))
3131
#'(void)))]))
3232

@@ -292,14 +292,14 @@ So our compiler will emit x86 assembly code. To make our lives a bit
292292
easier, we will write the run-time system in C. Let's start with the
293293
Abscond runtime:
294294

295-
@filebox-include[fancy-c "abscond/main.c"]
295+
@filebox-include[fancy-c abscond "main.c"]
296296

297297
This C program provides the main entry point for running an Abscond
298298
program. It relies upon a function @tt{print_result} which is defined
299299
as follows:
300300

301-
@filebox-include[fancy-c "abscond/print.h"]
302-
@filebox-include[fancy-c "abscond/print.c"]
301+
@filebox-include[fancy-c abscond "print.h"]
302+
@filebox-include[fancy-c abscond "print.c"]
303303

304304
Separating out @tt{print_result}, which at this point is just a simple
305305
@tt{printf} statement, seems like overkill, but it will be useful in
@@ -334,7 +334,7 @@ example. Let's say the Abscond program is @racket[42]. What should
334334
the assembly code for this program look like? Here we have to learn a
335335
bit about the x86-64 assembly language.
336336

337-
@filebox-include[fancy-nasm "abscond/42.s"]
337+
@filebox-include[fancy-nasm abscond "42.s"]
338338

339339
@margin-note{Note: on macOS, labels must be prepended with @tt{_},
340340
while on Linux they are not; e.g. @tt{_entry} vs @tt{entry}.}
@@ -449,7 +449,7 @@ Using a Makefile, we can capture the whole compilation dependencies as:
449449
@margin-note{Note: the appropriate object file format is detected
450450
based on the operating system.}
451451

452-
@filebox-include[fancy-make "abscond/Makefile"]
452+
@filebox-include[fancy-make abscond "Makefile"]
453453

454454
And now compiling Abscond programs is easy-peasy:
455455

www/notes/blackmail.scrbl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@
55
redex/pict
66
"../fancyverb.rkt"
77
"../utils.rkt"
8-
"../../langs/blackmail/semantics.rkt"
8+
blackmail/semantics
99
"utils.rkt"
1010
"ev.rkt")
1111

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

1414
@(ev '(require rackunit a86))
15-
@(for-each (λ (f) (ev `(require (file ,(path->string (build-path notes "blackmail" f))))))
15+
@(for-each (λ (f) (ev `(require (file ,(path->string (build-path langs "blackmail" f))))))
1616
'("interp.rkt" "compile.rkt" "random.rkt" "ast.rkt"))
1717

1818
@(define (shellbox . s)
19-
(parameterize ([current-directory (build-path notes "blackmail")])
19+
(parameterize ([current-directory (build-path langs "blackmail")])
2020
(filebox (emph "shell")
2121
(fancyverbatim "fish" (apply shell s)))))
2222

2323
@(require (for-syntax "../utils.rkt" racket/base "utils.rkt"))
2424
@(define-syntax (shell-expand stx)
2525
(syntax-case stx ()
2626
[(_ s ...)
27-
(parameterize ([current-directory (build-path notes "blackmail")])
27+
(parameterize ([current-directory (build-path langs "blackmail")])
2828
(begin (apply shell (syntax->datum #'(s ...)))
2929
#'(void)))]))
3030

@@ -208,7 +208,7 @@ increments the contents of a register by some given amount.
208208

209209
Concretely, the program that adds 1 twice to 40 looks like:
210210

211-
@filebox-include[fancy-nasm "blackmail/add1-add1-40.s"]
211+
@filebox-include[fancy-nasm blackmail "add1-add1-40.s"]
212212

213213
The runtime stays exactly the same as before.
214214

www/notes/bt/bt.rkt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#lang racket
2+
(provide (all-defined-out))
3+
4+
(module+ test
5+
(require rackunit))
6+
7+
;; type Bt =
8+
;; | (leaf)
9+
;; | (node Integer Bt Bt)
10+
(struct leaf () #:prefab)
11+
(struct node (v l r) #:prefab)
12+
13+
;; Bt -> Boolean
14+
;; Is the binary tree empty?
15+
(define (bt-empty? bt)
16+
(match bt
17+
[(leaf) #t]
18+
[_ #f]))
19+
20+
(module+ test
21+
(check-equal? (bt-empty? (leaf)) #t)
22+
(check-equal? (bt-empty? (node 3
23+
(node 7 (leaf) (leaf))
24+
(node 9 (leaf) (leaf))))
25+
#f))
26+
27+
;; Bt -> Natural
28+
;; Compute the height of a binary tree
29+
(define (bt-height bt)
30+
(match bt
31+
[(leaf) 0]
32+
[(node _ left right)
33+
(+ 1 (max (bt-height left)
34+
(bt-height right)))]))
35+
36+
(module+ test
37+
(check-equal? (bt-height (leaf)) 0)
38+
(check-equal? (bt-height (node 3 (leaf) (leaf))) 1)
39+
(check-equal? (bt-height (node 2 (leaf) (node 1 (leaf) (leaf))))
40+
2))

www/notes/con.scrbl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#;(prefix-in sem: (only-in "con/semantics.rkt" ext lookup))
99
"utils.rkt"
1010
"ev.rkt"
11-
"../../langs/con/semantics.rkt"
11+
con/semantics
1212
"../utils.rkt")
1313

1414

@@ -17,7 +17,7 @@
1717

1818

1919
@(ev '(require rackunit a86))
20-
@(for-each (λ (f) (ev `(require (file ,(path->string (build-path notes "con" f))))))
20+
@(for-each (λ (f) (ev `(require (file ,(path->string (build-path langs "con" f))))))
2121
'("interp.rkt" "compile.rkt" "parse.rkt" "ast.rkt" "random.rkt"))
2222

2323

www/notes/dodger.scrbl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@(define codeblock-include (make-codeblock-include #'h))
1515

1616
@(ev '(require rackunit a86))
17-
@(for-each (λ (f) (ev `(require (file ,(path->string (build-path notes "dodger" f))))))
17+
@(for-each (λ (f) (ev `(require (file ,(path->string (build-path langs "dodger" f))))))
1818
'("interp.rkt" "compile.rkt" "ast.rkt" "parse.rkt" "types.rkt"))
1919

2020

@@ -198,17 +198,17 @@ need to add run-time support for printing character literals.
198198
We extend the bit-encoding of values following the pattern we've
199199
already seen:
200200

201-
@filebox-include[fancy-c "dodger/types.h"]
201+
@filebox-include[fancy-c dodger "types.h"]
202202

203203
And update the interface for values in the runtime system:
204204

205-
@filebox-include[fancy-c "dodger/values.h"]
206-
@filebox-include[fancy-c "dodger/values.c"]
205+
@filebox-include[fancy-c dodger "values.h"]
206+
@filebox-include[fancy-c dodger "values.c"]
207207

208208
The only other change is that @tt{print_result} is updated to handle
209209
the case of printing characters:
210210

211-
@filebox-include[fancy-c "dodger/print.c"]
211+
@filebox-include[fancy-c dodger "print.c"]
212212

213213
Will these pieces in place, we can try out some examples:
214214

www/notes/dupe.scrbl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
"../fancyverb.rkt"
99
"utils.rkt"
1010
"ev.rkt"
11-
"../../langs/dupe/semantics.rkt"
12-
"../../langs/dupe/types.rkt"
11+
dupe/semantics
12+
dupe/types
1313
"../utils.rkt")
1414

1515

1616

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

1919
@(ev '(require rackunit a86))
20-
@(for-each (λ (f) (ev `(require (file ,(path->string (build-path notes "dupe" f))))))
20+
@(for-each (λ (f) (ev `(require (file ,(path->string (build-path langs "dupe" f))))))
2121
'("interp.rkt" "interp-prim.rkt" "compile.rkt" "ast.rkt" "parse.rkt" "random.rkt" "types.rkt"))
2222

2323

@@ -934,7 +934,7 @@ what is being represented and prints it appropriately.
934934
For the run-time system, we define the bit representations in a header
935935
file corresponding to the definitions given in @tt{types.rkt}:
936936

937-
@filebox-include[fancy-c "dupe/types.h"]
937+
@filebox-include[fancy-c dupe "types.h"]
938938

939939
It uses an idiom of ``masking'' in order to examine on
940940
particular bits of a value. So for example if we want to
@@ -950,18 +950,18 @@ true.
950950

951951
We use the following interface for values in the runtime system:
952952

953-
@filebox-include[fancy-c "dupe/values.h"]
954-
@filebox-include[fancy-c "dupe/values.c"]
953+
@filebox-include[fancy-c dupe "values.h"]
954+
@filebox-include[fancy-c dupe "values.c"]
955955

956956
The @tt{main} function remains largely the same although now we use
957957
@tt{val_t} in place of @tt{int64_t}:
958958

959-
@filebox-include[fancy-c "dupe/main.c"]
959+
@filebox-include[fancy-c dupe "main.c"]
960960

961961
And finally, @tt{print_result} is updated to do a case analysis on the
962962
type of the result and print accordingly:
963963

964-
@filebox-include[fancy-c "dupe/print.c"]
964+
@filebox-include[fancy-c dupe "print.c"]
965965

966966
@section{Correctness and testing}
967967

0 commit comments

Comments
 (0)