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.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/boot/tree.c b/boot/tree.c
index 2d49a2c..6e7fd6a 100644
--- a/boot/tree.c
+++ b/boot/tree.c
@@ -657,6 +657,10 @@ enum Statement_Kind
     STATEMENT_BLOCK,
     STATEMENT_CONDITIONAL,
     STATEMENT_LOOP,
+    STATEMENT_RETURN,
+    STATEMENT_BREAK,
+    STATEMENT_CONTINUE,
+    STATEMENT_DEFER,
 };
 
 struct Statement_Value_Expression
@@ -701,6 +705,20 @@ struct Statement_Value_Loop
     struct Block_Node body;
 };
 
+struct Statement_Value_Return
+{
+    // nil if there is no return value.
+    struct Expression* value;
+};
+
+struct Statement_Value_Defer
+{
+    // either a simple expression, or, if expression is nil,
+    // a block of code to execute.
+    struct Expression* expression;
+    struct Block_Node block;
+};
+
 union Statement_Value
 {
     struct Statement_Value_Expression expression;
@@ -708,6 +726,8 @@ union Statement_Value
     struct Statement_Value_Block block;
     struct Statement_Value_Conditional conditional;
     struct Statement_Value_Loop loop;
+    struct Statement_Value_Return return_value;
+    struct Statement_Value_Defer defer;
 };
 
 struct Statement
@@ -832,6 +852,31 @@ statement_print(const struct Statement* statement)
         block_node_print(&statement->value.loop.body);
         break;
     }
+    case STATEMENT_RETURN: {
+        printf("(return");
+        if (statement->value.return_value.value) {
+            printf(" ");
+            expression_print(statement->value.return_value.value);
+        }
+        printf(")");
+        break;
+    }
+    case STATEMENT_BREAK:
+        printf("(break)");
+        break;
+    case STATEMENT_CONTINUE:
+        printf("(continue)");
+        break;
+    case STATEMENT_DEFER: {
+        printf("(defer ");
+        if (statement->value.defer.expression) {
+            expression_print(statement->value.defer.expression);
+        } else {
+            block_node_print(&statement->value.defer.block);
+        }
+        printf(")");
+        break;
+    }
     default:
         failure("unexpected statement kind passed to `statement_print`");
         break;