From 69487ed29aed49ca0e3481e9783e02e9156258b2 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Fri, 22 May 2020 17:14:48 -0700 Subject: fix: encapsulated the IO stack into the lexer --- sys/cmd/cc/cc.h | 123 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 61 insertions(+), 62 deletions(-) (limited to 'sys/cmd/cc/cc.h') diff --git a/sys/cmd/cc/cc.h b/sys/cmd/cc/cc.h index 0d4c876..62837c4 100644 --- a/sys/cmd/cc/cc.h +++ b/sys/cmd/cc/cc.h @@ -263,17 +263,46 @@ Sym *lookup(SymTab *tab, string ident); error forget(SymTab *tab, string ident); void forgetall(SymTab *tab); +enum +{ + IOnil = iota(0), + IOfile = iota(1), + IObuff = iota(2), +}; + +struct Io +{ + io·Buffer rdr; + string path; + uint32 kind; + union { + Stream *f; + byte *b; + }; + + Pos store; + struct Io *link; +}; + struct Lexer { Pos pos; - Io *io; - SymTab sym; + SymTab sym; byte *b; byte buf[2*1024]; /* predefined dynamic macros */ uintptr macfile; uintptr macline; + + /* i/o data */ + Io *io, *new; + Io iostk[100]; + struct { + int cap; + int len; + string *path; + } omit; }; /* lex.c functions */ @@ -285,8 +314,11 @@ rune getrune(Lexer *); byte ungetbyte(Lexer *); rune ungetrune(Lexer *, rune r); -void pushio(Lexer *lx, Io *new); -void popio(Lexer *lx); +Io* openio(Lexer *lx, byte *path); +Io* makeio(Lexer *lx, byte *name); +void freeio(Lexer *lx, Io *io); +void pushio(Lexer *lx, Io *new); +void popio(Lexer *lx); void puttok(Token); @@ -524,6 +556,7 @@ enum Sbad = -1, }; +/* intermediate nodes */ struct Ptr { uint64 kind; @@ -551,29 +584,22 @@ struct Dtor struct Decls { - union { - struct Dtor; - Dtor dtor; - }; + Type *type; Expr *init; struct Decls *link; }; +/* final ast node */ struct Decl { struct Node; - uint64 spec; + uint32 spec; + string name; + Type *type; union { - struct { - struct Dtor; - Stmt *body; - } func; - struct { - struct Dtor; - Expr *init; - struct Decls *link; - } var; - struct Dtor type; + Stmt *func; + Expr *init; + struct Decls *link; }; }; @@ -627,42 +653,23 @@ struct Parser Decl **decls; } ast; + /* static buffers */ Scope *sp; Scope spstk[20]; + + Name *nm; + Name nmstk[40]; + + Dtor *dt; + Dtor dtstk[40]; }; /* ast.c functions */ -void parse(Parser *, Lexer *); +error parse(Parser *, Lexer *); // ----------------------------------------------------------------------- // global compiler -enum -{ - IOnil = iota(0), - IOfile = iota(1), - IObuff = iota(2), -}; - -struct Io -{ - io·Buffer rdr; - string path; - uint32 kind; - union { - Stream *f; - byte *b; - }; - - Pos store; - struct Io *link; -}; - -/* cc.c io functions */ -Io* openio(byte *path); -Io* makeio(byte *name); -void freeio(Io *io); - struct StrTab { int32 n_buckets; @@ -687,35 +694,27 @@ struct Compiler string outfile; struct { - int cap; - int len; - Type *info; - } type; + int cap; + int len; + string *val; + } def; - /* i/o data */ struct { int cap; int len; string *dir; } inc; - Io *io; - Io iostk[100]; struct { - int cap; - int len; - string *path; - } omit; - - /* partitioned data for stages */ - Lexer lxr; - Parser psr; + int cap; + int len; + Type *info; + } type; }; extern Compiler C; /* cc.c compiler functions */ -void pushomit(string omit); void init(); #undef iota -- cgit v1.2.1