ascherer / cweb

Literate Programming in C/C++
https://github.com/ascherer/cwebbin
86 stars 11 forks source link

CWEB 4.8 breaks MMIX. #38

Closed ascherer closed 1 year ago

ascherer commented 2 years ago

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 commented 2 years ago

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

texdraft commented 2 years ago

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).

ascherer commented 2 years ago

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 commented 1 year ago

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

ascherer commented 1 year ago

Finished.

ascherer commented 10 months ago

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