Skip to content

Commit 18539ea

Browse files
committed
Closes #138.
1 parent 957331d commit 18539ea

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

langs/a86/ast.rkt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@
318318
(check-unique-label-decls p)
319319
(check-label-targets-declared p)
320320
(check-has-initial-label p)
321+
(check-initial-label-global p)
321322
;; anything else?
322323
p))
323324

@@ -383,3 +384,11 @@
383384
(define (check-has-initial-label asm)
384385
(unless (findf Label? asm)
385386
(error 'prog "no initial label found")))
387+
388+
;; Asm -> Void
389+
(define (check-initial-label-global asm)
390+
(match (findf Label? asm)
391+
[(Label init)
392+
(unless (member init (map (lambda (i) (match i [(Global l) l]))
393+
(filter Global? asm)))
394+
(error 'prog "initial label undeclared as global: ~v" init))]))

langs/a86/test/errors.rkt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,12 @@
2020
(check-not-exn (thunk (Add 'rax (sub1 (expt 2 32)))))
2121
(check-exn exn:fail? (thunk (Sub 'rax (expt 2 32))))
2222
(check-not-exn (thunk (Sub 'rax (sub1 (expt 2 32)))))
23+
24+
;; Check prog
25+
(check-exn exn:fail? (thunk (prog (Ret))))
26+
(check-exn exn:fail? (thunk (prog (Label 'start) (Ret))))
27+
(check-exn exn:fail? (thunk (prog (Global 'foo) (Label 'start) (Label 'foo) (Ret))))
28+
(check-not-exn (thunk (prog (Global 'start) (Label 'start) (Ret))))
29+
(check-not-exn (thunk (prog (Label 'start) (Ret) (Global 'start))))
30+
31+

0 commit comments

Comments
 (0)