unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Bruce Korb <bkorb@gnu.org>
To: guile-devel Development <guile-devel@gnu.org>
Cc: "Ludovic Courtès" <ludo@gnu.org>
Subject: Re: reprise: scm_c_eval_string_from_file_line
Date: Thu, 24 Feb 2011 14:58:16 -0800	[thread overview]
Message-ID: <4D66E288.7030608@gnu.org> (raw)
In-Reply-To: <87sjvdl6ce.fsf@gnu.org>

On 02/24/11 08:56, Ludovic Courtès wrote:
> It compiles fine up to here:
> 
> --8<---------------cut here---------------start------------->8---
> make[4]: Entering directory `/home/ludo/tmp/autogen-5.11.7pre1/getdefs'
> exec > gd.c ; \
> echo '#include "config.h"' ; \
> echo '#undef   PKGDATADIR' ; \
> echo '#define  PKGDATADIR "/home/ludo/soft/share/autogen"' ; \
> for f in opts.c getdefs.h proto.h getdefs.c gdemit.c gdinit.c ; \
> do echo "#include \"$f\"" ; done
> top_builddir=.. top_srcdir=.. PATH=`cd ../columns >/dev/null && pwd`:$PATH ; export top_builddir to
> p_srcdir PATH ; /home/ludo/tmp/autogen-5.11.7pre1/agen5/autogen -L../autoopts/tpl -L../autoopts/tpl
>  -MF.deps/opts-dep -MTstamp-opts ./opts.def
> module/ice-9/psyntax.scm:896:30: In procedure dobody:
> module/ice-9/psyntax.scm:896:30: Syntax error:
> ../autoopts/tpl/optlib.tlib:167:22: definition in expression context in subform UP-prefix of (string-append (string-upcase! (get "prefix")) "_")
> Scheme evaluation error.  AutoGen ABEND-ing in template
>         ../autoopts/tpl/optlib.tlib on line 66
[...]
> The failing code is:
> 
> --8<---------------cut here---------------start------------->8---
> (if (exist? "prefix")
>  (begin
>    (define UP-prefix  (string-append (string-upcase! (get "prefix")) "_"))
> --8<---------------cut here---------------end--------------->8---
> 
> ‘define’ is no longer allowed here (search ‘NEWS’ for ‘prohibiting
> definitions in expression’.)

This is an example of why it is important to be able to specify
the source file and line number where the scheme expression gets
extracted from.  This "../autoopts/tpl/optlib.tlib:167:22" thing
led Ludovic directly to the problematic code.  (He sees the problem,
I do not.)  But in order to get the Guile library to understand
where the code comes from, I have to go through what I consider
to be somersaults.

Anyway, picking up threads from 2003 and 2008:
http://osdir.com/ml/lisp.guile.devel/2003-05/msg00202.html
http://www.mail-archive.com/guile-devel@gnu.org/msg02825.html
http://www.mail-archive.com/guile-devel@gnu.org/msg02826.html

I would really, _really_ appreciate being able to yank it out of
my code.  Below is an example of what I go through to do it.
It is simplified somewhat since I no longer support Guile 1.4.

It simply doesn't feel like a straight forward interface.
It feels like I am starting a "process this string" function,
then inject some information, then call a function to scan
a bit then process a bit.  How would it ever get compiled?
It'd be nice to be able to say, "here's some text, from this
file and this line number, give me back the compiled form"
and then call the "run it" function.  But I can't.  I have to
insert the file and line information.  It's icky code.

Thank you.  Regards, Bruce

SCM
ag_scm_c_eval_string_from_file_line(
    char const * pzExpr, char const * pzFile, int line)
{
    SCM port = scm_open_input_string(AG_SCM_STR02SCM(pzExpr));

    if (OPT_VALUE_TRACE >= TRACE_EVERYTHING)
        fprintf(pfTrace, "eval from file %s line %d:\n%s\n", pzFile, line,
                pzExpr);

    {
        static SCM    file      = SCM_UNDEFINED;
        static char * pzOldFile = NULL;

        if ((pzOldFile == NULL) || (strcmp(pzOldFile, pzFile) != 0)) {
            if (pzOldFile != NULL)
                AGFREE(pzOldFile);
            AGDUPSTR(pzOldFile, pzFile, "scheme file source");
            file = AG_SCM_STR02SCM(pzFile);
        }

        {
#if GUILE_VERSION < 107000
            scm_t_port * pt = SCM_PTAB_ENTRY(port);
            pt->line_number = line - 1;
            pt->file_name   = file;
#else
            SCM ln = scm_from_int(line);
            scm_set_port_filename_x(port, file);
            scm_set_port_line_x(port, ln);
#endif
        }
    }

    {
        SCM ans = SCM_UNSPECIFIED;

        /* Read expressions from that port; ignore the values.  */
        for (;;) {
            SCM form = scm_read(port);
            if (SCM_EOF_OBJECT_P(form))
                break;
            ans = scm_primitive_eval_x(form);
        }

        return ans;
    }
}



       reply	other threads:[~2011-02-24 22:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.4.1298297717.17321.info-gnu@gnu.org>
     [not found] ` <87vd0cqjvx.fsf@gnu.org>
     [not found]   ` <4D643043.6080406@gnu.org>
     [not found]     ` <4D658101.7030307@gnu.org>
     [not found]       ` <87sjvdl6ce.fsf@gnu.org>
2011-02-24 22:58         ` Bruce Korb [this message]
2011-02-25 11:13           ` reprise: scm_c_eval_string_from_file_line Andy Wingo
2011-03-08 22:28           ` Andy Wingo
2011-03-08 22:45             ` Bruce Korb
2011-03-08 22:52               ` Andy Wingo
2011-03-09  6:30                 ` Mark H Weaver
2011-03-09 10:07               ` Ludovic Courtès
2011-03-09 20:15                 ` Andy Wingo
2011-03-10  9:35                   ` Bruce Korb

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=4D66E288.7030608@gnu.org \
    --to=bkorb@gnu.org \
    --cc=guile-devel@gnu.org \
    --cc=ludo@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).