diff options
Diffstat (limited to 'sys/cmd/cc/cc.c')
-rw-r--r-- | sys/cmd/cc/cc.c | 55 |
1 files changed, 36 insertions, 19 deletions
diff --git a/sys/cmd/cc/cc.c b/sys/cmd/cc/cc.c index 6bc363c..87d9a35 100644 --- a/sys/cmd/cc/cc.c +++ b/sys/cmd/cc/cc.c @@ -99,30 +99,28 @@ END: Io* openio(byte *path) { - Io *it; + string *it, *end; Stream *f; intern(&path); // See if we have already opened file; // If so, and it hasn't been flagged return it - for (it = C.iostk; it != C.io; ++it) { - if ((uintptr)it->path == (uintptr)path) { - if (it->kind & IOonce) { - return nil; - } - return it; - } + for (it = C.omit.path, end = it + C.omit.len; it < end; ++it) { + if ((uintptr)(*it) == (uintptr)(path)) + return nil; } + printf("OPENING PATH %s\n", path); if ((C.io - C.iostk) >= arrlen(C.iostk)-1) panicf("out of I/O space!"); - C.io->f = io·open(path, "r"); - if (!C.io->f) { + C.io->f = io·open(path, "r"); + if (!C.io->f) panicf("file %s not found", path); - } + + C.io->kind = IOfile; C.io->path = path; bufio·initreader(&C.io->buf, asrdr(io·read), C.io->f); @@ -151,21 +149,28 @@ makeio() } #undef asrdr -// TODO: Think about if this is always at the _end_ of the stack. -// Right now we don't have access to it. void freeio(Io *io) { - if (io->kind & ~IOmac) { - free(io->b); - } else { + if (io->kind & IOfile) { io·close(io->f); } + io->kind = 0; io->link = nil; io->path = nil; io->store = (Pos){ 0 }; } +void +pushomit(string omit) +{ + if (C.omit.len == C.omit.cap) { + C.omit.cap += 20; + C.omit.path = realloc(C.omit.path, C.omit.cap*sizeof(*C.omit.path)); + } + C.omit.path[C.omit.len++] = omit; +} + // ----------------------------------------------------------------------- // universal compiler builtins @@ -234,8 +239,13 @@ init(void) C.inc.dir = calloc(C.inc.cap, sizeof(*C.inc.dir)); C.inc.dir[C.inc.len++] = "."; - C.outfile = nil; - C.io = C.iostk; + C.omit.len = 0; + C.omit.cap = 100; + C.omit.path = calloc(C.omit.cap, sizeof(*C.inc.dir)); + + C.outfile = nil; + C.io = C.iostk; + C.io->link = nil; memset(C.iostk, 0, sizeof(C.iostk)); C.lxr = (Lexer){ 0 }; @@ -248,7 +258,9 @@ compile(byte *path) Token tok; byte *p, out[400]; + intern(&path); strcpy(out, path); + p = utf8·findrrune(out, '/'); if (p) *p++ = '\0'; @@ -268,7 +280,12 @@ compile(byte *path) } } - C.lxr.io = openio(path); + C.lxr.io = openio(path); + C.lxr.pos = (Pos){ + .path = path, + .line = 1, + .col = 1, + }; while (tok = lex(&C.lxr), tok.kind > Aeof) { puttok(tok); } |