From e8bcd324458335d280a45181b58e50a2eb077da9 Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Wed, 23 Feb 2022 21:30:00 +0000 Subject: [PATCH] Remove the deep struct equality implementation from backends. --- TODO.md | 2 -- src/castile/backends/c.py | 25 +------------------------ src/castile/backends/javascript.py | 22 ++-------------------- 3 files changed, 3 insertions(+), 46 deletions(-) diff --git a/TODO.md b/TODO.md index 15c7a96..145365c 100644 --- a/TODO.md +++ b/TODO.md @@ -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 `"`. diff --git a/src/castile/backends/c.py b/src/castile/backends/c.py index 16fbac4..ecd200a 100644 --- a/src/castile/backends/c.py +++ b/src/castile/backends/c.py @@ -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': @@ -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]) diff --git a/src/castile/backends/javascript.py b/src/castile/backends/javascript.py index 555dca4..e6dbe17 100644 --- a/src/castile/backends/javascript.py +++ b/src/castile/backends/javascript.py @@ -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]) @@ -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])