diff options
| author | 2022-08-07 15:26:53 +0200 | |
|---|---|---|
| committer | 2022-08-07 15:29:04 +0200 | |
| commit | 92bbf45f333bbf9190befc52a6bc114dc2957e41 (patch) | |
| tree | 87196fb07a02e1eb6cb5048da86dadd30a69ddc1 /bootstrap/all.h | |
| parent | 0a4f81e86d21d056329a2b7b2186152e9b9c2375 (diff) | |
basic templates (generics)
Diffstat (limited to 'bootstrap/all.h')
| -rw-r--r-- | bootstrap/all.h | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/bootstrap/all.h b/bootstrap/all.h index 8c80fe4..aba2bc3 100644 --- a/bootstrap/all.h +++ b/bootstrap/all.h @@ -70,6 +70,8 @@ enum toktype { TKident, TKmacident, TKgensym, + TKtype, + TKexpr, TKeof, }; #define NUM_KEYWORDS TKintlit @@ -91,6 +93,8 @@ struct tok { const char *str; int strlen; }; + const struct type *ty; + struct expr *ex; }; }; @@ -121,8 +125,9 @@ struct parser { slice_t(struct expanarg) args; struct toktree toks; const char *name; - struct span spp,span; + struct span span; int idx; + bool tepl; } *curexpan; // macro expansions int expanno; const struct type *targty; @@ -178,6 +183,13 @@ struct type { const struct type *ty; }) flds; slice_t(struct decl *) decls; + slice_t(struct teplarg { + bool typ; + union { + const struct type *ty; + struct tok tok; + }; + }) tpargs; bool fwd; int id; } agg; @@ -218,6 +230,7 @@ enum decltype { Dlet, Dstatic, Dmacro, + Dtepl, }; struct decl { @@ -235,9 +248,27 @@ struct decl { int id, fnid; } var; struct macro macro; + struct tepl { + enum decltype t; + enum typetype tkind; + const char *name; + struct env *env; + slice_t(struct teplparam) params; + struct teplcache { + struct teplcache *next; + slice_t(struct teplarg) args; + const struct type *ty; + } *cache; + struct toktree toks; + } tepl; }; }; +struct teplparam { + const char *name; + bool typ; +}; + struct env { struct env *parent; struct decls { @@ -444,7 +475,7 @@ bswap64(u64 x) { (slice)->n = (v)->length) #define container_of(x, T, fld) \ - (T *)((char *)(x) - offsetof(T, fld)) + ((T *)((char *)(x) - offsetof(T, fld))) /// ///////////////////////////////// |