From c620d528fb9d9efbac559002d23857623e71df05 Mon Sep 17 00:00:00 2001 From: Preston Pan Date: Fri, 6 Jan 2023 20:48:56 -0800 Subject: whoops, fixed concat. Include in the making --- src/visitor.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/visitor.c') diff --git a/src/visitor.c b/src/visitor.c index 14ea404..25fb7cd 100644 --- a/src/visitor.c +++ b/src/visitor.c @@ -60,6 +60,10 @@ bool is_built_in(ast_t *e) { strcmp(cmp, "atof") == 0 || strcmp(cmp, "ftoa") == 0) return true; + /* I/O and other operating system stuff */ + if (strcmp(cmp, "exit") == 0 || strcmp(cmp, "readin") == 0 || + strcmp(cmp, "read") == 0) + return true; return false; } @@ -422,10 +426,22 @@ ast_t *eval_list(visitor_t *v, ast_t *e) { char *ret = malloc((string_len1 + string_len2) * sizeof(char)); strcat(ret, arg1->string_value); strcat(ret, arg2->string_value); - return ret; + return init_ast_string(ret); + } else + eval_error(v, e); + } else if (strcmp(function->string_value, "exit") == 0) { + if (cmp != 1) + eval_error(v, e); + + ast_t *arg1 = eval_expr(v, args->car); + + if (arg1->type == AST_INT) { + int code = arg1->int_value; + exit(code); } else eval_error(v, e); } + return NULL; } /* printf("debug 2\n"); */ -- cgit