IRC channel logs

2021-11-19.log

back to list of logs

<stikonas>argh, macro functions are a bit annoying...
<stikonas>I might be able to easily get simple case working, but then mes also uses them recursively...
<stikonas>#define CAAR(x) CAR (CAR (x))
<stikonas>well, maybe it will just work by accident...
<oriansj>stikonas: it is ok to not to implement a function
<oriansj>also you can be insanely inefficient too
<stikonas>oriansj: well, if we want to build mes-m2 then we should implement it, but yes, it can be inefficient
<stikonas>anyway, reading info and matching variables to arguments in define is easy, I have those lists
<oriansj>What if you do a state machine for define?
<stikonas>just need to carefully insert tokens
<oriansj>or not
<stikonas>oriansj: I just added one more member to the struct
<oriansj>just map them and replace
<stikonas>struct macro_list had next, symbol, expansion and I've added another token_list* arguments
<stikonas>so mapping is done
<stikonas>just need to do replacement
<oriansj>nice
<oriansj>good work
<stikonas> https://github.com/stikonas/M2-Planet/commits/macro_functions
<stikonas>see last 2 commits
<stikonas>but I still haven't done replacement
<oriansj>just a thought
<stikonas>but it's definitely doable
<oriansj>but how do most C preprocessors do it?
<stikonas>hmm
<stikonas>must be something similar...
<stikonas>it's just text replacement
<stikonas>even for macro functions...
<stikonas>but I guess details do matter...
<oriansj>because I have suspicion that it is probably something really simple we are missing
<stikonas>maybe...
<stikonas>although, I wouldn't say those first two commits that I have are complicated...
<stikonas>although, it might be that my data structures are not the best
<oriansj>hmm https://blog.robertelder.org/7-weird-old-things-about-the-c-preprocessor/
<stikonas>well, I think we'll have to do without #define concat(a,b) a ## b
<stikonas>and stuff like #define function_mac () something might be incompatible with gcc...
<stikonas>but we don't need to get 100% compatibility with gcc preprocessor
<oriansj>I vote we never do a full C macro processor in M2-Planet and just demand basic sanity from downstream projects?
<stikonas>yeah..
<stikonas>well, even if we can't implement "Function Argument Pre-expansion" that shouldn't be too hard to patch out in mes
<oriansj>I wonder if peer pressure would be enough to convince janneke to save us the trouble...
<stikonas>those things can be preexpanded manually
<stikonas>well, let's first see what we can get
<oriansj>fair
<stikonas>at least defines without recursive pre-expansion should be doable
<oriansj>yeah just banning DEFER, OBSTRUCT and EXPAND right now
<oriansj>because holy fuck
<stikonas>at least everything till line 57 should be doable https://git.savannah.gnu.org/cgit/mes.git/tree/include/mes/macros.h
<oriansj>infinitely recursive macro definitions that require lazy evaluation to implement
<oriansj>basically one needs to do a half a haskell, just to deal with what one can do with that.
<oriansj>no wonder people thought bootstrapping C was impossible
<stikonas>well, tcc preprocessor is as large as the whole M2-Planet...
<stikonas>it's about 100KB
<oriansj>hmm https://github.com/ParksProjets/C-Preprocessor/blob/master/lib/compiler.js
<stikonas>hmm, and I"ll have to fix my commits to handle cases like #define A (1) which is not a macro function...
<oriansj>looks like we could just do a simple walk apply for #defines
<stikonas>I guess that's why that whitespace matters between define and paranthesis
<stikonas>hmm
<oriansj>but that isn't collected by M2-Planet so
<stikonas>let me see that link
<stikonas>oh...
<oriansj>and honestly we can restrict ourselves to 3 cases
<oriansj>#define foo 1 #define bar(x) thing_with_[x].car and #define caar(x) bar(bar(x))
<oriansj>if no ( after the first token we do only first case
<stikonas> https://gitlab.com/janneke/nyacc/-/blob/master/module/nyacc/lang/c99/cpp.scm#L140
<oriansj>and the other two are just straight application of match first token and ( then use what is between the ( and ) as x and replace acordingly
<stikonas>yes, I think those 3 cases are good enough...
<stikonas>but then need to be careful with stuff like
<stikonas>#define foo (1)
<oriansj>throw a hard error
<stikonas>maybe...
<oriansj>just exit(FAILURE) with line_error and a sterm message
<oriansj>not our problem
<stikonas>let me see if mes uses it
<stikonas>probably not
<stikonas>then yes, not our problem
<stikonas>tcc does use it...
<oriansj>and if so, no logical reason not to fix it
<stikonas>but I think tcc might be too advanced for M2-Planet...
<oriansj>well yes, M2-Planet is just a stepping stone
<stikonas>anyway, I'll think more tomorrow...
***smartin1 is now known as smartin
<muurkha>happy Arecibo Day
***stikonas_ is now known as stikonas
<stikonas>oriansj: I did get macro functions somewhat working now
<stikonas>so e.g. https://paste.debian.net/1220116/ is expanded correctly
<stikonas>although I think it's still struggling with include/mes/macros.h
<stikonas>and struggling a bit with #define M2_CELL_SIZE (3 * sizeof(long))
<stikonas>that we had in mes-m2
<stikonas>so either workaround is needed, e.g. #define M2_CELL_SIZE 0 + (3 * sizeof(long))
<stikonas>or "#define A (a)" needs to be implemented