From 1c770e7cfd1dddeb728a0ce9fa30955cf2c6b0f0 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Tue, 16 Feb 2016 16:34:21 -0800 Subject: [PATCH] foo works --- quad/quad/foo.rkt | 14 +++++++++++--- quad/quad/foo2.rkt | 3 +++ quad/quad/lang/quad.rkt | 8 ++------ quad/quad/main.rkt | 2 +- quad/quad/quads.rkt | 4 ++-- quad/quad/quick-sample.rkt | 6 ++++-- quad/quad/quick-test.rkt | 4 ++-- quad/quad/test-quadlangmod.rkt | 3 +++ quad/quad/test-render.rkt | 2 ++ quad/quad/utils.rkt | 5 ++--- 10 files changed, 32 insertions(+), 19 deletions(-) create mode 100644 quad/quad/foo2.rkt create mode 100644 quad/quad/test-quadlangmod.rkt create mode 100644 quad/quad/test-render.rkt diff --git a/quad/quad/foo.rkt b/quad/quad/foo.rkt index 2a1978ea..f0088963 100644 --- a/quad/quad/foo.rkt +++ b/quad/quad/foo.rkt @@ -1,6 +1,14 @@ #lang racket -(require racket/list) +(module foo quad/lang/quad + (block '(measure 240.0 font "Times New Roman" leading 16.0 vmeasure 300.0 size 13.5 x-align justify x-align-last-line left) (box '(width 15.0)) (block '() (block '(weight bold) "Hot " (word '(size 22.0) "D") "ang, My Fellow Americans.") " This " (block '(no-break #t) "is some truly") " nonsense generated from my typesetting system, which is called Quad. I’m writing this in a source file in DrRacket. When I click [Run], a PDF pops out. Not bad\u200a—\u200aand no LaTeX needed. Quad, however, does use the fancy linebreaking algorithm developed for TeX. (It also includes a faster linebreaking algorithm for when speed is more important than quality.) Of course, it can also handle " (block '(font "Courier") "different fonts,") (block '(style italic) " styles, ") (word '(size 14.0 weight bold) "and sizes-") " within the same line. As you can see, it can also justify paragraphs." (block-break) (box '(width 15.0)) (block '() "“Each horizontal row represents " (box '(color "Red" background "Yellow") "an OS-level thread,") " and the colored dots represent important events in the execution of the program (they are color-coded to distinguish one event type from another). The upper-left blue dot in the timeline represents the future’s creation. The future executes for a brief period (represented by a green bar in the second line) on thread 1, and then pauses to allow the runtime thread to perform a future-unsafe operation.") (column-break) (box '(width 15.0))(block '() "In the Racket implementation, future-unsafe operations fall into one of two categories. A blocking operation halts the evaluation of the future, and will not allow it to continue until it is touched. After the operation completes within touch, the remainder of the future’s work will be evaluated sequentially by the runtime thread. A synchronized operation also halts the future, but the runtime thread may perform the operation at any time and, once completed, the future may continue running in parallel. Memory allocation and JIT compilation are two common examples of synchronized operations." (page-break) "another page")))) -(define (F) - (flatten '(1 2 3))) \ No newline at end of file +(require (prefix-in o: 'foo)) +(require quad quad/quads quad/render) + +(quad? o:out) +(define o:ts (typeset o:out)) +(time (send (new pdf-renderer%) render-to-file o:ts "foo-test.pdf")) +(require "foo2.rkt") +(define ts (typeset out)) +(time (send (new pdf-renderer%) render-to-file o:ts "foo2-test.pdf")) diff --git a/quad/quad/foo2.rkt b/quad/quad/foo2.rkt new file mode 100644 index 00000000..f5760f2e --- /dev/null +++ b/quad/quad/foo2.rkt @@ -0,0 +1,3 @@ +#lang quad + +◊(block '(measure 240.0 font "Times New Roman" leading 16.0 vmeasure 300.0 size 13.5 x-align justify x-align-last-line left) (box '(width 15.0)) (block '() (block '(weight bold) "Hot " (word '(size 22.0) "D") "ang, My Fellow Americans.") " This " (block '(no-break #t) "is some truly") " nonsense generated from my typesetting system, which is called Quad. I’m writing this in a source file in DrRacket. When I click [Run], a PDF pops out. Not bad\u200a—\u200aand no LaTeX needed. Quad, however, does use the fancy linebreaking algorithm developed for TeX. (It also includes a faster linebreaking algorithm for when speed is more important than quality.) Of course, it can also handle " (block '(font "Courier") "different fonts,") (block '(style italic) " styles, ") (word '(size 14.0 weight bold) "and sizes-") " within the same line. As you can see, it can also justify paragraphs." (block-break) (box '(width 15.0)) (block '() "“Each horizontal row represents " (box '(color "Red" background "Yellow") "an OS-level thread,") " and the colored dots represent important events in the execution of the program (they are color-coded to distinguish one event type from another). The upper-left blue dot in the timeline represents the future’s creation. The future executes for a brief period (represented by a green bar in the second line) on thread 1, and then pauses to allow the runtime thread to perform a future-unsafe operation.") (column-break) (box '(width 15.0))(block '() "In the Racket implementation, future-unsafe operations fall into one of two categories. A blocking operation halts the evaluation of the future, and will not allow it to continue until it is touched. After the operation completes within touch, the remainder of the future’s work will be evaluated sequentially by the runtime thread. A synchronized operation also halts the future, but the runtime thread may perform the operation at any time and, once completed, the future may continue running in parallel. Memory allocation and JIT compilation are two common examples of synchronized operations." (page-break) "another page")))) \ No newline at end of file diff --git a/quad/quad/lang/quad.rkt b/quad/quad/lang/quad.rkt index e98de921..be000912 100644 --- a/quad/quad/lang/quad.rkt +++ b/quad/quad/lang/quad.rkt @@ -9,9 +9,5 @@ [(_ expr ...) (replace-context #'(expr ...) #'(#%module-begin - (define src (box null (list expr ...))) - (parameterize ([world:quality-default world:draft-quality]) - (displayln "Typesetting:") - (displayln src) - (define to (time (typeset src))) - (displayln "PDF rendering:"))))])) \ No newline at end of file + (define out (block #f expr ...)) + (provide out)))])) \ No newline at end of file diff --git a/quad/quad/main.rkt b/quad/quad/main.rkt index 86458e58..699e118e 100644 --- a/quad/quad/main.rkt +++ b/quad/quad/main.rkt @@ -198,7 +198,7 @@ doc) -(module+ main +#;(module+ main (require "render.rkt" racket/class profile sugar/debug) (require "samples.rkt") (activate-logger quad-logger) diff --git a/quad/quad/quads.rkt b/quad/quad/quads.rkt index 9cdb0d7b..028f8a55 100644 --- a/quad/quad/quads.rkt +++ b/quad/quad/quads.rkt @@ -10,8 +10,8 @@ [(define write-proc (λ(b port mode) (display (format "(~a)" (string-join (filter-not void? (list (~a (quad-name b)) - (if (and (hash? (quad-attrs b)) (> (length (hash-keys (quad-attrs b))) 0)) (~v (flatten (hash->list (quad-attrs b)))) (void)) - (if (> (length (quad-list b)) 0) (~a (string-join (map ~v (quad-list b)) "")) (void)))) " ")) port)))] + (if (and (hash? (quad-attrs b)) (> (length (hash-keys (quad-attrs b))) 0)) (~v (flatten (hash->list (quad-attrs b)))) "#f") + (if (> (length (quad-list b)) 0) (~a (string-join (map ~v (quad-list b)) " ")) (void)))) " ")) port)))] #:property prop:sequence (λ(q) (quad-list q))) diff --git a/quad/quad/quick-sample.rkt b/quad/quad/quick-sample.rkt index d19e30c9..6e67d896 100644 --- a/quad/quad/quick-sample.rkt +++ b/quad/quad/quick-sample.rkt @@ -1,4 +1,6 @@ #lang typed/racket/base/no-check (require "quads.rkt" racket/file racket/string racket/function racket/list racket/include) -(provide (all-defined-out)) -(include "quick-sample.rktd") \ No newline at end of file +(provide quick-sample) + +(define quick-sample + (block '(measure 240.0 font "Times New Roman" leading 16.0 vmeasure 300.0 size 13.5 x-align justify x-align-last-line left) (box '(width 15.0)) (block '() (block '(weight bold) "Hot " (word '(size 22.0) "D") "ang, My Fellow Americans.") " This " (block '(no-break #t) "is some truly") " nonsense generated from my typesetting system, which is called Quad. I’m writing this in a source file in DrRacket. When I click [Run], a PDF pops out. Not bad\u200a—\u200aand no LaTeX needed. Quad, however, does use the fancy linebreaking algorithm developed for TeX. (It also includes a faster linebreaking algorithm for when speed is more important than quality.) Of course, it can also handle " (block '(font "Courier") "different fonts,") (block '(style italic) " styles, ") (word '(size 14.0 weight bold) "and sizes-") " within the same line. As you can see, it can also justify paragraphs." (block-break) (box '(width 15.0)) (block '() "“Each horizontal row represents " (box '(color "Red" background "Yellow") "an OS-level thread,") " and the colored dots represent important events in the execution of the program (they are color-coded to distinguish one event type from another). The upper-left blue dot in the timeline represents the future’s creation. The future executes for a brief period (represented by a green bar in the second line) on thread 1, and then pauses to allow the runtime thread to perform a future-unsafe operation.") (column-break) (box '(width 15.0))(block '() "In the Racket implementation, future-unsafe operations fall into one of two categories. A blocking operation halts the evaluation of the future, and will not allow it to continue until it is touched. After the operation completes within touch, the remainder of the future’s work will be evaluated sequentially by the runtime thread. A synchronized operation also halts the future, but the runtime thread may perform the operation at any time and, once completed, the future may continue running in parallel. Memory allocation and JIT compilation are two common examples of synchronized operations." (page-break) "another page")))) \ No newline at end of file diff --git a/quad/quad/quick-test.rkt b/quad/quad/quick-test.rkt index 1aa0b5f5..7db06835 100644 --- a/quad/quad/quick-test.rkt +++ b/quad/quad/quick-test.rkt @@ -1,10 +1,10 @@ #lang racket/base (require "main.rkt" "world.rkt" "quick-sample.rkt" - "render.rkt" racket/class) + "render.rkt" racket/class quad/quads) (parameterize ([world:quality-default world:draft-quality]) (displayln "Untyped Quad") (displayln "Typesetting:") - (define to (time (typeset (quick-sample)))) + (define to (time (typeset (dynamic-require "foo.rkt" 'ts)))) (displayln "PDF rendering:") (time (send (new pdf-renderer%) render-to-file to "quick-test-untyped.pdf"))) \ No newline at end of file diff --git a/quad/quad/test-quadlangmod.rkt b/quad/quad/test-quadlangmod.rkt new file mode 100644 index 00000000..60404f27 --- /dev/null +++ b/quad/quad/test-quadlangmod.rkt @@ -0,0 +1,3 @@ +#lang quad + +◊block[#f]{hi there everyone} \ No newline at end of file diff --git a/quad/quad/test-render.rkt b/quad/quad/test-render.rkt new file mode 100644 index 00000000..f1056a76 --- /dev/null +++ b/quad/quad/test-render.rkt @@ -0,0 +1,2 @@ +#lang racket +(require "test-quadlangmod.rkt") \ No newline at end of file diff --git a/quad/quad/utils.rkt b/quad/quad/utils.rkt index 60188132..221042c6 100644 --- a/quad/quad/utils.rkt +++ b/quad/quad/utils.rkt @@ -77,9 +77,9 @@ ;; pushes attributes down from parent quads to children, ;; resulting in a flat list of quads. -;; input is often large, so macro allows us to avoid allocation (provide flatten-quad) -(define-syntax-rule (flatten-quad q) +(require sugar/debug) +(define (flatten-quad q) ; (quad? . -> . quads?) (flatten (let loop ([x q][parent #f]) @@ -98,7 +98,6 @@ ;; input is often large, so macro allows us to avoid allocation (define+provide (split-quad q) ;(quad? . -> . quads?) - (displayln q) (letrec ([do-explode (λ(x [parent #f]) (cond [(quad? x)