From 792463cb133f65645feb48743bbc03ef8eb96bdd Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Tue, 13 Sep 2022 21:46:21 +0100 Subject: Move towards C23, improve events and vcall macros Another big one. Here's a list of things: - Since the upcoming C23 standardises typeof(), use it as an extension for the time being in order to allow passing arbitrary types as macro/codegen parameters. It wouldn't have been a big leap to do this even without standardisation since it's apparently an easy extension to implement - and also, to be honest, this project is essentially glued to Clang anyway so who cares. - Likewise, bool, true and false are becoming pre-defined, so pre-pre-define them now in order to get the benefit of not having to remember one header everywhere. - Really ungodly/amazing vcall macro stuff now allows us to call C++ virtual functions like regular C functions. It's pretty cool! - Events can now take arbitrary parameters and come in two types: regular events and predicates. All this makes the base code even uglier but makes the feature implementation nicer. In other words, it places more of the cognitive burden on myself and less on other people who might want to contribute. This is a good tradeoff, because I'm a genius. --- src/3p/chibicc/chibicc.h | 4 ++-- src/3p/chibicc/tokenize.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/3p') diff --git a/src/3p/chibicc/chibicc.h b/src/3p/chibicc/chibicc.h index dd810ec..2a80ecf 100644 --- a/src/3p/chibicc/chibicc.h +++ b/src/3p/chibicc/chibicc.h @@ -7,7 +7,7 @@ #include #include #include -#include +//#include #include #include #include @@ -93,7 +93,7 @@ _Noreturn void error(char *fmt, ...) __attribute__((format(printf, 1, 2))); _Noreturn void error_at(char *loc, char *fmt, ...) __attribute__((format(printf, 2, 3))); _Noreturn void error_tok(Token *tok, char *fmt, ...) __attribute__((format(printf, 2, 3))); void warn_tok(Token *tok, char *fmt, ...) __attribute__((format(printf, 2, 3))); -bool equal(Token *tok, char *op); +bool equal(const Token *tok, const char *op); Token *skip(Token *tok, char *op); bool consume(Token **rest, Token *tok, char *str); void convert_pp_tokens(Token *tok); diff --git a/src/3p/chibicc/tokenize.c b/src/3p/chibicc/tokenize.c index 8ed414e..3b15df9 100644 --- a/src/3p/chibicc/tokenize.c +++ b/src/3p/chibicc/tokenize.c @@ -77,7 +77,7 @@ void warn_tok(Token *tok, char *fmt, ...) { } // Consumes the current token if it matches `op`. -bool equal(Token *tok, char *op) { +bool equal(const Token *tok, const char *op) { return memcmp(tok->loc, op, tok->len) == 0 && op[tok->len] == '\0'; } -- cgit v1.2.3