git @ Cat's Eye Technologies Tamsin / c003ab3
I did say the going would be slow, I believe. Cat's Eye Technologies 11 years ago
1 changed file(s) with 27 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
120120
121121 compile_branch(P,B,Mod,FmlNms, prodbranch(Fs, Ls, E)) =
122122
123 # all_pattern_variables = set()
124
125123 emitln('{') &
126124 indent &
127125 emit_formal_match_patterns(FmlNms, Fs, nil) → PatNms &
129127 emit_pattern_match_expression(PatNms, FmlNms) &
130128 emitln(' 1) {') &
131129 indent &
132
133 # # declare and get variables which are found in patterns for this branch
134 # for fml_num in xrange(0, len(branch.formals)):
135 # variables = []
136 # formal = branch.formals[fml_num]
137 # formal.to_term().collect_variables(variables)
138 # for variable in variables:
139 # self.emit('struct term *%s = '
140 # 'term_find_variable(pattern%s, "%s");' %
141 # (variable.name, fml_num, variable.name)
142 # )
143 # all_pattern_variables.add(variable.name)
144
130 emit_matched_variables(Fs, PatNms) &
145131 emit_locals(Ls) &
146132 compile_r(P, prodbranch(Fs, Ls, E), Mod, E) &
147133
166152 emitln(') &&') &
167153 emit_pattern_match_expression(PatNms, FmlNms).
168154
155 # declare and get variables which are found in patterns for this branch
156 emit_matched_variables(nil, nil) = 'ok'.
157 emit_matched_variables(list(F, Fs), list(PatNm, PatNms)) =
158 collect_variables(F, nil) → Vars &
159 emit_assign_matched_variables(PatNm, Vars) &
160 emit_matched_variables(Fs, PatNms).
161
162 emit_assign_matched_variables(PatNm, nil) = 'ok'.
163 emit_assign_matched_variables(PatNm, list(variable(VN), T)) =
164 emit('struct term *') &
165 emit(VN) &
166 emit(' = term_find_variable(') &
167 emit(PatNm) &
168 emit(', "') &
169 emit(VN) &
170 emitln('");') &
171 emit_assign_matched_variables(PatNm, T).
172
173 # TODO should be like compile_r(term) but... different
174 collect_variables(F, L) = L.
169175
170176 # .... general compiler continues ....
171177
420426
421427 ############### emitting pattern terms ###############
422428
423 # should be like compile_r(term), except... with differences
429 # should be like compile_r(term), except variables are different
424430
425431 emit_pattern(atom(T)) =
426432 emit('struct term *') &
432438 emitln('");') &
433439 Nm.
434440
435 # TODO: THIS IS WHERE IT SHOULD BE DIFFERENT
436441 emit_pattern(variable(VN)) =
437442 emit('struct term *') &
438443 $:gensym('pattern') → Nm &
439444 emit(Nm) &
440 emit(' = ') &
441 emit(VN) &
442 emitln(';') &
445 emit(' = term_new_variable("') &
446 emit(VN) &
447 emit('", term_new_from_cstring("nil_') &
448 emit(VN) &
449 emitln('"));') &
443450 Nm.
444451
445452 emit_pattern(constructor(T,Ts)) =