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.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HTML_MESSAGE,MAILING_LIST_MULTI,MIME_QP_LONG_LINE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 29639 invoked from network); 19 Feb 2022 16:07:24 -0000 Received: from minnie.tuhs.org (45.79.103.53) by inbox.vuxu.org with ESMTPUTF8; 19 Feb 2022 16:07:24 -0000 Received: by minnie.tuhs.org (Postfix, from userid 112) id 9F3C59BA40; Sun, 20 Feb 2022 02:07:14 +1000 (AEST) Received: from minnie.tuhs.org (localhost [127.0.0.1]) by minnie.tuhs.org (Postfix) with ESMTP id 36FF59CAFE; Sun, 20 Feb 2022 02:06:32 +1000 (AEST) Authentication-Results: minnie.tuhs.org; dkim=pass (2048-bit key; unprotected) header.d=iitbombay-org.20210112.gappssmtp.com header.i=@iitbombay-org.20210112.gappssmtp.com header.b="Y0WJZ4Bv"; dkim-atps=neutral Received: by minnie.tuhs.org (Postfix, from userid 112) id 8468C9CAFB; Sun, 20 Feb 2022 02:06:30 +1000 (AEST) Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) by minnie.tuhs.org (Postfix) with ESMTPS id 6EF439CBCB for ; Sun, 20 Feb 2022 02:06:27 +1000 (AEST) Received: by mail-qv1-f44.google.com with SMTP id v10so21064566qvk.7 for ; Sat, 19 Feb 2022 08:06:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iitbombay-org.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:from:mime-version:subject:date:message-id :references:cc:in-reply-to:to; bh=9U2+phPI00e2vyn8NwDjCCDjk2G9+qU72ikZrEzE2Ps=; b=Y0WJZ4BvsQctS3ktISsVQ6H0SBWR3yLXXVouqQIctm7KU5JMvjG5NjKj0+8bOt0dQh W0cLHBrTDbiqEXI+aiBjs+kSawqhUuKObGdklU1xsbbrwXbB3lgrPyGAD869F9KcNn6i GoaJKXQnqq76iroL+scUiSSswb8/OsSNtE1p3GOJC02MCTNkUyIC60zOlZewuTlzD0Tu mJAUxZzysMGVFf4PcVmFgILye61L7u2uAfg62/9k686TwA+FUFt5+pFsHDuolz8rElkL a0YwVje+Kr4cSiWcX+8Rp0aAHMS4X7VZSjE2S+sHj2DjTA02LV+den6CN9sXU4Y4HlO7 k0tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:content-transfer-encoding:from:mime-version :subject:date:message-id:references:cc:in-reply-to:to; bh=9U2+phPI00e2vyn8NwDjCCDjk2G9+qU72ikZrEzE2Ps=; b=vWqyvRdhBhpewP/P+MD+jOIr0VARxqxyTsah8Ha7s74cYlFThPxREE+GEG+0xwvv/f m595M2S5k3oNynTZePDx/RJvMWPrPh06bRH7Ndtk6yWGNRtqXc51LVZJariAe0tR1eFD gvbNpmITaAv0+zF2r51StMWm2897xsFu9fSxskXZLJJsIIj8aRXWtt1yMV52ZK4tWKZy Vof+XzgQGltGAeVh9+yCQj3omq+PRm4HfoLteuHLH52jz3mIKODM3nWyzLyMdNXK0rxA BbjC6e2x8mrXX4lBIjYQuAT+oLT9PWm7iqVik3hYDS4jrY8NTDJfUKBEVvAPKDu5g3oe m+AQ== X-Gm-Message-State: AOAM531414MB+BXkTmi1l8U0Q5Q9w/7POMtBCl7wjohOgT+gAoasWp/k RPSWp/l4siR54joPjW5HRS5k7/ibwVfr+w== X-Google-Smtp-Source: ABdhPJxtNTnDN9z+DqT50oizc35LbsOfopcvtLSF6XsZcDURLlgoZGTxrWUs13DOgZ73nb9EpF7/Tg== X-Received: by 2002:ac8:57c9:0:b0:2d7:f146:159b with SMTP id w9-20020ac857c9000000b002d7f146159bmr11418837qta.257.1645286786350; Sat, 19 Feb 2022 08:06:26 -0800 (PST) Received: from smtpclient.apple (107-215-223-229.lightspeed.sntcca.sbcglobal.net. [107.215.223.229]) by smtp.gmail.com with ESMTPSA id v9sm787010qkf.4.2022.02.19.08.06.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 19 Feb 2022 08:06:25 -0800 (PST) Content-Type: multipart/alternative; boundary=Apple-Mail-9A3779E5-12DF-4A12-BFF3-95DFB72A442B Content-Transfer-Encoding: 7bit From: Bakul Shah Mime-Version: 1.0 (1.0) Date: Sat, 19 Feb 2022 08:06:23 -0800 Message-Id: <34EEC8D8-77BD-4A44-8C30-4E1C9015F42D@iitbombay.org> References: <69d88b37-5817-9a0d-4971-3d8641c2d153@gmail.com> In-Reply-To: <69d88b37-5817-9a0d-4971-3d8641c2d153@gmail.com> To: Will Senn X-Mailer: iPad Mail (19D52) 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" --Apple-Mail-9A3779E5-12DF-4A12-BFF3-95DFB72A442B Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable https://research.swtch.com/shmacro > On Feb 19, 2022, at 7:44 AM, Will Senn wrote: >=20 > =EF=BB=BF I have been poring through the v7 source code lately, and came a= cross an oddity I would like to know more about. Specifically, in sh. The co= de for sh is c, but it makes extensive use of of macros, for example: > /usr/src/cmd/sh/word.c > ... > WHILE (c=3Dnextc(0), space(c)) DONE > ... >=20 > 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, b= ut I'm curious why the macros and how this came about? In v6, the sh source i= s straight up c. Is there a story behind it worth knowing? >=20 > Thanks, >=20 > Will --Apple-Mail-9A3779E5-12DF-4A12-BFF3-95DFB72A442B Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

On Feb 19, 2022, a= t 7:44 AM, Will Senn <will.senn@gmail.com> wrote:

=
=EF=BB=BF =20 =20 =20 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/c= md/sh/word.c
...
WHILE (c=3Dnextc(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
=20
= --Apple-Mail-9A3779E5-12DF-4A12-BFF3-95DFB72A442B--