guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reprise: scm_c_eval_string_from_file_line


From: Bruce Korb
Subject: Re: reprise: scm_c_eval_string_from_file_line
Date: Thu, 24 Feb 2011 14:58:16 -0800
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.16) Gecko/20101125 SUSE/3.0.11 Thunderbird/3.0.11

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/address@hidden/msg02825.html
http://www.mail-archive.com/address@hidden/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 via email to

[Prev in Thread] Current Thread [Next in Thread]