Skip to content

Commit

Permalink
Equality function in C backend. Prettier output in Ruby backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpressey committed Feb 17, 2022
1 parent f471be3 commit 4d34bfc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/castile/backends/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,12 @@ def compile(self, ast):
self.indent += 1
for child in field_defns:
assert child.tag == 'FieldDefn', child.tag
struct_type = child.children[0].value if child.children[0].tag == 'StructType' else None
if struct_type:
child_type = child.children[0]
if child_type.tag == 'StructType':
struct_type = child_type.value
self.write_indent('if (!equal_%s(a->%s, b->%s)) return 0;\n' % (struct_type, child.value, child.value))
elif child_type.tag == 'UnionType':
self.write_indent('if (!equal_tagged_value(a->%s, b->%s)) return 0;\n' % (child.value, child.value))
else:
self.write_indent('if (a->%s != b->%s) return 0;\n' % (child.value, child.value))

Expand Down
10 changes: 8 additions & 2 deletions src/castile/backends/ruby.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,21 @@ def compile(self, ast):
self.write_indent('if (')
self.compile(ast.children[0])
self.write("[0] == '%s')" % str(ast.children[1].type))
self.write('then save=')
self.write(' then\n')
self.indent += 1
self.write_indent('save=')
self.compile(ast.children[0])
self.write('\n')
self.write_indent('')
self.compile(ast.children[0])
self.write('=')
self.compile(ast.children[0])
self.write('[1]\n')
self.compile(ast.children[2])
self.write_indent('')
self.compile(ast.children[0])
self.write(' = save end')
self.write(' = save\n')
self.indent -= 1
self.write_indent('end')
else:
raise NotImplementedError(repr(ast))

0 comments on commit 4d34bfc

Please sign in to comment.