|
5 | 5 | "../syntax/types.rkt") |
6 | 6 |
|
7 | 7 | (provide progs->batch ; (Listof Expr) -> Batch |
8 | | - batch->progs ; Batch -> *(or (Listof Root) (Vectorof Root)) -> (Listof Expr) |
| 8 | + batch->progs ; Batch -> ?(or (Listof Root) (Vectorof Root)) -> (Listof Expr) |
9 | 9 | (struct-out batch) |
10 | 10 | (struct-out batchref) ; temporarily for patch.rkt |
11 | 11 | (struct-out mutable-batch) ; temporarily for patch.rkt |
| 12 | + expr-recurse ; Expr -> (Expr -> ?) -> Expr |
12 | 13 | batch-length ; Batch -> Integer |
13 | 14 | batch-ref ; Batch -> Idx -> Expr |
14 | 15 | deref ; Batchref -> Expr |
15 | 16 | batch-replace ; Batch -> (Expr<Batchref> -> Expr<Batchref>) -> Batch |
16 | 17 | egg-nodes->batch ; Nodes -> Spec-maps -> Batch -> (Listof Batchref) |
17 | | - batchref->expr ; Batchref -> Expr |
18 | | - batch-remove-zombie ; Batch -> *(Vectorof Root) -> Batch |
19 | | - mutable-batch-munge! ; Mutable-batch -> Root |
| 18 | + debatchref ; Batchref -> Expr |
| 19 | + batch-remove-zombie ; Batch -> ?(Vectorof Root) -> Batch |
| 20 | + mutable-batch-munge! ; Mutable-batch -> Expr -> Root |
20 | 21 | mutable-batch->batch ; Mutable-batch -> Batch |
21 | 22 | make-mutable-batch ; Mutable-batch |
22 | | - mutable-batch-devour-batchref! ; Mutable-batch -> Batchref -> Idx |
23 | 23 | batch->mutable-batch ; Batch -> Mutable-batch |
24 | | - batch-push!) ; Mutable-batch -> Expr -> Idx |
| 24 | + batch-copy-mutable-nodes! ; Batch -> Mutable-batch -> Void |
| 25 | + batch-push!) ; Mutable-batch -> Node -> Idx |
25 | 26 |
|
26 | 27 | ;; This function defines the recursive structure of expressions |
27 | 28 | (define (expr-recurse expr f) |
|
64 | 65 | (batch-restore-index b) |
65 | 66 | (reverse (batch-vars b)))) |
66 | 67 |
|
| 68 | +(define (batch-copy-mutable-nodes! b mb) |
| 69 | + (set-batch-nodes! b (list->vector (reverse (mutable-batch-nodes mb))))) |
| 70 | + |
67 | 71 | (struct batchref (batch idx)) |
68 | 72 |
|
69 | 73 | (define (deref x) |
70 | 74 | (match-define (batchref b idx) x) |
71 | 75 | (expr-recurse (vector-ref (batch-nodes b) idx) (lambda (ref) (batchref b ref)))) |
72 | 76 |
|
73 | | -(define (batchref->expr x) |
| 77 | +(define (debatchref x) |
74 | 78 | (match-define (batchref b idx) x) |
75 | 79 | (batch-ref b idx)) |
76 | 80 |
|
|
96 | 100 | (batch-push! b (expr-recurse prog munge))) |
97 | 101 | (munge expr)) |
98 | 102 |
|
99 | | -(define (mutable-batch-devour-batchref! b ref) |
100 | | - (match-define (batchref b* idx) ref) |
101 | | - (define nodes* (batch-nodes b*)) |
102 | | - (define (munge idx) |
103 | | - (batch-push! b (expr-recurse (vector-ref nodes* idx) munge))) |
104 | | - (munge idx)) |
105 | | - |
106 | 103 | (define (batch->progs b [roots (batch-roots b)]) |
107 | 104 | (define exprs (make-vector (batch-length b))) |
108 | 105 | (for ([node (in-vector (batch-nodes b))] |
|
0 commit comments