git @ Cat's Eye Technologies Tamsin / ab9cd4f
I did say it would be slow going, I think. Cat's Eye Technologies 11 years ago
1 changed file(s) with 16 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
109109 compile_branches(P,B,Mod,FmlNms, Bs) &
110110 emit('result = term_new_from_cstring("No \'') &
111111 emit(N) &
112 emitln(' matched arguments");') &
112 emitln('\' production matched arguments");') &
113113 emitln('ok = 0;') &
114114 outdent &
115115 emitln('}').
156156 emit_matched_variables(nil, nil) = 'ok'.
157157 emit_matched_variables(list(F, Fs), list(PatNm, PatNms)) =
158158 collect_variables(F, nil) → Vars &
159 list:reverse(Vars, nil) → Vars &
159160 emit_assign_matched_variables(PatNm, Vars) &
160161 emit_matched_variables(Fs, PatNms).
161162
169170 emit(VN) &
170171 emitln('");') &
171172 emit_assign_matched_variables(PatNm, T).
172
173 # TODO should be like compile_r(term) but... different
174 collect_variables(F, L) = L.
175173
176174 # .... general compiler continues ....
177175
278276 emit(RNm) &
279277 emitln(');').
280278
279 # TODO: ARGUMENTS!
281280 compile_r(P,B,Mod, call(prodref(M, N), A)) =
282281 emit('prod_') &
283282 emit(M) &
470469 emit(Nm) &
471470 emitln(');') &
472471 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).
473485
474486 ############### misc helpers ##############
475487