about summary refs log tree commit diff
path: root/boot/tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'boot/tree.c')
-rw-r--r--boot/tree.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/boot/tree.c b/boot/tree.c
index 64eb23b..3ae90b8 100644
--- a/boot/tree.c
+++ b/boot/tree.c
@@ -592,6 +592,7 @@ enum Statement_Kind
     // NOTE: a block could be an expression in the future.
     STATEMENT_BLOCK,
     STATEMENT_CONDITIONAL,
+    STATEMENT_LOOP,
 };
 
 struct Statement_Value_Expression
@@ -624,12 +625,25 @@ struct Statement_Value_Conditional
     uint condition_count;
 };
 
+struct Statement_Value_Loop
+{
+    // exists for iterator-style + c-style loops.
+    struct Statement* declaration;
+    // exists for all loop types, except for infinite loops.
+    struct Expression* condition;
+    // exists for c-style loops.
+    struct Expression* iteration;
+
+    struct Block_Node body;
+};
+
 union Statement_Value
 {
     struct Statement_Value_Expression expression;
     struct Statement_Value_Declaration declaration;
     struct Statement_Value_Block block;
     struct Statement_Value_Conditional conditional;
+    struct Statement_Value_Loop loop;
 };
 
 struct Statement
@@ -731,6 +745,29 @@ statement_print(const struct Statement* statement)
         printf(")");
         break;
     }
+    case STATEMENT_LOOP: {
+        printf("(loop ");
+        if (statement->value.loop.declaration) {
+            printf("(declaration ");
+            statement_print(statement->value.loop.declaration);
+            printf(") ");
+        }
+
+        if (statement->value.loop.condition) {
+            printf("(condition ");
+            expression_print(statement->value.loop.condition);
+            printf(") ");
+        }
+
+        if (statement->value.loop.iteration) {
+            printf("(iteration ");
+            expression_print(statement->value.loop.iteration);
+            printf(") ");
+        }
+
+        block_node_print(&statement->value.loop.body);
+        break;
+    }
     default:
         failure("unexpected statement kind passed to `statement_print`");
         break;