The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: Will Senn <will.senn@gmail.com>
To: Bakul Shah <bakul@iitbombay.org>
Cc: TUHS main list <tuhs@minnie.tuhs.org>
Subject: Re: [TUHS] v7 source code for sh
Date: Sat, 19 Feb 2022 10:57:11 -0600	[thread overview]
Message-ID: <8417bc40-5970-a427-dfd5-dc4b99eb01ae@gmail.com> (raw)
In-Reply-To: <34EEC8D8-77BD-4A44-8C30-4E1C9015F42D@iitbombay.org>

[-- Attachment #1: Type: text/plain, Size: 2716 bytes --]

Thanks Bakul, that's interesting.

Impetus for the obfuscated c contest?! The same contest where a guy 
wrote a pdp11 emulator capable of running v0, v6, and 2.9bsd in 50 lines 
of c (Mills, 2018)? I still get a kick out of that code. Particularly 
because you can run Mullender's 1984 entry on the 2.9 bsd instance it 
hosts (it also works in v7, but it's too fast, even with stty 300).

Thankfully, macros, while adding an additional layer of complexity, 
aren't as impenetrable as the ioccc stuff:

    mills's prog.c snippet:
    struct timeval F,G; struct termios H,U={ T} ; enum{
    N=64,a=N<<7,b=a-1,c=a*32,d
    =c-1,    e=c/    2,f=    a*2,    g=a/2,h =g/2,j =h/ 2,Q=V*j*5} ;
    char*s=P,K,M;
    int*      p,      l[      a]      ,m,n,J,o=A,
    O=j,E,R,i,k,t,r,q,u,v,w,x,y,z
    ,B,C,    *D,Z    ;int    main    (){ for(D=mmap...

    mullender's mullender.c in it's entirety (requires v7 or better and
    pdp11):
    short main[] = {
         277, 04735, -4129, 25, 0, 477, 1019, 0xbef, 0, 12800,
         -113, 21119, 0x52d7, -1006, -7151, 0, 0x4bc, 020004,
         14880, 10541, 2056, 04010, 4548, 3044, -6716, 0x9,
         4407, 6, 5568, 1, -30460, 0, 0x9, 5570, 512, -30419,
         0x7e82, 0760, 6, 0, 4, 02400, 15, 0, 4, 1280, 4, 0,
         4, 0, 0, 0, 0x8, 0, 4, 0, ',', 0, 12, 0, 4, 0, '#',
         0, 020, 0, 4, 0, 30, 0, 026, 0, 0x6176, 120, 25712,
         'p', 072163, 'r', 29303, 29801, 'e'
    };

Later,

Will



On 2/19/22 10:06 AM, Bakul Shah wrote:
> https://research.swtch.com/shmacro
>
>> On Feb 19, 2022, at 7:44 AM, Will Senn <will.senn@gmail.com> wrote:
>>
>>  I have been poring through the v7 source code lately, and came 
>> across an oddity I would like to know more about. Specifically, in 
>> sh. The code for sh is c, but it makes *extensive* use of of macros, 
>> for example:
>>
>>     /usr/src/cmd/sh/word.c
>>     ...
>>     WHILE (c=nextc(0), space(c)) DONE
>>     ...
>>
>> The macros for sh are defined in mac.h:
>>
>>     /usr/src/cmd/sh/mac.h
>>     ...
>>     #define BEGIN   {
>>     #define END     }
>>     #define SWITCH  switch(
>>     #define IN      ){
>>     #define ENDSW   }
>>     #define FOR     for(
>>     #define WHILE   while(
>>     #define DO      ){
>>     #define OD      ;}
>>     #define REP     do{
>>     #define PER     }while(
>>     #define DONE    );
>>     ...
>>
>> I can read the resultant code through the lens of my experience 
>> coding c, but I'm curious why the macros and how this came about? In 
>> v6, the sh source is straight up c. Is there a story behind it worth 
>> knowing?
>>
>> Thanks,
>>
>> Will

[-- Attachment #2: Type: text/html, Size: 4597 bytes --]

  reply	other threads:[~2022-02-19 17:01 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-19 15:43 Will Senn
2022-02-19 16:03 ` Steve Nickolas
2022-02-19 16:07   ` Clem Cole
2022-02-19 16:43   ` Steve Nickolas
2022-02-19 17:24   ` Ron Natalie
2022-02-19 16:04 ` Clem Cole
2022-02-19 16:06 ` Bakul Shah
2022-02-19 16:57   ` Will Senn [this message]
2022-02-19 17:44 Bakul Shah
2022-02-19 18:44 ` Rob Pike
2022-02-19 19:29   ` Clem Cole
2022-02-19 22:39   ` John Cowan
2022-02-19 23:11     ` Sven Mascheck
2022-02-19 23:34       ` Rob Pike
2022-02-19 23:36       ` silas poulson
2022-02-20 20:54       ` Chet Ramey
2022-02-20 21:02         ` Larry McVoy
2022-02-20 21:19           ` Chet Ramey
2022-02-20 21:19         ` Lyndon Nerenberg (VE7TFX/VE6BBM)
2022-02-20 22:39           ` Chet Ramey
2022-02-21  1:01             ` Dan Cross
2022-02-22  4:54               ` Dan Stromberg
2022-02-22  5:39                 ` Rob Pike
2022-02-22  5:54                   ` George Michaelson
2022-02-20  7:24 Rudi Blom
2022-02-21 17:58 Norman Wilson
2022-02-21 18:10 ` Rob Pike
2022-02-22  3:07 Brian Walden
2022-02-22 14:28 ` Chet Ramey
2022-02-22 14:47 ` Clem Cole

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8417bc40-5970-a427-dfd5-dc4b99eb01ae@gmail.com \
    --to=will.senn@gmail.com \
    --cc=bakul@iitbombay.org \
    --cc=tuhs@minnie.tuhs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).