Skip to content

Commit

Permalink
Remove the deep struct equality implementation from backends.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpressey committed Feb 23, 2022
1 parent 8adf1d7 commit e8bcd32
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 46 deletions.
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ TODO

### Implementation ###

Remove the deep struct equality implementation from backends.

Name mangling for compilers (prepend with `_` most likely.)

And literal characters in strings, especially `'` and `"`.
Expand Down
25 changes: 1 addition & 24 deletions src/castile/backends/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,25 +199,6 @@ def compile(self, ast):
self.indent -= 1
self.write_indent('}\n\n')

# FIXME the language no longer supports this, it can be jettisoned
self.write_indent('int equal_%s(struct %s * a, struct %s * b) {\n' % (ast.value, ast.value, ast.value))

self.indent += 1
for child in field_defns:
assert child.tag == 'FieldDefn', child.tag
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))

self.write_indent('return 1;\n')
self.indent -= 1
self.write_indent('}\n\n')

elif ast.tag == 'FieldDefn':
self.write_indent('%s;\n' % self.c_decl(ast.children[0].type, ast.value))
elif ast.tag == 'FunLit':
Expand Down Expand Up @@ -257,11 +238,7 @@ def compile(self, ast):
self.indent -= 1
elif ast.tag == 'Op':
if ast.value == '==' and isinstance(ast.children[0].type, Struct):
self.write('equal_%s(' % ast.children[0].type.name)
self.compile(ast.children[0])
self.write(', ')
self.compile(ast.children[1])
self.write(')')
raise NotImplementedError('structs cannot be compared for equality')
elif ast.value == '==' and isinstance(ast.children[0].type, Union):
self.write('equal_tagged_value(')
self.compile(ast.children[0])
Expand Down
22 changes: 2 additions & 20 deletions src/castile/backends/javascript.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,7 @@ def compile(self, ast):
elif ast.tag == 'Forward':
pass
elif ast.tag == 'StructDefn':
# FIXME the language no longer supports this, it can be jettisoned
field_defns = ast.children[0].children
self.write('function equal_%s(a, b) {\n' % ast.value)
for child in field_defns:
assert child.tag == 'FieldDefn', child.tag
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 false;\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 false;\n' % (child.value, child.value))
self.write('return true;\n')
self.write('}\n\n')
pass
elif ast.tag == 'FunLit':
self.write('function(')
self.compile(ast.children[0])
Expand Down Expand Up @@ -123,11 +109,7 @@ def compile(self, ast):
self.compile(ast.children[1])
elif ast.tag == 'Op':
if ast.value == '==' and isinstance(ast.children[0].type, Struct):
self.write('equal_%s(' % ast.children[0].type.name)
self.compile(ast.children[0])
self.write(', ')
self.compile(ast.children[1])
self.write(')')
raise NotImplementedError('structs cannot be compared for equality')
elif ast.value == '==' and isinstance(ast.children[0].type, Union):
self.write('equal_tagged_value(')
self.compile(ast.children[0])
Expand Down

0 comments on commit e8bcd32

Please sign in to comment.