From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: paul Newsgroups: gmane.lisp.guile.user Subject: Re: Difficulty integrating with Swift/Objective-C Date: Mon, 06 Sep 2021 20:26:53 +1000 Message-ID: References: <20210905115646.dcb786924e77fb3198e5271b@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; format=flowed Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24773"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.15; emacs 27.2 To: Chris Vine , guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Mon Sep 06 12:27:36 2021 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 1mNBqg-00069R-Bo for guile-user@m.gmane-mx.org; Mon, 06 Sep 2021 12:27:35 +0200 Original-Received: from localhost ([::1]:59166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNBqf-0004nn-Bf for guile-user@m.gmane-mx.org; Mon, 06 Sep 2021 06:27:33 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50320) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNBqP-0004lx-D6 for guile-user@gnu.org; Mon, 06 Sep 2021 06:27:17 -0400 Original-Received: from aibo.runbox.com ([91.220.196.211]:45818) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNBqM-0000LE-Tm for guile-user@gnu.org; Mon, 06 Sep 2021 06:27:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=inktvis.org ; s=selector1; h=Content-Type:MIME-Version:Message-ID:Date:In-reply-to: Subject:To:From:References; bh=ERwPmTR5RgmvqWdvyDTp+9jQk0OI2l9GbER4fypLzsk=; b=m/RFHSRRwPV7K5x+RRd+oFPmX5z8+JKCeRHYhBPHyVhd/hD4zqbiHS4z36CeHQMrITa+lFJuo+ PIzFkBMuuFmufVz6f6mjBAWfNiPQD67UiE2nDK8y4/QhyAh8F4IGYWc4T4VN21aBbKPV9AGc6IbML u8eSX9g/gV1Ii78t4VugUbVG5VgHq1uJr/SvFuCm/gptelq671GSmoas00loEZIM2eEPDmjfDssth cfxlZzXFA2HpO6Z/ZCnt0rlPciVjLXQGfJkTAgJnnugsx/IItgys9asGez5C8n+uHWNZZJ1Wn3tX5 ch/fjflNXU6ZjNds167/Hfz0L5QbZixWj6aEQ==; Original-Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1mNBqL-0008Qo-Dn; Mon, 06 Sep 2021 12:27:13 +0200 Original-Received: by submission02.runbox with esmtpsa [Authenticated ID (826552)] (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) id 1mNBq7-0005fE-Ig; Mon, 06 Sep 2021 12:27:00 +0200 In-reply-to: <20210905115646.dcb786924e77fb3198e5271b@gmail.com> Received-SPF: pass client-ip=91.220.196.211; envelope-from=paul@inktvis.org; helo=aibo.runbox.com 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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:17718 Archived-At: Hey Chris, On 2021-09-05 at 20:56 AEST, quoth Chris Vine : > You appear to want to run scheme code as an extension language, > via the > guile VM, in a program written for MacOS in the Swift language. This is exactly right. > I know > nothing about the Swift language and whether it has a sufficient > C-like > FFI to achieve this, but you may get some inspiration from the > following, which enables scheme code to be run as an extension > language > within a C++ program: > https://sourceforge.net/p/cxx-gtk-utils/git/ci/master/tree/c++-gtk-utils/extension.h > > However there are various issues. First, guile's exceptions > (based on C's longjmp()/setjmp() and cognates) are almost > certainly > not implemented in the same way as Swift's exceptions (assuming > Swift > has exceptions), which means amongst other things that, if Swift > has > something akin to destructors/deinitialization, you should not > allow > guile exceptions to leave Swift objects undestroyed were guile > to > jump out of local scope on raising an exception > (scm_dynwind_begin(), > scm_dynwind_end and scm_dynwind_unwind_handler can be useful > here if > you are able to manage your Swift objects manually in C). Nor > more > generally should you allow Swift exceptions (if Swift has them) > to > escape out of a guile scm_dynwind_begin()/scm_dynwind_end() > pair, or > you will stop guile's resource management working correctly. > > Secondly, there are some issues relating to the fact that > guile's > 'make-fresh-user-module' and 'load' procedures leak memory, > which can > be problematic if all tasks run as scheme code are not to share > the > same top level. > > Thirdly you will need to cater for translating guile return > values such > as lists or vectors into containers that Swift can work with, > and vice > versa. > > This is all pretty well documented in the C++ code mentioned > above, but > it is not for the faint hearted. I'll definitely take a look at the codebase you link; thank you. Although i am probably on the fainter-hearted side, i have a bit of hope it might be feasible, since my project actually already includes a "core" implemented in Rust and included as a statically-linked library. I'm able to call out to Rust functions i've marked as `extern C`, and so while i don't fully understand the mechanism and the implications for threading and exceptions, so far it has worked well in that limited case. I'm hoping that i can make something similar work in Guile. I think my needs are fairly modest - initially my ambition is to allow the user to rebind shortcut keys of my app using a Guile script. We'll see what else i can come up with later. Thanks for the info though, i'll definitely refer back if i run into issues! Kind regards, p.