@@ -65,6 +65,17 @@ bool lexical_scope_is_nested(Nodes scope, Nodes parentMaybe) {
65
65
66
66
bool compare_nodes (Nodes * a , Nodes * b );
67
67
68
+ static Nodes remake_variables (Context * ctx , Nodes old ) {
69
+ IrArena * a = ctx -> rewriter .dst_arena ;
70
+ LARRAY (const Node * , nvars , old .count );
71
+ for (size_t i = 0 ; i < old .count ; i ++ ) {
72
+ const Node * node = old .nodes [i ];
73
+ nvars [i ] = var (a , node -> payload .var .type ? qualified_type_helper (rewrite_node (& ctx -> rewriter , node -> payload .var .type ), false) : NULL , node -> payload .var .name );
74
+ assert (nvars [i ]-> tag == Variable_TAG );
75
+ }
76
+ return nodes (a , old .count , nvars );
77
+ }
78
+
68
79
static const Node * process_op (Context * ctx , NodeClass op_class , String op_name , const Node * node ) {
69
80
IrArena * a = ctx -> rewriter .dst_arena ;
70
81
switch (node -> tag ) {
@@ -156,7 +167,6 @@ static const Node* process_op(Context* ctx, NodeClass op_class, String op_name,
156
167
} else if (compare_nodes (dom_lexical_scope , dst_lexical_scope )) {
157
168
debug_print ("We need to introduce a control() block at %s, pointing at %s\n." , get_abstraction_name (dom -> node ), get_abstraction_name (dst ));
158
169
Controls * * found = find_value_dict (const Node , Controls * , ctx -> controls , dom -> node );
159
- assert (found );
160
170
if (found ) {
161
171
Controls * controls = * found ;
162
172
const Node * join_token = NULL ;
@@ -174,15 +184,15 @@ static const Node* process_op(Context* ctx, NodeClass op_class, String op_name,
174
184
controls -> tokens = append_nodes (a , controls -> tokens , join_token );
175
185
controls -> destinations = append_nodes (a , controls -> destinations , dst );
176
186
}
177
- Nodes nargs = recreate_variables ( & ctx -> rewriter , get_abstraction_params (dst ));
178
-
187
+ Nodes nparams = remake_variables ( ctx , get_abstraction_params (dst ));
188
+ //register_processed_list(&ctx->rewriter, get_abstraction_params(dst), nparams);
179
189
Node * fn = src ;
180
190
if (fn -> tag == BasicBlock_TAG )
181
191
fn = (Node * ) fn -> payload .basic_block .fn ;
182
192
assert (fn -> tag == Function_TAG );
183
- Node * wrapper = basic_block (a , fn , nargs , format_string_arena (a -> arena , "wrapper_to_%s" , get_abstraction_name (dst )));
193
+ Node * wrapper = basic_block (a , fn , nparams , format_string_arena (a -> arena , "wrapper_to_%s" , get_abstraction_name (dst )));
184
194
wrapper -> payload .basic_block .body = join (a , (Join ) {
185
- .args = nargs ,
195
+ .args = nparams ,
186
196
.join_point = join_token
187
197
});
188
198
return jump_helper (a , wrapper , rewrite_nodes (& ctx -> rewriter , node -> payload .jump .args ));
@@ -247,7 +257,7 @@ void postprocess(Parser* p, Module* src, Module* dst) {
247
257
248
258
ctx .rewriter .rewrite_op_fn = (RewriteOpFn ) process_op ;
249
259
ctx .rewriter .config .process_variables = true;
250
- // ctx.rewriter.config.search_map = false ;
260
+ ctx .rewriter .config .search_map = true ;
251
261
// ctx.rewriter.config.write_map = false;
252
262
253
263
rewrite_module (& ctx .rewriter );
0 commit comments