git @ Cat's Eye Technologies Tamsin / 6551a95
Fix bugs in compiler, so tamsin-ast.tamsin compiles (at least). Cat's Eye Technologies 11 years ago
3 changed file(s) with 28 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
206206 subsidiary production scanner returned EOF
207207 * `@include` -- for the scanner, especially
208208 * `$.unquote` should take left and right quotes to expect
209 * define a stringify-repr operation on terms
210 * get rid of `enc`
209211
210212 ### 8-bit clean/UTF-8 ###
211213
8181 self.indent_ -= 1
8282
8383 def emit(self, *args):
84 self.outfile.write(" " * self.indent_ + ''.join(args) + "\n")
84 s = " " * self.indent_ + ''.join(args) + "\n"
85 self.outfile.write(s.encode('UTF-8'))
8586
8687 def compile(self):
8788 self.emit(PRELUDE)
125126 all_pattern_variables = set()
126127
127128 # emit matching code
128 i = 0
129 fml_num = 0
129130 for f in formals:
130 self.emit_term(f, "pattern%s" % i, pattern=True)
131 self.emit("if (!term_match(pattern%s, i%s)) {" % (i, i))
131 self.emit_term(f, "pattern%s" % fml_num, pattern=True)
132 self.emit("if (!term_match(pattern%s, i%s)) {" %
133 (fml_num, fml_num)
134 )
132135 self.indent()
133136
134 # ...
135137 next = None
136 for prod in self.program.prodmap[self.current_prod_name]:
137 if prod.rank == ast.rank + 1:
138 next = prod
139 break
138 myprods = self.program.prodmap[self.current_prod_name]
139 if ast.rank + 1 < len(myprods):
140 next = myprods[ast.rank + 1]
140141
141142 if next:
142143 args = ', '.join(["i%s" % i for i in xrange(0, len(formals))])
157158 for variable in variables:
158159 self.emit('struct term *%s = '
159160 'term_find_variable(pattern%s, "%s");' %
160 (variable.name, i, variable.name)
161 (variable.name, fml_num, variable.name)
161162 )
162163 all_pattern_variables.add(variable.name)
163164
164 i += 1
165 self.emit("")
166 fml_num += 1
165167
166168 for local in locals_:
167169 if local not in all_pattern_variables:
342344 elif isinstance(term, Variable):
343345 if pattern:
344346 self.emit('struct term *%s = term_new_variable("%s", %s);' %
345 (name, term.name, 'term_new("nil_%s")'))
347 (name, term.name, 'term_new("nil_%s")' % term.name))
346348 else:
347349 self.emit('struct term *%s = %s;' % (name, term.name))
348350 else:
361363 escaped_name = s
362364 escaped_name = escaped_name.replace("\\", r"\\")
363365 escaped_name = escaped_name.replace("\n", r"\n")
366 escaped_name = escaped_name.replace("\r", r"\r")
364367 escaped_name = escaped_name.replace("\t", r"\t")
365368 escaped_name = escaped_name.replace('"', r'\"')
366369 return escaped_name
4444 diff -ru 1.txt 2.txt > ast.diff
4545 diff -ru 1.txt 2.txt || exit 1
4646 done
47 elif [ x$1 = xcompiledast ]; then # check that tamsin-ast output looks like bin/tamsin parse
48 echo "Compiling parser (for AST) in Tamsin and testing it..."
49 bin/tamsin compile eg/tamsin-ast.tamsin > foo.c && \
50 gcc -g -Ic_src -Lc_src foo.c -o tamsin-ast -ltamsin || exit 1
51 for EG in eg/*.tamsin; do
52 echo $EG
53 bin/tamsin parse $EG > 1.txt
54 ./tamsin-ast <$EG > 2.txt || exit 1
55 diff -ru 1.txt 2.txt > ast.diff
56 diff -ru 1.txt 2.txt || exit 1
57 done
4758 elif [ x$1 = xinterpreter ]; then
4859 echo "Testing Python interpreter..."
4960 falderal --substring-error fixture/tamsin.py.markdown $FILES