aboutsummaryrefslogtreecommitdiff
path: root/ast.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-03-26 14:02:48 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-03-26 14:02:48 -0400
commit135e23094c42b33acdd05dd522bbe0fd691b9eee (patch)
tree68a675393083286a79d3f66e6f57aa4ac1ebd212 /ast.c
parent59b62035c1304b4c6c39b6d546b9c5187e8d0738 (diff)
Improve codegen for table/array iteration by inlining the iteration
macros
Diffstat (limited to 'ast.c')
-rw-r--r--ast.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/ast.c b/ast.c
index 316bb958..e0354f53 100644
--- a/ast.c
+++ b/ast.c
@@ -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