Liste des Groupes | Revenir à l c |
On 2025-04-22, bart <bc@freeuk.com> wrote:That's a good way to describe it.BTW here is that macro definition from Lua:I'm assuming that op_arith is called numerous times to define handling
>
#define op_arith(L,iop,fop) { \
TValue *v1 = vRB(i); \
TValue *v2 = vRC(i); \
op_arith_aux(L, v1, v2, iop, fop); }
for various VM opcodes.
It *reliably* writes a bunch of code that would otherwise require a lot
of error-prone copy and paste.
This is language extension; the LUA maintainers have written
themselves an op_arith language feature.
The generated codee is large and complex, but at least you can see it.Yes, but that is only needed by the people writing and debugging the macros involved.
If that language feature were wired into the compiler, it would onlyIt is certainly split up more than I would have written, but there are perhaps good reasons for the style. I haven't seen any more of the code than what Bart has quoted here - perhaps there are other situations in which "cast_int" is being passed as a parameter in another macro. Or maybe there are historical reasons - "cast_int" came first, then there were other "cast_X" macros added later, then a generic "cast" macro and "cast_int" was redefined in terms of the generic one. Maybe there are development or test versions of some of these macros where the plain casts are replaced by runtime checks before the conversion, and what we see here is just the release versions without the checks.
be harder to work with. All that morass of code would be hidden
inside, generated into some intermediate representation (that you
can perhaps intercept and get in some readable form, in a
language/notation you will have to learn).
It calls yet more macros, and those in turn call others; here are a fewSome of these look like low value. For instance cast_int(x) saves no
for vRB:
>
#define vRB(i) s2v(RB(i))
#define s2v(o) (&(o)->val)
#define RB(i) (base+GETARG_B(i))
#define GETARG_A(i) getarg(i, POS_A, SIZE_A)
#define getarg(i,pos,size) (cast_int(((i)>>(pos)) & MASK1(size,0)))
#define cast_int(i) cast(int, (i))
#define MASK1(n,p) ((~((~(Instruction)0)<<(n)))<<(p))
#define cast(t, exp) ((t)(exp))
characters over cast(int,x), and ony one character over cast(int, x),
and that is longer than just (int)(x), not to mention (int)x
situations where you can omit parentheses.
Les messages affichés proviennent d'usenet.