From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.devel Subject: proposal: scm_c_public_ref et al Date: Sun, 06 Mar 2011 12:24:11 +0100 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1299410666 1353 80.91.229.12 (6 Mar 2011 11:24:26 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 6 Mar 2011 11:24:26 +0000 (UTC) To: guile-devel Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Mar 06 12:24:22 2011 Return-path: Envelope-to: guile-devel@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 1PwC4R-0002tG-H7 for guile-devel@m.gmane.org; Sun, 06 Mar 2011 12:24:20 +0100 Original-Received: from localhost ([127.0.0.1]:34893 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PwC4Q-00043Q-Ii for guile-devel@m.gmane.org; Sun, 06 Mar 2011 06:24:18 -0500 Original-Received: from [140.186.70.92] (port=38424 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PwC4K-00043L-QD for guile-devel@gnu.org; Sun, 06 Mar 2011 06:24:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PwC4J-0004SV-GI for guile-devel@gnu.org; Sun, 06 Mar 2011 06:24:12 -0500 Original-Received: from a-pb-sasl-sd.pobox.com ([64.74.157.62]:38623 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PwC4J-0004SR-DV for guile-devel@gnu.org; Sun, 06 Mar 2011 06:24:11 -0500 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTP id 6F3613DDD for ; Sun, 6 Mar 2011 06:25:35 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:mime-version:content-type; s=sasl; bh=g U866w3ev9AG97kok8Nw3ZwNXyg=; b=BxgIstvaF393AgY0qUkPIuNtXBO73ZxA8 2fI66cnV4iLfdUQZ4fyhro74OnIQOjCxtfCmSNOx7A8zRMbJoJmIJFeDwOwjfsvS RAYmktaq8DvOKcH4OIFzk0hrw2q5As+PUEtwRXi7iNU5IdYkaheXvDTjKh3s1pGa 6Gj/wtBBi4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :date:message-id:mime-version:content-type; q=dns; s=sasl; b=EB1 E6b+xNIHJGiaY/zhzeUDKdQ80l+kzBDrpT9Nf0uUXNVkiWkPfIvRTmgUxm419ISi MwTIcht6f6I0ZrHA30To1c4FH+GXk0omi4F+SY+fWAYBtT9RtZ2ugamxMY2p7VVV 1C2f8YCARG0wWo7+WdWfI/hymq1m39D2nb+X28gs= Original-Received: from a-pb-sasl-sd.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTP id 6C9F63DDC for ; Sun, 6 Mar 2011 06:25:35 -0500 (EST) Original-Received: from unquote.localdomain (unknown [90.164.198.39]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTPSA id CE8A83DDB for ; Sun, 6 Mar 2011 06:25:34 -0500 (EST) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) X-Pobox-Relay-ID: 74841B7E-47E4-11E0-B39F-AF401E47CF6F-02397024!a-pb-sasl-sd.pobox.com X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-Received-From: 64.74.157.62 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:11787 Archived-At: Hey all, As we move more and more to writing code in Scheme and not in C, it becomes apparent that it is more cumbersome to reference Scheme values than it should be. I propose that we add helper C APIs like these: SCM scm_public_lookup (SCM module_name, SCM sym); SCM scm_private_lookup (SCM module_name, SCM sym); Look up a variable bound to SYM in the module named MODULE_NAME. If the module does not exist or the symbol is unbound, signal an error. The "public" variant looks in the public interface of the module, while scm_private_lookup looks into the module itself. Then also: SCM scm_public_ref (SCM module_name, SCM sym); Equivalent to scm_variable_ref (scm_public_ref (module_name, sym)). SCM scm_private_ref (SCM module_name, SCM sym); Equivalent to scm_variable_ref (scm_private_ref (module_name, sym)). And then: SCM scm_c_public_lookup (const char *module_name, const char *name); SCM scm_c_private_lookup (const char *module_name, const char *name); SCM scm_c_public_ref (const char *module_name, const char *name); SCM scm_c_private_ref (const char *module_name, const char *name); Like the above, but with locale-encoded C strings, for convenience. Module names are encoded as for `scm_c_resolve_module'. With all these, we can happily implement Bruce Korb's `eval-string-from-file-line' using the new `(ice-9 eval-string)', and our code becomes: SCM scm_c_eval_string_from_file_line (const char *str, const char *file, int line) { return scm_call_5 (scm_c_public_ref ("ice-9 eval-string", "eval-string"), scm_from_locale_string (the_string), scm_from_locale_keyword ("file"), scm_from_locale_string (file_name), scm_from_locale_keyword ("line"), scm_from_int (line)); } scm_call_N doesn't go up to 5 yet, but it probably should. We can cache the var if we want: SCM scm_c_eval_string_from_file_line (const char *str, const char *file, int line) { static SCM eval_string_var = SCM_BOOL_F; if (scm_is_false (eval_string_var)) eval_string_var = scm_c_public_lookup ("ice-9 eval-string", "eval-string"); return scm_call_5 (scm_variable_ref (eval_string_var), scm_from_locale_string (the_string), scm_from_locale_keyword ("file"), scm_from_locale_string (file_name), scm_from_locale_keyword ("line"), scm_from_int (line)); } And we can use this strategy for easily moving over more C code to Scheme modules as time goes on. (If we make this convenient enough, we might be able to avoid defining scm_c_eval_string_from_file_line ourselves, and just say to call the function from ice-9 eval-string; but that's another discussion.) Any thoughts? Andy -- http://wingolog.org/