changeset 127:dbed1593881c

func: Implement yfunc_destroy()
author Lewin Bormann <lbo@spheniscida.de>
date Sun, 01 Sep 2019 19:21:46 +0200
parents 4b55334c8708
children 38714d118bbd
files src/func.c src/func.h
diffstat 2 files changed, 23 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/func.c	Sun Sep 01 19:21:21 2019 +0200
+++ b/src/func.c	Sun Sep 01 19:21:46 2019 +0200
@@ -1,2 +1,18 @@
 #include "func.h"
 
+#include "value.h"
+
+void yfunc_destroy(yfunc_t* func) {
+    for (size_t i = 0; i < func->body.len; i++) {
+        yexpr_destroy(YVEC_AT(&func->body, i, yexpr_t));
+    }
+    yvec_destroy(&func->body);
+    for (size_t i = 0; i < func->args.len; i++) {
+        yarg_desc_t* arg = YVEC_AT(&func->args, i, yarg_desc_t);
+        ystr_destroy(&arg->argname);
+        yref_destroy(&arg->argref);
+    }
+    yvec_destroy(&func->args);
+    ystr_destroy(&func->name);
+}
+
--- a/src/func.h	Sun Sep 01 19:21:21 2019 +0200
+++ b/src/func.h	Sun Sep 01 19:21:46 2019 +0200
@@ -30,10 +30,10 @@
  * TODO: Extend to allow reference capture for closures?
  */
 typedef struct {
-    /// Expressions making up the function. Often a list; the value of the last
+    /// Expressions (yexpr_t) making up the function body. The value of the last
     /// expression is the value of the invoked function. `args` describes the
     /// references in `body` that are to be bound before calling.
-    yexpr_t body;
+    yvec_t body;
     /// Name of the function.
     ystr_t name;
     /// Vector of yarg_desc_t values, each describing an argument, in order of
@@ -42,6 +42,11 @@
 } yfunc_t;
 
 /**
+ * @brief Free resources associated with func.
+ */
+void yfunc_destroy(yfunc_t* func);
+
+/**
  * @}
  */
 #endif