git @ Cat's Eye Technologies Tamsin / c47ad81
Begin catching up compiler-in-Tamsin. Cat's Eye Technologies 11 years ago
3 changed file(s) with 26 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
123123 emitln('{') &
124124 indent &
125125 emit_formal_match_patterns(P,B,Mod, FmlNms, Fs, nil) → PatNms &
126 collect_all_pattern_variables(Fs, nil) → AllPatVars &
127 emit_unifier_structure(AllPatVars) &
128
126129 emitln('if (') &
127130 emit_pattern_match_expression(PatNms, FmlNms) &
128131 emitln(' 1) {') &
372375 $:gensym('temp') → Nm &
373376 emitln_fmt('struct term *%s = %s;', [Nm, VN]) & Nm.
374377
375 compile_r(P,B,Mod, patternvariable(VN)) =
378 compile_r(P,B,Mod, patternvariable(VN, I)) =
376379 $:gensym('pattern') → Nm &
377380 emitln_fmt('struct term *%s = term_new_variable("%s", ' +
378 'term_new_from_cstring("nil_%s"));', [Nm, VN, VN]) & Nm.
381 'term_new_from_cstring("nil_%s"), %s);', [Nm, VN, VN, I]) &
382 Nm.
379383
380384 compile_r(P,B,Mod, constructor(T,Ts)) =
381385 compile_r(P,B,Mod, atom(T)) → Nm &
400404 collect_variable_names_all(Ts, L).
401405 collect_variable_names(variable(VN), L) =
402406 return list(VN, L).
403 collect_variable_names(patternvariable(VN), L) =
407 collect_variable_names(patternvariable(VN, I), L) =
404408 return list(VN, L).
405409
406410 ############### misc helpers ##############
438442 PatNms ← [PatNm|PatNms] &
439443 emit_formal_match_patterns(P,B,Mod, Nms, Fs, PatNms).
440444
445 collect_all_pattern_variables([], Acc) = Acc.
446 collect_all_pattern_variables([F|Fs], Acc) =
447 collect_variable_names(F, nil) → VarNms &
448 list:reverse(VarNms, nil) → VarNms &
449 list:append(Acc, VarNms) → Acc &
450 collect_all_pattern_variables(Fs, Acc).
451
452 emit_unifier_structure(AllPatVars) =
453 emit('const struct term *unifier[] = {') &
454 emit_unifier_structure_r(AllPatVars) &
455 emitln('};').
456 emit_unifier_structure_r(nil) = 'ok'.
457 emit_unifier_structure_r([V]) =
458 emit('NULL').
459 emit_unifier_structure_r([V|Vs]) =
460 emit('NULL, ') & emit_unifier_structure_r(Vs).
461
441462 emit_pattern_match_expression([], []) = 'ok'.
442463 emit_pattern_match_expression([PatNm | PatNms], [FmlNm | FmlNms]) =
443464 emitln_fmt(' term_match(%s, %s) &&', [PatNm, FmlNm]) &
176176 self.indent()
177177
178178 pat_names = []
179 vars_for_formal = []
180179 for fml_num in xrange(0, len(branch.formals)):
181180 formal = branch.formals[fml_num]
182181 pat_names.append(self.compile_r(formal))
183182
184183 variables = []
185184 formal.collect_variables(variables)
186 vars_for_formal.append(variables)
187185 for variable in variables:
188186 if variable not in all_pattern_variables:
189187 all_pattern_variables.append(variable)
144144 "./bin/tamsin analyze" \
145145 "bin/tamsin-analyzer"
146146 elif [ x$1 = xtcompiler ]; then
147 make bin/tamsin-compiler
147 make bin/tamsin-compiler || exit 1
148148 echo "*** Testing Tamsin-in-Tamsin compiler..."
149149 falderal $VERBOSE --substring-error fixture/compiler.tamsin.markdown $FILES
150150 elif [ x$1 = xbootstrap ]; then
151151 echo "*** Compiling Bootstrapped Tamsin-in-Tamsin compiler..."
152 make bin/tamsin-compiler
152 make bin/tamsin-compiler || exit 1
153153 bin/tamsin-compiler lib/list.tamsin lib/tamsin_scanner.tamsin \
154154 lib/tamsin_parser.tamsin lib/tamsin_analyzer.tamsin \
155155 mains/compiler.tamsin > tmp/foo.c && \