|
1 | | -#lang mzscheme |
| 1 | +#lang racket/base |
2 | 2 |
|
3 | | - (require mzlib/pretty |
4 | | - mzlib/list |
5 | | - mzlib/class |
6 | | - mred) |
| 3 | + (require racket/pretty |
| 4 | + racket/list |
| 5 | + racket/class |
| 6 | + racket/gui/base) |
7 | 7 |
|
8 | 8 | (provide debug-origin) ;; : syntax [syntax] -> void |
9 | 9 | ;; creates a frame for examining the |
|
23 | 23 |
|
24 | 24 | ;; assume that there aren't any eq? sub structures, only eq? flat stuff (symbols, etc) |
25 | 25 | ;; this is guaranteed by syntax-object->datum/ht |
26 | | - (define range-start-ht (make-hash-table)) |
27 | | - (define range-ht (make-hash-table)) |
| 26 | + (define range-start-ht (make-hasheq)) |
| 27 | + (define range-ht (make-hasheq)) |
28 | 28 | (define original-output-port (current-output-port)) |
29 | 29 | (define (range-pretty-print-pre-hook x v) |
30 | | - (hash-table-put! range-start-ht x (send output-text last-position))) |
| 30 | + (hash-set! range-start-ht x (send output-text last-position))) |
31 | 31 | (define (range-pretty-print-post-hook x v) |
32 | | - (hash-table-put! range-ht x |
33 | | - (cons |
34 | | - (cons |
35 | | - (hash-table-get range-start-ht x) |
36 | | - (send output-text last-position)) |
37 | | - (hash-table-get range-ht x (λ () null))))) |
| 32 | + (hash-set! range-ht x |
| 33 | + (cons |
| 34 | + (cons |
| 35 | + (hash-ref range-start-ht x) |
| 36 | + (send output-text last-position)) |
| 37 | + (hash-ref range-ht x (λ () null))))) |
38 | 38 |
|
39 | 39 | (define (make-modern text) |
40 | 40 | (send text change-style |
|
43 | 43 | (send text last-position))) |
44 | 44 |
|
45 | 45 | (define dummy |
46 | | - (begin (pretty-print (syntax-object->datum original-object) output-port) |
| 46 | + (begin (pretty-print (syntax->datum original-object) output-port) |
47 | 47 | (newline output-port) |
48 | 48 | (parameterize ([current-output-port output-port] |
49 | 49 | [pretty-print-pre-print-hook range-pretty-print-pre-hook] |
|
54 | 54 |
|
55 | 55 | (define ranges |
56 | 56 | (sort |
57 | | - (apply append (hash-table-map range-ht (λ (k vs) (map (λ (v) (cons k v)) vs)))) |
| 57 | + (apply append (hash-map range-ht (λ (k vs) (map (λ (v) (cons k v)) vs)))) |
58 | 58 | (λ (x y) |
59 | 59 | (<= (- (car (cdr x)) (cdr (cdr x))) |
60 | 60 | (- (car (cdr y)) (cdr (cdr y))))))) |
61 | 61 |
|
62 | 62 | (define (show-info stx) |
63 | 63 | (fprintf info-port "datum: ~s\nsource: ~a\nposition: ~s\noffset: ~s\noriginal: ~s\nbound-in-source: ~s\n\n" |
64 | | - (syntax-object->datum stx) |
| 64 | + (syntax->datum stx) |
65 | 65 | (syntax-source stx) |
66 | 66 | (syntax-position stx) |
67 | 67 | (syntax-span stx) |
|
79 | 79 | (fprintf info-port |
80 | 80 | " original? ~a\n datum:\n ~a\n\n" |
81 | 81 | (and (syntax? origin) (syntax-original? origin)) |
82 | | - (and (syntax? origin) (syntax-object->datum origin)))] |
| 82 | + (and (syntax? origin) (syntax->datum origin)))] |
83 | 83 | [else (void)]))) |
84 | 84 |
|
85 | 85 | (for-each |
86 | 86 | (λ (range) |
87 | 87 | (let* ([obj (car range)] |
88 | | - [stx (hash-table-get stx-ht obj)] |
| 88 | + [stx (hash-ref stx-ht obj)] |
89 | 89 | [start (cadr range)] |
90 | 90 | [end (cddr range)]) |
91 | 91 | (when (syntax? stx) |
|
109 | 109 | (send info-text begin-edit-sequence) |
110 | 110 | (send info-text erase) |
111 | 111 | (for-each (λ (rng) |
112 | | - (let ([stx (hash-table-get stx-ht (car rng))]) |
| 112 | + (let ([stx (hash-ref stx-ht (car rng))]) |
113 | 113 | (when (syntax? stx) |
114 | 114 | (show-info stx)))) |
115 | 115 | ranges) |
|
126 | 126 | ;; build-ht : stx -> hash-table |
127 | 127 | ;; the resulting hash-table maps from the each sub-object's to its syntax. |
128 | 128 | (define (syntax-object->datum/ht stx) |
129 | | - (let ([ht (make-hash-table)]) |
| 129 | + (let ([ht (make-hasheq)]) |
130 | 130 | (values (let loop ([stx stx]) |
131 | 131 | (let ([obj (syntax-e stx)]) |
132 | 132 | (cond |
133 | 133 | [(list? obj) |
134 | 134 | (let ([res (map loop obj)]) |
135 | | - (hash-table-put! ht res stx) |
| 135 | + (hash-set! ht res stx) |
136 | 136 | res)] |
137 | 137 | [(pair? obj) |
138 | 138 | (let ([res (cons (loop (car obj)) |
139 | 139 | (loop (cdr obj)))]) |
140 | | - (hash-table-put! ht res stx) |
| 140 | + (hash-set! ht res stx) |
141 | 141 | res)] |
142 | 142 | [(vector? obj) |
143 | 143 | (let ([res (list->vector (map loop (vector->list obj)))]) |
144 | | - (hash-table-put! ht res stx) |
| 144 | + (hash-set! ht res stx) |
145 | 145 | res)] |
146 | 146 | [else |
147 | | - (let ([res (syntax-object->datum stx)]) |
148 | | - (hash-table-put! ht res stx) |
| 147 | + (let ([res (syntax->datum stx)]) |
| 148 | + (hash-set! ht res stx) |
149 | 149 | res)]))) |
150 | 150 | ht))) |
151 | 151 |
|
|
0 commit comments