cweb icon indicating copy to clipboard operation
cweb copied to clipboard

CWEB 4.8 breaks MMIX.

Open ascherer opened this issue 3 years ago • 3 comments

DEK uses the curious construct

function declaration with ARGS macro;@+@t}\6{@>
function definition without ARGS macro but K&R parameters

in MMIX modules mmixal.w, mmix-arith.w, mmix-config.w, mmix-io.w, mmix-mem.w, mmix-sim.w, and mmmix.w.

The new CWEB grammar for support of both K&R and ANSI functions indents the

function declaration with ARGS macro
    function definition together with the
    arguments;

Leaving out the @t}\6{@> as in mmotype.w is the natural solution.

Overall, the MMIX code is quite messy in this respect, intermingling function declarations and definitions and global (non-static!) variables.

A significantly better approach is used in mmix-pipe.w, separating @<Prototypes@> and @<Subroutines@> (internal and external).

ascherer avatar Jun 04 '22 17:06 ascherer

If you really, absolutely want to place function declarations and definitions together with a forced line break, you can use @t}\6\4\4{@>.

ascherer avatar Jun 04 '22 18:06 ascherer

Perhaps you could add a “super backup” macro to cwebmac that undoes all indentation and ensures the next line begins at the left margin. Then have CWEAVE put it at the beginning of function definitions/declarations. However, this would have the effect of removing support for nested function definitions/declaration (a nonstandard extension to C, but I think the current grammar allows them).

texdraft avatar Jun 08 '22 15:06 texdraft

The grammar and implementation being as fragile as it is, I will first set up a (small) set of test cases for “fixed” issues (like your testthings.w and my if.w codes). Then I'd have to study the @2 pragma to see in detail what's going on with the insert and where and why it gets merged into decl_head and fn_decl.

At the moment, I'd rather have “normal” CWEB programs format OK, rather than hacking around the peculiar MMIX sources (which I really don't like in general).

ascherer avatar Jun 09 '22 14:06 ascherer

I've made progress by fixing major parts of MMIX.

ascherer avatar Apr 15 '23 04:04 ascherer

Finished.

ascherer avatar Apr 15 '23 13:04 ascherer

Note that C23 will deprecate K&R function headers anyway.

ascherer avatar Jan 03 '24 21:01 ascherer