From a287fe5aeb6b681ab405c0297841dce64ab4b946 Mon Sep 17 00:00:00 2001 From: lemon Date: Fri, 14 Nov 2025 18:49:04 +0100 Subject: preeliminary va_list support --- c/c.h | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'c/c.h') diff --git a/c/c.h b/c/c.h index 81c07f9..e8e797c 100644 --- a/c/c.h +++ b/c/c.h @@ -5,7 +5,7 @@ /*************/ enum exprkind { - EXXX, ENUMLIT, ESTRLIT, ESYM, EINIT, EGETF, ECALL, ECOND, + EXXX, ENUMLIT, ESTRLIT, ESYM, EVAARG, EINIT, EGETF, ECALL, ECOND, /* unary */ EPLUS, ENEG, ECOMPL, ELOGNOT, EDEREF, EADDROF, ECAST, EPREINC, EPOSTINC, EPREDEC, EPOSTDEC, @@ -59,6 +59,18 @@ struct init { } *vals, **tail; }; +/** C compiler state **/ +struct comp { + struct lexer *lx; + struct env *env; + struct arena *fnarena, *exarena; + struct span fnblkspan; + uint loopdepth, switchdepth; + struct block *breakto, *loopcont; + struct switchstmt *switchstmt; + struct label *labels; +}; + enum storageclass { SCNONE, SCTYPEDEF = 1<<0, @@ -72,17 +84,35 @@ enum storageclass { struct decl { union type ty; uchar scls; - uchar qual : 2; - uchar isenum : 1; - uchar isdef : 1; + uchar qual : 2, + isenum : 1, + isdef : 1, + isbuiltin : 1; struct span span; const char *name; union { struct { ushort align; int id; }; vlong value; + const struct builtin *builtin; }; }; +extern union type cvalistty; +struct function; +struct decl *envadddecl(struct env *env, const struct decl *d); +bool assigncheck(union type t, const struct expr *src); +union ref expraddr(struct function *, const struct expr *); +union ref compileexpr(struct function *, const struct expr *, bool discard); + +/** builtin.c **/ +struct builtin { + bool (*sema)(struct comp *, struct expr *); + union ref (*comp)(struct function *, struct expr *, bool discard); +}; +void putbuiltins(struct env *); +union ref builtin_va_arg_comp(struct function *, const struct expr *, bool discard); + +/** eval.c **/ enum evalmode { EVNONE, EVINTCONST, -- cgit v1.2.3