Re: transpiling to low level C

Liste des GroupesRevenir à cl c  
Sujet : Re: transpiling to low level C
De : antispam (at) *nospam* fricas.org (Waldek Hebisch)
Groupes : comp.lang.c
Date : 17. Dec 2024, 19:46:00
Autres entêtes
Organisation : To protect and to server
Message-ID : <vjsgt6$32kfa$1@paganini.bofh.team>
References : 1 2 3 4 5 6 7 8 9 10
User-Agent : tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.1.0-9-amd64 (x86_64))
bart <bc@freeuk.com> wrote:
 
If you try to extract any meaning, it is that any control flow can be
expressed either with 'goto' or with 'recursive functions'.
 
This is what I picked up on. Who on earth would eschew 'goto' and use
such a disproportionately more complex and inefficient method like
recursive functions?

Due to silly conding standard?  Or in language that does not have
'goto'.
 
How would you even express an arbitrary goto from random point X in a
function to random point Y, which may be inside differently nested
blocks, via a recursive function?

AFAICS in C main limitation is that you either pass all variables
as parameters (ugly and verbose) or use only global variables
(much worse than 'goto').  The following silly example shows
that 'if' can be simulated using array of function pointers and
indirect calls:

static int bar(int a) {
    return a + 1;
}

static int baz(int a) {
    return 2*a;
}

int
silly(int a) {
    int (*t[2])(int) = {bar, baz};
    return (*t[!!(a > 3)])(a);
}

If you compile it with 'gcc -S -O2' you can see that actually there
are no function calls in generated code (but generated code is clearly
crappy).  However, needed optimication is really simple, so
in principle any compiler could do better.  OTOH code like
this is rare in practice, so probably compiler writers did not
bother.

In similar way one can simulate dense C 'switch'.

Main point is that function call at the end of say 'F' to function
'G' which retruns in the same way as 'F' can be compiled to some
stack shuffling + goto (this is called 'tail call optimization').

IIUC at least some Scheme and ML compilers keep calls in intermediate
level representation (both have no 'goto') and convert them to
jumps only when emiting machine code.

Similar thing was used by one disassembly system: it generated "high
level code" by converting all jumps in machine code to function
calls.  Later the result was cleaned up by transformations, in
particular recursion elimination.

Of course, for orginal purpose of this thread replacing 'if' by
indirect calls is useless

--
                              Waldek Hebisch

