I did say it would be slow going, I think.
Cat's Eye Technologies
11 years ago
109 | 109 | compile_branches(P,B,Mod,FmlNms, Bs) & |
110 | 110 | emit('result = term_new_from_cstring("No \'') & |
111 | 111 | emit(N) & |
112 | emitln(' matched arguments");') & | |
112 | emitln('\' production matched arguments");') & | |
113 | 113 | emitln('ok = 0;') & |
114 | 114 | outdent & |
115 | 115 | emitln('}'). |
156 | 156 | emit_matched_variables(nil, nil) = 'ok'. |
157 | 157 | emit_matched_variables(list(F, Fs), list(PatNm, PatNms)) = |
158 | 158 | collect_variables(F, nil) → Vars & |
159 | list:reverse(Vars, nil) → Vars & | |
159 | 160 | emit_assign_matched_variables(PatNm, Vars) & |
160 | 161 | emit_matched_variables(Fs, PatNms). |
161 | 162 | |
169 | 170 | emit(VN) & |
170 | 171 | emitln('");') & |
171 | 172 | emit_assign_matched_variables(PatNm, T). |
172 | ||
173 | # TODO should be like compile_r(term) but... different | |
174 | collect_variables(F, L) = L. | |
175 | 173 | |
176 | 174 | # .... general compiler continues .... |
177 | 175 | |
278 | 276 | emit(RNm) & |
279 | 277 | emitln(');'). |
280 | 278 | |
279 | # TODO: ARGUMENTS! | |
281 | 280 | compile_r(P,B,Mod, call(prodref(M, N), A)) = |
282 | 281 | emit('prod_') & |
283 | 282 | emit(M) & |
470 | 469 | emit(Nm) & |
471 | 470 | emitln(');') & |
472 | 471 | emit_pattern_subterms(ON, T). |
472 | ||
473 | ########### finding variables in patterns ########### | |
474 | ||
475 | collect_variables_all(nil, L) = L. | |
476 | collect_variables_all(list(H, T), L) = | |
477 | collect_variables(H, L) → L & | |
478 | collect_variables_all(T, L). | |
479 | ||
480 | collect_variables(atom(T), L) = L. | |
481 | collect_variables(constructor(T, Ts), L) = | |
482 | collect_variables_all(Ts, L). | |
483 | collect_variables(variable(VN), L) = | |
484 | return list(variable(VN), L). | |
473 | 485 | |
474 | 486 | ############### misc helpers ############## |
475 | 487 |