|
3 | 3 | (require racket/runtime-path) |
4 | 4 | (require "../utils/common.rkt" |
5 | 5 | "../utils/errors.rkt" |
| 6 | + "../config.rkt" |
6 | 7 | "../core/rules.rkt" |
7 | 8 | "matcher.rkt" |
8 | 9 | "types.rkt" |
|
25 | 26 | ;; Operator sets |
26 | 27 | (contract-out ;; Platforms |
27 | 28 | [platform? (-> any/c boolean?)] |
28 | | - [platform-name (-> platform? any/c)] |
29 | 29 | [platform-if-cost (-> platform? any/c)] |
30 | 30 | [platform-reprs (-> platform? (listof representation?))] |
31 | 31 | [platform-impls (-> platform? (listof symbol?))] |
|
54 | 54 | ;;; |
55 | 55 | ;;; A small API is provided for platforms for querying the supported |
56 | 56 | ;;; operators, operator implementations, and representation conversions. |
57 | | -(struct platform (name [if-cost #:mutable] representations implementations representation-costs) |
| 57 | +(struct platform ([if-cost #:mutable] representations implementations representation-costs) |
58 | 58 | #:name $platform |
59 | 59 | #:constructor-name create-platform |
60 | 60 | #:methods gen:custom-write |
61 | 61 | [(define (write-proc p port mode) |
62 | | - (if (platform-name p) |
63 | | - (fprintf port "#<platform:~a>" (platform-name p)) |
64 | | - (fprintf port "#<platform>")))]) |
| 62 | + (fprintf port "#<platform>"))]) |
65 | 63 |
|
66 | 64 | ;; Active platform |
67 | 65 | (define *active-platform* (make-parameter #f)) |
|
72 | 70 | [representations (hash-copy (platform-representations platform))] |
73 | 71 | [implementations (hash-copy (platform-implementations platform))])) |
74 | 72 |
|
75 | | -(define (make-empty-platform name) |
| 73 | +(define (make-empty-platform) |
76 | 74 | (define reprs (make-hash)) |
77 | 75 | (define repr-costs (make-hash)) |
78 | 76 | (define impls (make-hash)) |
79 | | - (create-platform name #f reprs impls repr-costs)) |
| 77 | + (create-platform #f reprs impls repr-costs)) |
80 | 78 |
|
81 | 79 | (define (platform-register-if-cost! platform #:cost cost) |
82 | 80 | (set-platform-if-cost! platform (platform/parse-if-cost cost))) |
|
88 | 86 | (when (hash-has-key? reprs (representation-name repr)) |
89 | 87 | (raise-herbie-error "Duplicate representation ~a in platform ~a" |
90 | 88 | (representation-name repr) |
91 | | - (platform-name platform))) |
| 89 | + (*platform-name*))) |
92 | 90 | ; Update tables |
93 | 91 | (hash-set! reprs (representation-name repr) repr) |
94 | 92 | (hash-set! repr-costs (representation-name repr) cost)) |
95 | 93 |
|
96 | 94 | (define (platform-register-implementation! platform impl) |
97 | 95 | (unless impl |
98 | | - (raise-herbie-error "Platform ~a missing implementation" (platform-name platform))) |
| 96 | + (raise-herbie-error "Platform ~a missing implementation" (*platform-name*))) |
99 | 97 | ; Reprs check |
100 | 98 | (define reprs (platform-representations platform)) |
101 | 99 | (define otype (context-repr (operator-impl-ctx impl))) |
102 | 100 | (define itype (context-var-reprs (operator-impl-ctx impl))) |
103 | 101 | (define impl-reprs (map representation-name (remove-duplicates (cons otype itype)))) |
104 | 102 | (unless (andmap (curry hash-has-key? reprs) impl-reprs) |
105 | 103 | (raise-herbie-error "Platform ~a missing representation of ~a implementation" |
106 | | - (platform-name platform) |
| 104 | + (*platform-name*) |
107 | 105 | (operator-impl-name impl))) |
108 | 106 | ; Cost check |
109 | 107 | (define impl-cost (operator-impl-cost impl)) |
|
114 | 112 | (when (hash-has-key? impls (operator-impl-name impl)) |
115 | 113 | (raise-herbie-error "Impl ~a is already registered in platform ~a" |
116 | 114 | (operator-impl-name impl) |
117 | | - (platform-name platform))) |
| 115 | + (*platform-name*))) |
118 | 116 | ; Update table |
119 | 117 | (hash-set! impls (operator-impl-name impl) impl)) |
120 | 118 |
|
|
151 | 149 | (raise-herbie-error "Could not find support for ~a representation: ~a in a platform ~a" |
152 | 150 | name |
153 | 151 | (string-join (map ~s (hash-keys reprs)) ", ") |
154 | | - (platform-name platform)))) |
| 152 | + (*platform-name*)))) |
155 | 153 |
|
156 | 154 | (define (repr-exists? name) |
157 | 155 | (define platform (*active-platform*)) |
|
199 | 197 | (hash-ref impls |
200 | 198 | impl-name |
201 | 199 | (lambda () |
202 | | - (error 'impl-info |
203 | | - "unknown impl '~a in platform ~a" |
204 | | - impl-name |
205 | | - (platform-name (*active-platform*)))))) |
| 200 | + (error 'impl-info "unknown impl '~a in platform ~a" impl-name (*platform-name*))))) |
206 | 201 | (case field |
207 | 202 | [(name) (operator-impl-name impl)] |
208 | 203 | [(vars) (context-vars (operator-impl-ctx impl))] |
|
377 | 372 | (define repr-costs (platform-representation-costs platform)) |
378 | 373 | (define if-cost (platform-if-cost platform)) |
379 | 374 |
|
380 | | - (printf "Platform: ~a;\n if-cost: ~a;\n\n" (platform-name platform) if-cost) |
| 375 | + (printf "Platform;\n if-cost: ~a;\n\n" if-cost) |
381 | 376 |
|
382 | 377 | (printf "Representations:\n") |
383 | 378 | (define reprs-data |
|
0 commit comments