From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Arne Babenhauserheide Newsgroups: gmane.lisp.guile.user Subject: Re: C programs in Scheme syntax Date: Fri, 29 May 2020 09:29:36 +0200 Message-ID: <878shbi4gv.fsf@web.de> References: <87pnantoe5.fsf@fcs20.keithdiane.us> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="24356"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.4; emacs 26.3 Cc: guile-user@gnu.org To: John Cowan Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Fri May 29 09:30:48 2020 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jeZTZ-0006C4-W7 for guile-user@m.gmane-mx.org; Fri, 29 May 2020 09:30:45 +0200 Original-Received: from localhost ([::1]:41934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeZTX-00057k-KE for guile-user@m.gmane-mx.org; Fri, 29 May 2020 03:30:43 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46436) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeZSY-00051a-LY for guile-user@gnu.org; Fri, 29 May 2020 03:29:42 -0400 Original-Received: from mout.web.de ([212.227.17.11]:39407) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeZSX-0004x2-1P for guile-user@gnu.org; Fri, 29 May 2020 03:29:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1590737376; bh=kArRMPac6AVnjUQLvqLg6GUMr4CphVxScXDXojTyFeM=; h=X-UI-Sender-Class:References:From:To:Cc:Subject:In-reply-to:Date; b=AolYzpFVq0yLRBA4fu5hPOtvVHlLyYlKZOa5LX/7Ui9Ux6QBcUTq/nrjGauOCkzK5 D37irAASrDeoQtXzACKjVCRT3KRMiep9Xby3xtVwvJGMrKy8GMy4USY7DDWLtjwqu7 CZgufpj/H/E83uRaddSDW/Kn4bos2ib97GbQl97o= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Original-Received: from fluss ([80.136.31.6]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MSads-1jWuSi2udY-00RWH1; Fri, 29 May 2020 09:29:36 +0200 In-reply-to: X-Provags-ID: V03:K1:fQOGqpFMOJC/MXfvLMlrWHx5tK5WQ+7RlmlEVBWahIewGuno4hy Y/e/mV7yUZtaNozQvP+8wL8A9lxLWtJiQazRsGzCPj/ufwsariXX050KvTXBG32aIXDCIic jyQiH0ULWU35drZdUP2/yvGvWoztekZ2up0hMlnudfBWgwnN7R0nqMCPXO9FftYyvKfJoW8 dn8KiiFTGVkjBsj0VS0TQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:yUfV2fJd218=:+pHhs0iKMJ6dx0sqR7YrTO 7RYNWxXqqqt7Nk2bTNcmMCKOEvZvDMARDfjFpD4MJa0+U5KGVxNgCbX/qHPoE9ZY8OZiq9Wa1 j1wx9pUHYgCHgEuLWH8k/QOJZ/Yj3cSVY1QtSaucLhQEgTOG2Z0dauOdr/iFrzaxrm+/PFEIa 7H4QpsOiIk8+qgpQ/QUCMJAIJJ+poZW8mEdHZVhNAdzDdOqrL0E5dw5u6zTlsTTTaGwyjuZDp wR5CDw+zWmtxBbyEpERIR1bTET/Pgi3Y4wgF8J9Opvc9rHk6jTwY2fKoZ/WtOlalQlSeeeurY uLJI6qNUX/d1Lkrh2YCahQ5RKtm0ov+SF0Od7XIhPV4lbn62DR7X/3iQHIsfLTimtn13F5pxN bgY+RfuoP0r1Wg/NjH78BJ2fs6lL6gS0145SC6wHWhCSga+coceClibTLCDsDCh2VTcD9PRb4 vN2LE++GepB6783sHRyWzj/+wMs6KjKZMOYSJ7m6FGX6IPtui7EXOiIWKYojk/OuzGKUZU3Qp bQFFmy4VDj01dGTb6k6x9PyYAcWoRsD8/n67Fzf8gqU4QLzXRzKQbI3Nm99y56Y0NYRQeYrvb MoYF/aXFPhSWCvUKqtq6QDlmDKe3O56WVIoOm21VFRk9ZM2u5HvHgFwm6N3jx8CbZnryhGvwX ytOyyn/gC1I31mHrpni9I28et4nX23I7I+hBLfsbx+MinovZgK1My75hHjM1RQSDxPgKF/xlc 76wB/sCRzER7+Z0w6sav586Y083yIs4W7SkNpnCnDKPPHLk4wuGuo6PpYrbb6fWIhs6aCA8X Received-SPF: pass client-ip=212.227.17.11; envelope-from=arne_bab@web.de; helo=mout.web.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/29 03:29:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:16525 Archived-At: Also have a look at https://github.com/sph-mn/sph-sc Examples: ;; declaration (declare a uint32_t b (array uint8_t 3) c (struct (id int) (name char*)) d (enum (x y z)) e (type uint16_t) f (type (struct (id int) (name char*)))) ;; define with value (define a uint32_t 1) ;; macros (pre-define is-included #t id-size 4 (mymacro a b) (set a 1 b 2)) ;; functions (define (myfunction a b) (int char void) "a description of this function" (return 1)) I found it when the author did the full round-trip over wisp via c-indent: http://sph.mn/computer/guides/c/c-indent.html This then looks much more similar to C; but fully regular: pre-include "stdio.h" define (main argc argv) : int int char** declare i int printf "the number of program arguments passed is %d\n" argc for : (set i 0) (< i argc) (set+ i 1) printf "argument %d is %s\n" (+ i 1) (array-get argv i) return 0 Best wishes, Arne John Cowan writes: > Check out the Chibi library (chibi show c). in the Chibi repo at > lib/chibi/show/c.scm and .sld. It provides combinators that create a C > equivalent of the sexp; there is both a macro-based compiler and an > interpreter, IIRC. Unfortunately there is no real documentation. There's > some cleverness in it: c-if in statement context expands to an > if-statement, but in an expression context to a ?: operator. If you impo= rt > (chibi show) and (chibi show c) then (show #t (c-if 'foo 'bar 'baz)) will > generate a statement, but (show #t (c+ 2 (c-if 'foo 'bar 'baz))) will > generate an expression. > > > On Thu, May 28, 2020 at 11:38 PM Keith Wright wro= te: > >> I am thinkging about a project that uses Scheme macros >> to generate C code. To this end I want to encode C >> programs as S-expressions. For example, the C program >> that is encoded in Ascii as >> >> for (j=3D0;j<12;++j) a[j] =3D j*pi/6; >> >> might be encoded as an S-expression as >> >> (for ((=3D j 0)(< j 12) (++ j)) (=3D (sub a j)(/ (* j pi) 6))) >> >> Note that this is not a valid Scheme program, even with >> non-standard functions defined. It is a re-encoding >> of the Ascii C syntax as an S-expression. >> >> I think I have read about something like this, perhaps >> on this list, I am not sure. (Note to future language >> inventors: a single letter name makes a horrible Google >> search query. Name things with made up but pronouncable >> words---perl, fortran...) >> >> I most need to convert S-expr encoded C, to Ascii encoded C, >> but I am interested in >> (a) programs to convert S-expresions to C >> (b) specifications for the form of the S-expr encoding >> (c) better plans; advice from those who have tried and failed. >> >> Any pointers? >> >> -- Keith >> >> >> --=20 Unpolitisch sein hei=C3=9Ft politisch sein ohne es zu merken