changeset 169:cdf06bdd9592

bin/ylisp: Support reading scripts
author Lewin Bormann <lbo@spheniscida.de>
date Tue, 03 Sep 2019 20:18:05 +0200
parents 5697df53fe81
children df15d77ffff1
files src/bin/ylisp.c
diffstat 1 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/bin/ylisp.c	Tue Sep 03 20:06:59 2019 +0200
+++ b/src/bin/ylisp.c	Tue Sep 03 20:18:05 2019 +0200
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <err.h>
 
 #include <src/parse.h>
 #include <src/preprocess.h>
@@ -30,10 +31,26 @@
 
     if (argc == 1) {
         result = run(stdin, &state, &root);
+    } else {
+        for (int i = 1; i < argc; i++) {
+            FILE* source = fopen(argv[i], "r");
+            if (source == NULL) {
+                err(1, "couldn't open file %s", argv[i]);
+            }
+            yexpr_t result = run(source, &state, &root);
+            yexpr_destroy(&result);
+            fclose(source);
+        }
     }
 
+    yvec_destroy(YVEC_AT(root, 0, yvec_t));
+    free(*YVEC_AT(root, 0, void*));
     yvec_destroy(root);
+    free(root);
     yvec_destroy(&state.call_stack);
     yexpr_destroy(&result);
+
+    yvalue_free_all();
+    yatom_free_all();
     return 0;
 }