aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/cc/cc.h
diff options
context:
space:
mode:
Diffstat (limited to 'sys/cmd/cc/cc.h')
-rw-r--r--sys/cmd/cc/cc.h123
1 files changed, 61 insertions, 62 deletions
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