diff options
author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-04-20 03:39:40 +0300 |
---|---|---|
committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-04-20 03:39:40 +0300 |
commit | 1cc7990ef7d5483d0434dda412f2d88e0b17df27 (patch) | |
tree | 93c9945318908c4f593251c0b8f9ecf57c3bde96 /src/core.c | |
parent | edf56e3444d5333d4362277ee97a5cdf0c2f52af (diff) | |
download | posthaste-1cc7990ef7d5483d0434dda412f2d88e0b17df27.tar.gz posthaste-1cc7990ef7d5483d0434dda412f2d88e0b17df27.zip |
initial working bytecode
Diffstat (limited to 'src/core.c')
-rw-r--r-- | src/core.c | 60 |
1 files changed, 50 insertions, 10 deletions
@@ -3,9 +3,14 @@ #include <limits.h> #include <errno.h> -#include <posthaste/debug.h> +#include <posthaste/execute.h> #include <posthaste/parser.h> +#include <posthaste/debug.h> +#include <posthaste/scope.h> +#include <posthaste/check.h> +#include <posthaste/lower.h> #include <posthaste/core.h> +#include <posthaste/ast.h> /** * Read whole file into a buffer and return pointer to buffer. @@ -41,28 +46,63 @@ static char *read_file(const char *fname, FILE *f) int run(const char *fname) { + int ret = 0; + const char *buf = NULL; + struct scope *scope = NULL; + struct parser *p = NULL; + FILE *f = fopen(fname, "rb"); if (!f) { error("failed opening %s: %s\n", fname, strerror(errno)); return -1; } - const char *buf = read_file(fname, f); + buf = read_file(fname, f); fclose(f); - if (!buf) - return -1; + if (!buf) { + ret = -1; + goto out; + } - struct parser *p = create_parser(); - if (!p) - return -1; + p = create_parser(); + if (!p) { + ret = -1; + goto out; + } parse(p, fname, buf); - int ret = p->failed ? -1 : 0; + if (p->failed) { + ret = -1; + goto out; + } - /* eventually do other stuff as well */ - free((void *)buf); + scope = create_scope(); + if (!scope) { + ret = -1; + goto out; + } + + scope_set_file(scope, fname, buf); + + struct ast *ast = p->tree; + if (check(scope, ast)) { + ret = -1; + goto out; + } + if (lower_ast(ast)) { + ret = -1; + goto out; + } + + execute(); + +out: + free((void *)buf); + destroy_lowering(); + destroy_scopes(); + destroy_ast_nodes(); destroy_parser(p); return ret; } |