shorten kws

main
Matthew Butterick 3 years ago
parent ec0a9b536a
commit bea91f647d

@ -16,8 +16,8 @@ that will eventually be the tail of the attrs in every atomized quad.
|#
(define-pass (atomize q)
#:precondition quad?
#:postcondition (list-of quad?)
#:pre quad?
#:post (list-of quad?)
(match (quad-elems q)
[(cons str _)
(for/list ([c (in-string str)])

@ -16,14 +16,16 @@
(make-compiler (append (compiler-passes c) passes)))
(define-syntax-rule (define-pass (PASS-NAME ARG OTHER-ARG ...)
#:precondition PRECOND-PROC
#:postcondition POSTCOND-PROC
#:pre PRECOND-PROC
#:post POSTCOND-PROC
EXPRS ...)
(define PASS-NAME
(make-compiler (list (λ (ARG OTHER-ARG ...)
(unless (PRECOND-PROC ARG)
(error 'PASS-NAME (format "precondition failed: ~a for value ~v" 'PRECOND-PROC ARG)))
(define res (let () EXPRS ...))
(unless (POSTCOND-PROC res)
(error 'PASS-NAME (format "postcondition failed: ~a for value ~v" 'POSTCOND-PROC res)))
res)))))
(make-compiler
(list (procedure-rename
(λ (ARG OTHER-ARG ...)
(unless (PRECOND-PROC ARG)
(raise-argument-error 'PASS-NAME (format "~a" 'PRECOND-PROC) ARG))
(define res (let () EXPRS ...))
(unless (POSTCOND-PROC res)
(raise-argument-error 'PASS-NAME (format "~a" 'POSTCOND-PROC) res))
res) 'PASS-NAME)))))

@ -10,8 +10,8 @@
(provide (all-defined-out))
(define-pass (make-drawing-insts qs)
#:precondition (list-of has-position?)
#:postcondition (list-of $drawing-inst?)
#:pre (list-of has-position?)
#:post (list-of $drawing-inst?)
(flatten
(list ($doc 'start) ($page 'start)
(for/list ([q (in-list qs)])
@ -24,8 +24,8 @@
(define valid-tokens '(doc-start doc-end page-start page-end text move))
(define-pass (stackify xs)
#:precondition (λ (xs) (and (list? xs) (andmap $drawing-inst? xs)))
#:postcondition string?
#:pre (list-of $drawing-inst?)
#:post string?
(define move-points (map $move-posn (filter $move? xs)))
(define xmax (add1 (apply max (map $point-x move-points))))
(define ymax (add1 (apply max (map $point-y move-points))))

@ -36,8 +36,8 @@
(rect-contains-point? outer ($point (max-x inner) (max-y inner)))))
(define-pass (layout qs)
#:precondition (list-of has-no-position?)
#:postcondition (list-of has-position?)
#:pre (list-of has-no-position?)
#:post (list-of has-position?)
(define frame ($rect ($point 0 0) ($size (current-wrap-width) 30)))
(define (quad-fits? q posn)
(define q-size (size q))

@ -10,8 +10,8 @@
racket/match)
(define-pass (bootstrap x)
#:precondition values
#:postcondition quad?
#:pre values
#:post quad?
(match x
[(or (? quad? q) (list (? quad? q))) q]
[(and (list (? quad?) ...) qs) (make-quad #:elems qs)]

Loading…
Cancel
Save