From: Andy Wingo <wingo@pobox.com>
To: guile-devel <guile-devel@gnu.org>
Subject: proposal: scm_c_public_ref et al
Date: Sun, 06 Mar 2011 12:24:11 +0100 [thread overview]
Message-ID: <m34o7gcx0k.fsf@unquote.localdomain> (raw)
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/
next reply other threads:[~2011-03-06 11:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-06 11:24 Andy Wingo [this message]
2011-03-06 16:24 ` proposal: scm_c_public_ref et al Mark H Weaver
2011-03-06 17:10 ` Thien-Thi Nguyen
2011-03-06 21:34 ` Andy Wingo
2011-03-06 21:10 ` Andy Wingo
2011-03-06 22:22 ` Ludovic Courtès
2011-03-07 10:45 ` Andy Wingo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m34o7gcx0k.fsf@unquote.localdomain \
--to=wingo@pobox.com \
--cc=guile-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).