Skip to content

Commit c6e6093

Browse files
committed
Merge branch 'main' of github.com:cmsc430/www
2 parents 885b352 + 6553639 commit c6e6093

File tree

17 files changed

+669
-101
lines changed

17 files changed

+669
-101
lines changed

.github/workflows/langs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ jobs:
2929
- name: Version info
3030
run: |
3131
nasm --version
32-
gcc --version
32+
gcc --version
3333
- name: Install langs package
3434
run: raco pkg install langs/
3535
- name: Run tests
3636
run: |
37-
export LINK_DIR=/usr/lib/x86_64-linux-gnu
3837
raco test -p langs
38+
raco test -c outlaw

langs/a86/ast.rkt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
[m (identifier? #'m) #'(λ (x ...) (%Name (current-annotation) x ...))]
162162
[(m x ...) #'(%Name (current-annotation) x ...)])))
163163
(struct %Name instruction (x ...)
164+
#:reflection-name 'Name
164165
#:transparent
165166
#:guard guard
166167
#:methods gen:equal+hash
@@ -169,14 +170,36 @@
169170
(struct->vector i2))))
170171
(define hash-proc (λ (i hash) (hash (struct->vector i))))
171172
(define hash2-proc (λ (i hash) (hash (struct->vector i))))]
173+
174+
#:property prop:custom-print-quotable 'never
172175
#:methods gen:custom-write
173176
[(define write-proc
174-
(make-constructor-style-printer
177+
(instr-print 'Name)
178+
#;(make-constructor-style-printer
175179
(lambda (obj) 'Name)
176180
(lambda (obj)
177181
(rest (rest (vector->list (struct->vector obj)))))))])
178182
(define Name? %Name?)))]))
179183

