Skip to content

Commit

Permalink
Implement deep struct equality in C backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpressey committed Feb 13, 2022
1 parent 3f847d5 commit b7c71eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/castile/backends/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,11 @@ def compile(self, ast):
self.indent += 1
for child in ast.children:
assert child.tag == 'FieldDefn'
# TODO does not handle structs within structs
self.write_indent('if (a->%s != b->%s) return 0;\n' % (child.value, child.value))
struct_type = child.children[0].value if child.children[0].tag == 'StructType' else None
if struct_type:
self.write_indent('if (!equal_%s(a->%s, b->%s)) return 0;\n' % (struct_type, 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
Expand Down
2 changes: 2 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ if [ ! x`command -v gcc` = x ]; then
APPLIANCES="$APPLIANCES tests/appliances/castile-c-c.md"
fi

#APPLIANCES="tests/appliances/castile-c-c.md"

falderal $APPLIANCES tests/Castile.md
RESULT=$?
rm -f foo.* a.out
Expand Down

0 comments on commit b7c71eb

Please sign in to comment.