From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Bruce Korb Newsgroups: gmane.lisp.guile.devel Subject: Re: reprise: scm_c_eval_string_from_file_line Date: Thu, 24 Feb 2011 14:58:16 -0800 Message-ID: <4D66E288.7030608@gnu.org> References: <87vd0cqjvx.fsf@gnu.org> <4D643043.6080406@gnu.org> <4D658101.7030307@gnu.org> <87sjvdl6ce.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1298588314 3116 80.91.229.12 (24 Feb 2011 22:58:34 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 24 Feb 2011 22:58:34 +0000 (UTC) Cc: =?windows-1252?Q?Ludovic_Court=E8s?= To: guile-devel Development Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Feb 24 23:58:30 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 1Psk8i-0000Eu-Vb for guile-devel@m.gmane.org; Thu, 24 Feb 2011 23:58:30 +0100 Original-Received: from localhost ([127.0.0.1]:48363 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Psk8i-00084r-5Q for guile-devel@m.gmane.org; Thu, 24 Feb 2011 17:58:28 -0500 Original-Received: from [140.186.70.92] (port=55794 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Psk8d-00082d-Kj for guile-devel@gnu.org; Thu, 24 Feb 2011 17:58:24 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Psk8c-0007OT-1Q for guile-devel@gnu.org; Thu, 24 Feb 2011 17:58:23 -0500 Original-Received: from fencepost.gnu.org ([140.186.70.10]:45822) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Psk8b-0007OP-WF for guile-devel@gnu.org; Thu, 24 Feb 2011 17:58:22 -0500 Original-Received: from adsl-75-2-134-104.dsl.pltn13.sbcglobal.net ([75.2.134.104]:48743 helo=[10.10.1.101]) by fencepost.gnu.org with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1Psk8a-0003wQ-JO; Thu, 24 Feb 2011 17:58:20 -0500 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 In-Reply-To: <87sjvdl6ce.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.10 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:11709 Archived-At: 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; } }