diff options
| author | 2023-06-19 11:56:46 +0200 | |
|---|---|---|
| committer | 2023-06-19 11:56:46 +0200 | |
| commit | b71515071d1310bbf9cd34f8997aa736ebd30099 (patch) | |
| tree | f14ac1364d508ad2f1e8cdcda59b4dc9bae96f21 /c.h | |
| parent | 08649c95cc15b5ad99e6b8899d639f6c3b63266b (diff) | |
frontend: separate compiler & lexer
Diffstat (limited to 'c.h')
| -rw-r--r-- | c.h | 54 |
1 files changed, 54 insertions, 0 deletions
@@ -0,0 +1,54 @@ +#include "common.h" + +/*************/ +/* EXPR TREE */ +/*************/ + +enum exprkind { + EXXX, ENUMLIT, ESTRLIT, ESYM, EINIT, EGETF, ECALL, ECOND, + /* unary */ + EPLUS, ENEG, ECOMPL, ELOGNOT, EDEREF, EADDROF, ECAST, + EPREINC, EPOSTINC, EPREDEC, EPOSTDEC, + /* binary */ + EADD, ESUB, EMUL, EDIV, EREM, EBAND, EBIOR, EXOR, ESHL, ESHR, + ELOGAND, ELOGIOR, + EEQU, ENEQ, ELTH, EGTH, ELTE, EGTE, + ESET, ESETADD, ESETSUB, ESETMUL, ESETDIV, ESETREM, ESETAND, ESETIOR, ESETXOR, ESETSHL, ESETSHR, + ESEQ, +}; +#define isunop(t) in_range(t, EPLUS, EPOSTDEC) +#define isbinop(t) in_range(t, EADD, ESEQ) +#define isassign(t) in_range(t, ESET, ESETSHR) +#define assigntobinop(t) ((t) - ESETADD + EADD) + +struct expr { + uchar t; + uchar qual; + ushort narg; /* ECALL */ + union type ty; + struct span span; + union { + struct { + struct expr *sub; + struct { + ushort off; + uchar bitsiz, bitoff; + } fld; /* EGETF */ + }; + uvlong u; vlong i; double f; /* ENUMLIT */ + struct bytes s; /* ESTRLIT */ + struct decl *sym; /* ESYM */ + struct initializer *ini; /* EINIT */ + }; +}; + +enum evalmode { + EVINTCONST, + EVARITH, + EVSTATICINI, + EVFOLD, +}; + +bool eval(struct expr *, enum evalmode); + +/* vim:set ts=3 sw=3 expandtab: */ |