aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorPreston Pan <preston@nullring.xyz>2024-01-10 21:50:03 -0800
committerPreston Pan <preston@nullring.xyz>2024-01-10 21:50:03 -0800
commit8569af05d8111654f1839f1cf50175a32b0bc547 (patch)
tree4f1aa81f60a16d0ba1d8edfb0f04e945514b54c2 /src/main.c
parent4ada155b930cb5fb96493dff3a5af8809da3b214 (diff)
add shit
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index 3b1f53f..884a198 100644
--- a/src/main.c
+++ b/src/main.c
@@ -7,9 +7,7 @@
#include <unistd.h>
extern ht_t *WORD_TABLE;
-
extern array_t *STACK;
-extern char *INBUF;
extern parser_t *PARSER;
extern array_t *EVAL_STACK;
extern ht_t *OBJ_TABLE;
@@ -29,7 +27,9 @@ void version() {
int main(int argc, char **argv) {
value_t *v;
size_t len;
+ char *buf;
+ /* Parsing arguments */
if (argc < 2) {
usage();
}
@@ -40,16 +40,18 @@ int main(int argc, char **argv) {
version();
}
+ /* Read code from file */
FILE *FP = fopen(argv[1], "rb");
if (!FP) {
usage();
}
- ssize_t bytes_read = getdelim(&INBUF, &len, '\0', FP);
+ ssize_t bytes_read = getdelim(&buf, &len, '\0', FP);
fclose(FP);
- PARSER = parser_pp(INBUF);
+ /* Set up global variables */
+ PARSER = parser_pp(buf);
STACK = init_array(10);
WORD_TABLE = init_ht(500);
EVAL_STACK = init_array(10);
@@ -58,6 +60,7 @@ int main(int argc, char **argv) {
add_funcs();
+ /* parse and eval loop */
while (1) {
v = parser_get_next(PARSER);
if (v == NULL)
@@ -65,6 +68,7 @@ int main(int argc, char **argv) {
eval(v);
}
+ /* Free all global variables */
free(PARSER->source);
ht_free(WORD_TABLE, value_free);
ht_free(FLIT, func_free);