From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, NICE_REPLY_A,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 4329 invoked from network); 19 Feb 2022 17:01:21 -0000 Received: from minnie.tuhs.org (45.79.103.53) by inbox.vuxu.org with ESMTPUTF8; 19 Feb 2022 17:01:21 -0000 Received: by minnie.tuhs.org (Postfix, from userid 112) id B6B3993DC1; Sun, 20 Feb 2022 03:01:18 +1000 (AEST) Received: from minnie.tuhs.org (localhost [127.0.0.1]) by minnie.tuhs.org (Postfix) with ESMTP id 095D193D52; Sun, 20 Feb 2022 03:00:36 +1000 (AEST) Authentication-Results: minnie.tuhs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="YR60/yaF"; dkim-atps=neutral Received: by minnie.tuhs.org (Postfix, from userid 112) id EA73F9BA3E; Sun, 20 Feb 2022 02:57:13 +1000 (AEST) Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) by minnie.tuhs.org (Postfix) with ESMTPS id 5B5619BA32 for ; Sun, 20 Feb 2022 02:57:13 +1000 (AEST) Received: by mail-oo1-f43.google.com with SMTP id e19-20020a4ab993000000b0031a98fe3a9dso7620988oop.6 for ; Sat, 19 Feb 2022 08:57:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to; bh=42iV4D4F1Sb3VpXojZwiSwMKCqTVNpQwwQOA0dYVtoE=; b=YR60/yaFyw+IsLY8sLLjBNeWZHTVVsip7rMh1U6nfhPau3Quc9JNUfICSRUKJsxnak 9lfrFsRJgACq3N1Ie6Q62RUyKdYBVkrAwgDiZK7jO/P8H3CCb+2KqMv3UF7YSkcnExaA wW0cfcroBjsgBsMmaKwqes7ZQy1AArlX3DHSHh2XhVPugSCW257ALWyoOpIt8YTtuu2O HRyoQ4bVerEJ1E006prZG8LL5k3/iv5uNxYix4ndhGxVD4SWOu4tjmudC7oz9ONBlVLN 7GHoFMf00CYy5otKWRn8DMRNkS9LuqIZ33euzJ3G9vNCcAFcxdWUjbz1hb+11wuC9jTB T8uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to; bh=42iV4D4F1Sb3VpXojZwiSwMKCqTVNpQwwQOA0dYVtoE=; b=2ZarCzsD/IMhoBZ/5gQIJKXK1/EyXnV/y/pGF30chgSI88rHnx3aTynrHRIS2UtVPh 4zP59ZJbwXiPKfVPQWik63Zsf771yLaENjlGdHOOB92k73GjAD7ZuhsdWRDDc1UtMYRG FSBr5x3+SgWN4oS1POPg9VIr1yizlV5l/73oQ42mVP9w4hOrHTtWDha8qLEOSUfm+NMP lNtNt9dam6VROuxfYGHoS/Iot2TnjZLVVxbkuOgpyNluWiegapEC+BJo5+DLADs2oBGY D2o6HmOYfjA3hnJKJCSKOC4x+npyNXmJOsgJk5Lks0XJw+WTvptk/4ryGZS19BNogPyb x5jg== X-Gm-Message-State: AOAM5328mogX8JAtKn8rWAMZGAoZVJRFeqvLINSCmGYGx1Iay1nkT0J7 KdVP49Rubm9+aBpe/vXM3rhN2qBDwBQ= X-Google-Smtp-Source: ABdhPJyKuT9ZrJ/bNuz6ZarHNdGhhBQKyKev3Ehvnot32bqdrbTg2olC1I3qpvDGdBEscqnni50Flw== X-Received: by 2002:a05:6870:e412:b0:ce:c0c9:65b with SMTP id n18-20020a056870e41200b000cec0c9065bmr6040858oag.173.1645289832578; Sat, 19 Feb 2022 08:57:12 -0800 (PST) Received: from [10.8.2.5] ([2.56.188.40]) by smtp.gmail.com with ESMTPSA id j11sm3096368otj.30.2022.02.19.08.57.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 19 Feb 2022 08:57:12 -0800 (PST) Content-Type: multipart/alternative; boundary="------------EoJJ4Yxp3X2cBTz2KNf20YDf" Message-ID: <8417bc40-5970-a427-dfd5-dc4b99eb01ae@gmail.com> Date: Sat, 19 Feb 2022 10:57:11 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Content-Language: en-US To: Bakul Shah References: <69d88b37-5817-9a0d-4971-3d8641c2d153@gmail.com> <34EEC8D8-77BD-4A44-8C30-4E1C9015F42D@iitbombay.org> From: Will Senn In-Reply-To: <34EEC8D8-77BD-4A44-8C30-4E1C9015F42D@iitbombay.org> Subject: Re: [TUHS] v7 source code for sh X-BeenThere: tuhs@minnie.tuhs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: The Unix Heritage Society mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: TUHS main list Errors-To: tuhs-bounces@minnie.tuhs.org Sender: "TUHS" This is a multi-part message in MIME format. --------------EoJJ4Yxp3X2cBTz2KNf20YDf Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 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 --------------EoJJ4Yxp3X2cBTz2KNf20YDf Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
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:

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

--------------EoJJ4Yxp3X2cBTz2KNf20YDf--