From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: bolega Newsgroups: gmane.emacs.help Subject: Re: A toy example of embedding C code in lisp and vice versa Date: Sat, 12 Jun 2010 12:50:33 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <0d1dad3b-cd37-4bc3-b903-40ac6a53be32@j8g2000yqd.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1291831478 9950 80.91.229.12 (8 Dec 2010 18:04:38 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 8 Dec 2010 18:04:38 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Dec 08 19:04:34 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PQONV-0005kM-Ao for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 19:04:34 +0100 Original-Received: from localhost ([127.0.0.1]:50962 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQONU-0005US-F8 for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 13:04:32 -0500 Original-Path: usenet.stanford.edu!postnews.google.com!w12g2000yqj.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help, comp.lang.c, comp.lang.lisp, comp.lang.scheme, comp.lang.c++ Original-Lines: 61 Original-NNTP-Posting-Host: 75.28.103.27 Original-X-Trace: posting.google.com 1276372233 23348 127.0.0.1 (12 Jun 2010 19:50:33 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Sat, 12 Jun 2010 19:50:33 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: w12g2000yqj.googlegroups.com; posting-host=75.28.103.27; posting-account=REkl4woAAABFXaU7nL79XtGpnmNCQ415 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6,gzip(gfe) Original-Xref: usenet.stanford.edu gnu.emacs.help:178875 comp.lang.c:975914 comp.lang.lisp:288989 comp.lang.scheme:86971 comp.lang.c++:1040634 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:75756 Archived-At: On Jun 12, 12:08=A0pm, bolega wrote: > Here is a link to a thread that discusses this topic but there is no > complete example. > > http://objectmix.com/lisp/362409-howto-use-lisp-scripting-language-wi... > > Lars Lune has a good section on code by searching this string > > "On Tue, 18 Mar 2008 01:16:00 -0700, Blackguester wrote:" > > but his code is replaced with smileys and even source shows it. I > could not muster the confidence as a newbie to go into it by myself. > Unless a guru can guide and explain. > > http://common-lisp.net/project/cffi/http://common-lisp.net/project/cffi/m= anual/html_node/Tutorial.htmlhttp://www.sbcl.org/manual/Foreign-Function-In= terface.html > > Should I pick SBCL or ECL ? I have a long term view. http://www.sbcl.org/manual/Calling-Lisp-From-C.html#Calling-Lisp-From-C 8.7.4 Calling Lisp From C Calling Lisp functions from C is sometimes possible, but is extremely hackish and poorly supported as of SBCL 0.7.5. See funcall0 ... funcall3 in the runtime system. The arguments must be valid SBCL object descriptors (so that e.g. fixnums must be left-shifted by 2.) As of SBCL 0.7.5, the format of object descriptors is documented only by the source code and, in parts, by the old CMUCL INTERNALS documentation. Note that the garbage collector moves objects, and won't be able to fix up any references in C variables. There are three mechanisms for coping with this: 1. The sb-ext:purify moves all live Lisp data into static or read- only areas such that it will never be moved (or freed) again in the life of the Lisp session 2. sb-sys:with-pinned-objects is a macro which arranges for some set of objects to be pinned in memory for the dynamic extent of its body forms. On ports which use the generational garbage collector (as of SBCL 0.8.3, only the x86) this has a page granularity - i.e. the entire 4k page or pages containing the objects will be locked down. On other ports it is implemented by turning off GC for the duration (so could be said to have a whole-world granularity). 3. Disable GC, using the without-gcing macro. [Q] How easy is it to call ECL http://sourceforge.net/projects/ecls/ from C ? Any toy example of doing this ? what type of problem set would advise us that we embed C in LISP and where lisp in C ? Some toy examples ? send me email if you will share thru private correspondance only.