Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <vjnq5s$pubt$1@dont-email.me>
Deutsch   English   Français   Italiano  
<vjnq5s$pubt$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: BGB <cr88192@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: transpiling to low level C
Date: Sun, 15 Dec 2024 17:53:30 -0600
Organization: A noiseless patient Spider
Lines: 124
Message-ID: <vjnq5s$pubt$1@dont-email.me>
References: <vjlh19$8j4k$1@dont-email.me>
 <vjn9g5$n0vl$1@raubtier-asyl.eternal-september.org>
 <vjnhsq$oh1f$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 16 Dec 2024 00:53:32 +0100 (CET)
Injection-Info: dont-email.me; posting-host="ddb9061b7ff374fdc7dfdbef0796e5c0";
	logging-data="850301"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/ofZxY1Xt8naHMqHstpihvhkM3qEv0cmg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:QSAxAGzeKYdrIsqjk4Zo+AEmTxk=
In-Reply-To: <vjnhsq$oh1f$1@dont-email.me>
Content-Language: en-US
Bytes: 3531

On 12/15/2024 3:32 PM, bart wrote:
> On 15/12/2024 19:08, Bonita Montero wrote:
>> C++ is more readable because is is magnitudes more expressive than C.
>> You can easily write a C++-statement that would hunddres of lines in
>> C (imagines specializing a unordered_map by hand). Making a language
>> less expressive makes it even less readable, and that's also true for
>> your reduced C.
>>
> 
> That's not really the point of it. This reduced C is used as an 
> intermediate language for a compiler target. It will not usually be 
> read, or maintained.
> 
> An intermediate language needs to at a lower level than the source 
> language.
> 
> And for this project, it needs to be compilable by any C89 compiler.
> 
> Generating C++ would be quite useless.
> 

As an IL, even C is a little overkill, unless turned into a restricted 
subset (say, along similar lines to GCC's GIMPLE).

Say:
   Only function-scope variables allowed;
   No high-level control structures;
   ...

Say:
   int foo(int x)
   {
     int i, v;
     for(i=x, v=0; i>0; i--)
       v=v*i;
     return(v);
   }

Becoming, say:
   int foo(int x)
   {
     int i;
     int v;
     i=x;
     v=0;
     if(i<=0)goto L1;
     L0:
     v=v*i;
     i=i-1;
     if(i>0)goto L0;
     L1:
     return v;
   }

....


Though, this still requires the backend to have a full parser.



Would still be simpler still for a backend to use a plain binary 
serialization, and/or maybe a syntax more like BASIC or similar.

Say:
   SUB foo ( x as Int ) as Int
     DIM i as Int
     DIM v as Int
     i=x
     v=0
     IF i <= 0 THEN GOTO L1
     L0:
     v = v * i
     i = i - 1
     IF i > 0 THEN GOTO L0
     L1:
     RETURN v
   END SUB

Where one can have a parser that reads one line at a time, breaks it 
into tokens, and does simple pattern matching.

Pretty much all higher level control flow can be expressed via goto.

Variables within sub-blocks can be promoted to function scope, possibly 
renamed:
   int i;
   if() {
     long i;
     ...
   }
Remaps:
   int i$0;
   long i$1;

"switch()" can be decomposed:
   switch(i)
   {
     case 1:
       A;
       break;
     case 2:
       B;
     case 3:
       C;
   }
To:
   if(i==1)goto CL1;
   if(i==2)goto CL2;
   if(i==3)goto CL3;
   goto CDFL;
   CL1:
     A;
     goto CEND;
   CL2:
     B;
   CL3:
     C;
   CDFL:
   CEND:

....