184+
(define (instr-print type)
185+
(lambda (instr port mode)
186+
(if (number? mode)
187+
(write-string "(" port)
188+
(write-string "#(struct:" port))
189+
(write-string (symbol->string type) port)
190+
(let ([recur (case mode
191+
[(#t) write]
192+
[(#f) display]
193+
[else (lambda (p port) (print p port mode))])])
194+
(for-each (lambda (e)
195+
(write-string " " port)
196+
(recur e port))
197+
(rest (rest (vector->list (struct->vector instr))))))
198+
(if (number? mode)
199+
(write-string ")" port)
200+
(write-string ")" port))))
201+
202+
180203
(instruct Text () check:none)
181204
(instruct Data () check:none)
182205

langs/info.rkt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,12 @@
22
(define version "1.0")
33
(define collection 'multi)
44
(define deps (list))
5+
6+
;; Outlaw is omitted here because it depends on libraries that are a pain
7+
;; to ensure are set up properly and we don't want students to see failing
8+
;; tests at the beginning of the semester, nor do we want to get into
9+
;; setting up libraries only needed in the last week and only if you
10+
;; actually care to run Outlaw.
11+
12+
;; To test outlaw you should do an explicit: raco test -c outlaw
13+
(define test-omit-paths (list "outlaw"))

langs/outlaw/Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# ld will always choose .dylib over .a to link, so either rename or remove
44
# the .dylib versions.
55

6-
76
UNAME := $(shell uname)
87
.PHONY: test
98

@@ -62,7 +61,7 @@ runtime.o: $(objs)
6261
ld -r $(objs) -o runtime.o
6362

6463
%.run: %.o runtime.o
65-
gcc $(link_opts) -lunistring runtime.o $< -o $@
64+
gcc $(link_opts) runtime.o $< -lunistring -o $@
6665

6766
.c.o:
6867
gcc $(include) -fPIC -c -g -o $@ $<
@@ -79,5 +78,11 @@ stdlib.s: stdlib.rkt
7978
clean:
8079
rm *.o *.s *.run outlaw.rkt
8180

81+
outlaw2.s: outlaw.rkt outlaw.run
82+
cat outlaw.rkt | ./outlaw.run > outlaw2.s
83+
84+
self-host-test: outlaw.s outlaw2.s
85+
cmp -s outlaw.s outlaw2.s
86+
8287
test: example.run
8388
@test "$(shell ./example.run)" = "$(shell racket example.rkt)"

langs/outlaw/a.rkt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#lang racket
2+
(provide a)
3+
(require "b.rkt")
4+
5+
(define (a x)
6+
(+ (b x) (b x)))
7+
8+
(a 10)

langs/outlaw/a86/ast.rkt

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@
4848
'()
4949
xs))
5050

51+
(define registers
52+
'(cl eax rax rbx rcx rdx rbp rsp rsi rdi r8 r9 r10 r11 r12 r13 r14 r15))
53+
54+
;; Any -> Boolean
5155
(define (register? x)
52-
(and (memq x '(cl eax rax rbx rcx rdx rbp rsp rsi rdi r8 r9 r10 r11 r12 r13 r14 r15))
53-
#t))
56+
(and (memq x registers) #t))
5457

58+
;; Any -> Boolean
5559
(define (exp? x)
5660
(or (Offset? x)
5761
(and (Plus? x)
@@ -62,39 +66,15 @@
6266

6367
(define offset? Offset?)
6468

69+
;; Any -> Boolean
6570
(define (label? x)
6671
(and (symbol? x)
6772
(not (register? x))))
6873

74+
;; Any -> Boolean
6975
(define (instruction? x)
70-
(or (Text? x)
71-
(Data? x)
72-
(Global? x)
73-
(Label? x)
74-
(Extern? x)
75-
(Call? x)
76-
(Ret? x)
77-
(Mov? x)
78-
(Add? x)
79-
(Sub? x)
80-
(Cmp? x)
81-
(Jmp? x)
82-
(Je? x)
83-
(Jne? x)
84-
(Jl? x)
85-
(Jle? x)
86-
(Jg? x)
87-
(Jge? x)
88-
(And? x)
89-
(Or? x)
90-
(Xor? x)
91-
(Sal? x)
92-
(Sar? x)
93-
(Push? x)
94-
(Pop? x)
95-
(Lea? x)
96-
(Div? x)
97-
;(Comment? x)
98-
(Equ? x)
99-
(Dd? x)
100-
(Dq? x)))
76+
(ormap (λ (p) (p x))
77+
(list Text? Data? Global? Label? Extern? Call? Ret? Mov?
78+
Add? Sub? Cmp? Jmp? Je? Jne? Jl? Jle? Jg? Jge?
79+
And? Or? Xor? Sal? Sar? Push? Pop? Lea? Div? Equ?
80+
Dd? Dq?)))

langs/outlaw/a86/printer.rkt

Lines changed: 55 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
[_
3333
(λ (s)
3434
(if (current-shared?)
35-
(if (memq s (unbox external-labels))
36-
; hack for ELF64 shared libraries in service of
37-
; calling external functions in asm-interp
38-
(string-append (symbol->string s) " wrt ..plt")
39-
(symbol->string s))
40-
(symbol->string s)))]))
35+
(if (memq s (unbox external-labels))
36+
; hack for ELF64 shared libraries in service of
37+
; calling external functions in asm-interp
38+
(string-append (symbol->string s) " wrt ..plt")
39+
(symbol->string s))
40+
(symbol->string s)))]))
4141

4242
;; (U Label Reg) -> String
4343
(define (jump-target->string t)
@@ -70,7 +70,6 @@
7070

7171
(define tab (make-string 8 #\space))
7272

73-
7473
(define external-labels (box '()))
7574

7675
(define (external-label-shared? x)
@@ -85,16 +84,16 @@
8584
;; when 1) ELF, 2) building a shared object
8685
[(Offset (? external-label-shared? l) i)
8786
(string-append tab "mov "
88-
(arg->string a1) ", "
89-
"[" (label-symbol->string l) " + " (number->string i) " wrt ..gotpc]\n"
90-
tab "mov "
91-
(arg->string a1) ", "
92-
"[" (arg->string a1) "]")]
87+
(arg->string a1) ", "
88+
"[" (label-symbol->string l) " + " (number->string i) " wrt ..gotpc]\n"
89+
tab "mov "
90+
(arg->string a1) ", "
91+
"[" (arg->string a1) "]")]
9392
;; the usual case
9493
[_
9594
(string-append tab "mov "
96-
(arg->string a1) ", "
97-
(arg->string a2))]))
95+
(arg->string a1) ", "
96+
(arg->string a2))]))
9897

9998
;; Instruction -> String
10099
(define (instr->string i)
@@ -105,89 +104,89 @@
105104
[(Label l) (string-append (label-symbol->string l) ":")]
106105
[(Global x) (string-append tab "global " (label-symbol->string x))]
107106
[(Extern l) (let ((r (string-append tab "extern " (label-symbol->string l))))
108-
(begin
109-
(set-box! external-labels (cons l (unbox external-labels)))
110-
r))]
107+
(begin
108+
(set-box! external-labels (cons l (unbox external-labels)))
109+
r))]
111110
[(Mov a1 a2)
112111
(mov->string a1 a2)]
113112
[(Add a1 a2)
114113
(string-append tab "add "
115-
(arg->string a1) ", "
116-
(arg->string a2))]
114+
(arg->string a1) ", "
115+
(arg->string a2))]
117116
[(Sub a1 a2)
118117
(string-append tab "sub "
119-
(arg->string a1) ", "
120-
(arg->string a2))]
118+
(arg->string a1) ", "
119+
(arg->string a2))]
121120
[(Cmp a1 a2)
122121
(string-append tab "cmp "
123-
(arg->string a1) ", "
124-
(arg->string a2))]
122+
(arg->string a1) ", "
123+
(arg->string a2))]
125124
[(Sal a1 a2)
126125
(string-append tab "sal "
127-
(arg->string a1) ", "
128-
(arg->string a2))]
126+
(arg->string a1) ", "
127+
(arg->string a2))]
129128
[(Sar a1 a2)
130129
(string-append tab "sar "
131-
(arg->string a1) ", "
132-
(arg->string a2))]
130+
(arg->string a1) ", "
131+
(arg->string a2))]
133132
[(And a1 a2)
134133
(string-append tab "and "
135-
(arg->string a1) ", "
136-
(arg->string a2))]
134+
(arg->string a1) ", "
135+
(arg->string a2))]
137136
[(Or a1 a2)
138137
(string-append tab "or "
139-
(arg->string a1) ", "
140-
(arg->string a2))]
138+
(arg->string a1) ", "
139+
(arg->string a2))]
141140
[(Xor a1 a2)
142141
(string-append tab "xor "
143-
(arg->string a1) ", "
144-
(arg->string a2))]
142+
(arg->string a1) ", "
143+
(arg->string a2))]
145144
[(Jmp l)
146145
(string-append tab "jmp "
147-
(jump-target->string l))]
146+
(jump-target->string l))]
148147
[(Je l)
149148
(string-append tab "je "
150-
(jump-target->string l))]
149+
(jump-target->string l))]
151150
[(Jne l)
152151
(string-append tab "jne "
153-
(jump-target->string l))]
152+
(jump-target->string l))]
154153
[(Jl l)
155154
(string-append tab "jl "
156-
(jump-target->string l))]
155+
(jump-target->string l))]
157156
[(Jle l)
158157
(string-append tab "jle "
159-
(jump-target->string l))]
158+
(jump-target->string l))]
160159
[(Jg l)
161160
(string-append tab "jg "
162-
(jump-target->string l))]
161+
(jump-target->string l))]
163162
[(Jge l)
164163
(string-append tab "jge "
165-
(jump-target->string l))]
164+
(jump-target->string l))]
166165
[(Call l)
167166
(string-append tab "call "
168-
(jump-target->string l))]
167+
(jump-target->string l))]
169168
[(Push a)
170169
(string-append tab "push "
171-
(arg->string a))]
170+
(arg->string a))]
172171
[(Pop r)
173172
(string-append tab "pop "
174-
(reg->string r))]
173+
(reg->string r))]
175174
[(Lea d (? offset? x))
176175
(string-append tab "lea "
177-
(arg->string d) ", "
178-
(arg->string x))]
176+
(arg->string d) ", "
177+
(arg->string x))]
179178
[(Lea d x)
180179
(string-append tab "lea "
181-
(arg->string d) ", [rel "
182-
(exp->string x) "]")]
180+
(arg->string d) ", [rel "
181+
(exp->string x) "]")]
183182
[(Div r)
184183
(string-append tab "div "
185-
(arg->string r))]
184+
(arg->string r))]
186185
[(Equ x c)
187186
(string-append tab
188-
(symbol->string x)
189-
" equ "
190-
(number->string c))]
187+
(symbol->string x)
188+
" equ "
189+
(number->string c))]
191190

192191
[(Dd x)
193192
(string-append tab "dd " (arg->string x))]
@@ -208,14 +207,12 @@
208207
(match (findf Label? a)
209208
[(Label g)
210209
(string-append
211-
tab "global " (label-symbol->string g) "\n"
212-
tab "default rel\n"
213-
tab "section .text\n"
214-
(instrs->string a))]
210+
tab "global " (label-symbol->string g) "\n"
211+
tab "default rel\n"
212+
tab "section .text\n"
213+
(instrs->string a))]
215214
[_
216-
(instrs->string a)
217-
#;
218-
(error "program does not have an initial label")])))
215+
(instrs->string a)])))
219216

220217
(define (asm-display a)
221218
(begin

langs/outlaw/b.rkt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#lang racket
2+
(provide b)
3+
(require "c.rkt")
4+
5+
(define (b x)
6+
(add1 (c x)))

langs/outlaw/c.rkt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#lang racket
2+
(provide c)
3+
(define (c x)
4+
(+ x 5))

langs/outlaw/combine.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
(match fs
3939
['() (void)]
4040
[(cons f fs)
41-
(displayln (make-string 72 #\;))
41+
(displayln (make-string 12 #\;))
4242
(displayln (string-append ";; " f "\n"))
4343
(print-file f)
4444
(print-files fs)]))

0 commit comments

Comments
 (0)