Date Sujet#  Auteur
15 Dec 24 * transpiling to low level C127Thiago Adams
15 Dec 24 +* Re: transpiling to low level C10Lawrence D'Oliveiro
15 Dec 24 i`* Re: transpiling to low level C9Thiago Adams
15 Dec 24 i `* Re: transpiling to low level C8Lawrence D'Oliveiro
16 Dec 24 i  `* Re: transpiling to low level C7Thiago Adams
16 Dec 24 i   `* Re: transpiling to low level C6BGB
16 Dec 24 i    +- Re: transpiling to low level C1Thiago Adams
16 Dec 24 i    +- Re: transpiling to low level C1bart
16 Dec 24 i    +- Re: transpiling to low level C1Lawrence D'Oliveiro
16 Dec 24 i    `* Re: transpiling to low level C2Keith Thompson
17 Dec 24 i     `- Re: transpiling to low level C1bart
15 Dec 24 +* Re: transpiling to low level C3Chris M. Thomasson
15 Dec 24 i`* Re: transpiling to low level C2Thiago Adams
15 Dec 24 i `- Re: transpiling to low level C1Chris M. Thomasson
15 Dec 24 +* Re: transpiling to low level C3bart
15 Dec 24 i`* Re: transpiling to low level C2Thiago Adams
15 Dec 24 i `- Re: transpiling to low level C1Thiago Adams
15 Dec 24 `* Re: transpiling to low level C110Bonita Montero
15 Dec 24  +* Re: transpiling to low level C107bart
16 Dec 24  i`* Re: transpiling to low level C106BGB
16 Dec 24  i +- Re: transpiling to low level C1David Brown
16 Dec 24  i +* Re: transpiling to low level C22Thiago Adams
17 Dec 24  i i`* Re: transpiling to low level C21BGB
17 Dec 24  i i `* Re: transpiling to low level C20Thiago Adams
17 Dec 24  i i  +* Re: transpiling to low level C15Thiago Adams
17 Dec 24  i i  i`* Re: transpiling to low level C14Thiago Adams
17 Dec 24  i i  i `* Re: transpiling to low level C13bart
17 Dec 24  i i  i  `* Re: transpiling to low level C12Thiago Adams
17 Dec 24  i i  i   `* Re: transpiling to low level C11bart
18 Dec 24  i i  i    `* Re: transpiling to low level C10BGB
18 Dec 24  i i  i     `* Re: transpiling to low level C9Thiago Adams
19 Dec 24  i i  i      `* Re: transpiling to low level C8BGB
19 Dec 24  i i  i       `* Re: transpiling to low level C7bart
19 Dec 24  i i  i        `* Re: transpiling to low level C6BGB
19 Dec 24  i i  i         +* Re: transpiling to low level C3bart
19 Dec 24  i i  i         i`* Re: transpiling to low level C2BGB
20 Dec 24  i i  i         i `- Re: transpiling to low level C1BGB
23 Dec 24  i i  i         `* Re: transpiling to low level C2Lawrence D'Oliveiro
23 Dec 24  i i  i          `- Re: transpiling to low level C1BGB
17 Dec 24  i i  `* Re: transpiling to low level C4BGB
17 Dec 24  i i   +* Re: transpiling to low level C2Thiago Adams
18 Dec 24  i i   i`- Re: transpiling to low level C1BGB
21 Dec 24  i i   `- Re: transpiling to low level C1Lawrence D'Oliveiro
16 Dec 24  i +* Re: transpiling to low level C69Janis Papanagnou
16 Dec 24  i i+* Re: transpiling to low level C16bart
16 Dec 24  i ii`* Re: transpiling to low level C15Janis Papanagnou
17 Dec 24  i ii `* Re: transpiling to low level C14bart
17 Dec 24  i ii  +* Re: transpiling to low level C12Keith Thompson
17 Dec 24  i ii  i+- Re: transpiling to low level C1BGB
17 Dec 24  i ii  i`* Re: transpiling to low level C10bart
17 Dec 24  i ii  i +- Re: transpiling to low level C1Janis Papanagnou
17 Dec 24  i ii  i +* Re: transpiling to low level C6Waldek Hebisch
17 Dec 24  i ii  i i+* Re: transpiling to low level C4bart
18 Dec 24  i ii  i ii`* Re: transpiling to low level C3Waldek Hebisch
18 Dec 24  i ii  i ii `* Re: transpiling to low level C2bart
18 Dec 24  i ii  i ii  `- Re: transpiling to low level C1Waldek Hebisch
18 Dec 24  i ii  i i`- Re: transpiling to low level C1Janis Papanagnou
17 Dec 24  i ii  i `* Re: transpiling to low level C2Keith Thompson
18 Dec 24  i ii  i  `- Re: transpiling to low level C1Janis Papanagnou
17 Dec 24  i ii  `- Re: transpiling to low level C1Janis Papanagnou
21 Dec 24  i i`* Re: transpiling to low level C52Tim Rentsch
21 Dec 24  i i `* Re: transpiling to low level C51Janis Papanagnou
21 Dec 24  i i  +* Re: transpiling to low level C2Tim Rentsch
22 Dec 24  i i  i`- Re: transpiling to low level C1Janis Papanagnou
21 Dec 24  i i  +* Re: transpiling to low level C16Michael S
22 Dec 24  i i  i+* Re: transpiling to low level C12Janis Papanagnou
22 Dec 24  i i  ii`* Re: transpiling to low level C11Michael S
22 Dec 24  i i  ii `* Re: transpiling to low level C10Janis Papanagnou
22 Dec 24  i i  ii  `* Re: transpiling to low level C9Michael S
22 Dec 24  i i  ii   +* Re: transpiling to low level C6Janis Papanagnou
23 Dec 24  i i  ii   i`* Re: transpiling to low level C5Tim Rentsch
23 Dec 24  i i  ii   i `* Re: transpiling to low level C4Waldek Hebisch
23 Dec 24  i i  ii   i  `* Re: transpiling to low level C3David Brown
25 Dec 24  i i  ii   i   `* Re: transpiling to low level C2BGB
28 Dec 24  i i  ii   i    `- Re: transpiling to low level C1Tim Rentsch
22 Dec 24  i i  ii   `* Re: transpiling to low level C2James Kuyper
22 Dec 24  i i  ii    `- Re: transpiling to low level C1Janis Papanagnou
23 Dec 24  i i  i`* Re: transpiling to low level C3Tim Rentsch
23 Dec 24  i i  i `* Re: transpiling to low level C2Chris M. Thomasson
24 Dec 24  i i  i  `- Re: transpiling to low level C1Chris M. Thomasson
22 Dec 24  i i  +* Re: transpiling to low level C26Waldek Hebisch
22 Dec 24  i i  i+* Re: transpiling to low level C2Michael S
22 Dec 24  i i  ii`- Re: transpiling to low level C1bart
22 Dec 24  i i  i+* Re: transpiling to low level C2Tim Rentsch
22 Dec 24  i i  ii`- Re: transpiling to low level C1Waldek Hebisch
22 Dec 24  i i  i`* Re: transpiling to low level C21Janis Papanagnou
22 Dec 24  i i  i +* Re: transpiling to low level C4Michael S
23 Dec 24  i i  i i+- Re: transpiling to low level C1bart
23 Dec 24  i i  i i+- Re: transpiling to low level C1Michael S
23 Dec 24  i i  i i`- Re: transpiling to low level C1Tim Rentsch
23 Dec 24  i i  i +- Re: transpiling to low level C1Waldek Hebisch
23 Dec 24  i i  i +* Re: transpiling to low level C14David Brown
23 Dec 24  i i  i i+* Re: transpiling to low level C2bart
23 Dec 24  i i  i ii`- Re: transpiling to low level C1David Brown
23 Dec 24  i i  i i+* Re: transpiling to low level C10Michael S
23 Dec 24  i i  i ii+- Re: transpiling to low level C1David Brown
23 Dec 24  i i  i ii`* Re: transpiling to low level C8Tim Rentsch
24 Dec 24  i i  i ii +* Re: transpiling to low level C2Ben Bacarisse
24 Dec 24  i i  i ii i`- Re: transpiling to low level C1Tim Rentsch
25 Dec 24  i i  i ii `* Re: transpiling to low level C5BGB
25 Dec 24  i i  i ii  +- Re: transpiling to low level C1BGB
28 Dec 24  i i  i ii  `* Re: transpiling to low level C3Tim Rentsch
23 Dec 24  i i  i i`- Re: transpiling to low level C1Chris M. Thomasson
23 Dec 24  i i  i `- Re: transpiling to low level C1Tim Rentsch
22 Dec 24  i i  +* Re: transpiling to low level C2Ben Bacarisse
22 Dec 24  i i  `* Re: transpiling to low level C4Kaz Kylheku
16 Dec 24  i `* Re: transpiling to low level C13Lawrence D'Oliveiro
16 Dec 24  `* Re: transpiling to low level C2Lawrence D'Oliveiro

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal