From 92bbf45f333bbf9190befc52a6bc114dc2957e41 Mon Sep 17 00:00:00 2001 From: lemon Date: Sun, 7 Aug 2022 15:26:53 +0200 Subject: basic templates (generics) --- bootstrap/all.h | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'bootstrap/all.h') 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))) /// ///////////////////////////////// -- cgit v1.2.3