summaryrefslogtreecommitdiff
path: root/6/main.c
diff options
context:
space:
mode:
authorOri Bernstein <ori@markovcorp.com>2019-02-26 14:07:58 -0800
committerOri Bernstein <ori@markovcorp.com>2019-02-26 14:07:58 -0800
commitd87c0959d85b40fcf60b9c6dd0a2f2111f888b55 (patch)
tree3d9ee97668eda3d4e2656ac069f8575250edc7e2 /6/main.c
parent02201160614e5f25a7a73d86ed26a1f90fa4f5bb (diff)
downloadmc-d87c0959d85b40fcf60b9c6dd0a2f2111f888b55.tar.gz
Accept that `file` isn't a node.
Shrink node sizes, simplify code a bit.
Diffstat (limited to '6/main.c')
-rw-r--r--6/main.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/6/main.c b/6/main.c
index c980887..618eb5f 100644
--- a/6/main.c
+++ b/6/main.c
@@ -21,7 +21,7 @@
#include "../config.h"
/* FIXME: move into one place...? */
-Node *file;
+File file;
char debugopt[128];
int writeasm;
int extracheck = 1;
@@ -161,12 +161,12 @@ gentempfile(char *buf, size_t bufsz, char *path, char *suffix)
}
static int
-hasmain(Node *file)
+hasmain(void)
{
Node *n, *name;
name = mknsname(Zloc, NULL, "main");
- n = getdcl(file->file.globls, name);
+ n = getdcl(file.globls, name);
if (!n)
return 0;
n = n->decl.name;
@@ -201,7 +201,7 @@ genuse(char *path)
fprintf(stderr, "could not open path %s\n", buf);
exit(1);
}
- writeuse(f, file);
+ writeuse(f);
fclose(f);
}
@@ -285,25 +285,26 @@ main(int argc, char **argv)
globls = mkstab(0);
tyinit(globls);
tokinit(ctx.args[i]);
- file = mkfile(ctx.args[i]);
- file->file.globls = globls;
+ file.ns = mkht(strhash, streq);
+ file.globls = globls;
+ lappend(&file.files, &file.nfiles, ctx.args[i]);
yyparse();
/* before we do anything to the parse */
if (debugopt['T'])
- dump(file, stdout);
+ dump(stdout);
loaduses();
- if (hasmain(file)) {
- genautocall(file->file.init, file->file.ninit,
- file->file.localinit, "__init__");
- genautocall(file->file.fini, file->file.nfini,
- file->file.localfini, "__fini__");
+ if (hasmain()) {
+ genautocall(file.init, file.ninit,
+ file.localinit, "__init__");
+ genautocall(file.fini, file.nfini,
+ file.localfini, "__fini__");
}
infer();
tagexports(0);
/* after all type inference */
if (debugopt['t'])
- dump(file, stdout);
+ dump(stdout);
if (writeasm) {
if (outfile != NULL)
@@ -314,7 +315,7 @@ main(int argc, char **argv)
gentempfile(buf, sizeof buf, ctx.args[i], ".s");
}
genuse(ctx.args[i]);
- gen(file, buf);
+ gen(buf);
assemble(buf, ctx.args[i]);
free(localincpath);