diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-03-26 14:02:48 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-03-26 14:02:48 -0400 |
| commit | 135e23094c42b33acdd05dd522bbe0fd691b9eee (patch) | |
| tree | 68a675393083286a79d3f66e6f57aa4ac1ebd212 /ast.c | |
| parent | 59b62035c1304b4c6c39b6d546b9c5187e8d0738 (diff) | |
Improve codegen for table/array iteration by inlining the iteration
macros
Diffstat (limited to 'ast.c')
| -rw-r--r-- | ast.c | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -179,4 +179,20 @@ int printf_ast(FILE *stream, const struct printf_info *info, const void *const a } } +bool is_idempotent(ast_t *ast) +{ + switch (ast->tag) { + case Int: case Bool: case Num: case Var: case Nil: case TextLiteral: return true; + case Index: { + auto index = Match(ast, Index); + return (index->index == NULL) && is_idempotent(index->indexed); + } + case FieldAccess: { + auto access = Match(ast, FieldAccess); + return is_idempotent(access->fielded); + } + default: return false; + } +} + // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 |
