|
221 | 221 |
|
222 | 222 | ;; Converts a patch to full alt with valid history |
223 | 223 | (define (reconstruct! alts) |
224 | | - (define reconstruct-batch (make-batch)) |
225 | | - (define reconstruct-batch-mutable (make-mutable-batch)) |
226 | | - |
| 224 | + (define reconstruct-batch (make-mutable-batch)) |
227 | 225 | ;; extracts the base expressions of a patch as a batchref |
228 | 226 | (define (get-starting-expr altn) |
229 | 227 | (match* ((alt-event altn) (alt-prevs altn)) |
230 | | - [((list 'patch expr _) _) expr] |
| 228 | + [((list 'patch expr _) _) expr] ; here original Expr can be pulled as well |
231 | 229 | [(_ (list prev)) (get-starting-expr prev)] |
232 | 230 | [(_ _) (error 'get-starting-spec "unexpected: ~a" altn)])) |
233 | 231 |
|
234 | 232 | ;; takes a patch and converts it to a full alt |
235 | | - (define (reconstruct-alt-batch altn loc0 orig) |
236 | | - (let loop ([altn altn]) |
237 | | - (match-define (alt _ event prevs _) altn) |
238 | | - (match event |
239 | | - [(list 'patch _ _) orig] |
240 | | - [_ |
241 | | - (define event* |
242 | | - (match event |
243 | | - [(list 'taylor name var) (list 'taylor loc0 name var)] |
244 | | - [(list 'rr input proof soundiness) (list 'rr loc0 input proof soundiness)] |
245 | | - [(list 'simplify input proof soundiness) (list 'simplify loc0 input proof soundiness)])) |
246 | | - (define idx |
247 | | - (location-do-batch loc0 reconstruct-batch-mutable (alt-expr orig) (alt-expr altn))) |
248 | | - (define expr* (batchref reconstruct-batch idx)) |
249 | | - (alt expr* event* (list (loop (first prevs))) (alt-preprocessing orig))]))) |
250 | | - |
251 | | - (define batchified-out |
252 | | - (reap [sow] |
253 | | - (for ([altn (in-list alts)]) ;; does not have preproc |
254 | | - (define start-expr (get-starting-expr altn)) ; batchref |
255 | | - (for ([full-altn (in-list (^next-alts^))]) |
256 | | - (define expr (alt-expr full-altn)) |
257 | | - (for ([loc (in-list (get-locations expr start-expr))]) |
258 | | - (sow (reconstruct-alt-batch altn loc full-altn))))))) |
259 | | - (batch-copy-mutable-nodes! reconstruct-batch reconstruct-batch-mutable) |
260 | | - |
261 | | - (define (rebuild-alts x) |
262 | | - (match-define (alt expr event prevs preprocessing) x) |
263 | | - (match (batchref? expr) |
264 | | - [#t (alt (batchref->expr expr) event (map rebuild-alts prevs) preprocessing)] |
265 | | - [#f (alt expr event (map rebuild-alts prevs) preprocessing)])) |
266 | | - (set! batchified-out (map rebuild-alts batchified-out)) |
267 | | - |
268 | | - ;; takes a patch and converts it to a full alt |
269 | | - #; |
270 | 233 | (define (reconstruct-alt altn loc0 orig) |
271 | 234 | (let loop ([altn altn]) |
272 | 235 | (match-define (alt _ event prevs _) altn) |
|
281 | 244 | (define expr* (location-do loc0 (alt-expr orig) (const (batchref->expr (alt-expr altn))))) |
282 | 245 | (alt expr* event* (list (loop (first prevs))) (alt-preprocessing orig))]))) |
283 | 246 |
|
284 | | - #;(define out |
285 | | - (reap [sow] |
286 | | - (for ([altn (in-list alts)]) ;; does not have preproc |
287 | | - (define start-expr (get-starting-expr altn)) |
288 | | - (if start-expr |
289 | | - (for ([full-altn (in-list (^next-alts^))]) |
290 | | - (define expr (alt-expr full-altn)) |
291 | | - (for ([loc (in-list (get-locations expr start-expr))]) |
292 | | - (sow (reconstruct-alt altn loc full-altn)))) |
293 | | - ; altn is a full alt (probably iter 0 simplify) |
294 | | - (sow altn))))) |
295 | | - |
296 | | - (^patched^ batchified-out) |
297 | | - #;(for ([p (in-list out)] |
298 | | - [p* (in-list batchified-out)]) |
299 | | - (printf "\tp=~a\n" p) |
300 | | - (printf "\tp*=~a\n\n" p*)) |
| 247 | + (^patched^ (reap [sow] |
| 248 | + (for ([altn (in-list alts)]) ;; does not have preproc |
| 249 | + (define start-expr (get-starting-expr altn)) |
| 250 | + (for ([full-altn (in-list (^next-alts^))]) |
| 251 | + (define expr (alt-expr full-altn)) |
| 252 | + (for ([loc (in-list (get-locations expr start-expr))]) |
| 253 | + (sow (reconstruct-alt altn loc full-altn))))))) |
301 | 254 |
|
302 | 255 | (void)) |
303 | 256 |
|
|
0 commit comments