From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Bruce Korb Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] for strports.c: scm_c_eval_string_from_file_line Date: Sun, 01 Jun 2003 13:38:22 -0700 Organization: Home Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <3EDA643E.2215A945@veritas.com> References: <3ECFDA48.309D0F5@veritas.com> <87el2dlg9s.fsf@zagadka.ping.de> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: main.gmane.org 1054499439 27526 80.91.224.249 (1 Jun 2003 20:30:39 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sun, 1 Jun 2003 20:30:39 +0000 (UTC) Cc: guile development Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Jun 01 22:30:37 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19MZTG-00078q-00 for ; Sun, 01 Jun 2003 22:30:26 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19MZU4-0002tD-Hy for guile-devel@m.gmane.org; Sun, 01 Jun 2003 16:31:16 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.20) id 19MZTM-0002hY-SS for guile-devel@gnu.org; Sun, 01 Jun 2003 16:30:32 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.20) id 19MZT3-0002Oy-4R for guile-devel@gnu.org; Sun, 01 Jun 2003 16:30:15 -0400 Original-Received: from bay-bridge.veritas.com ([143.127.3.10] helo=bach.veritas.com) by monty-python.gnu.org with esmtp (Exim 4.20) id 19MZS6-0001sJ-MX for guile-devel@gnu.org; Sun, 01 Jun 2003 16:29:14 -0400 Original-Received: from veritas.com (localhost [127.0.0.1]) by bach.veritas.com (Postfix) with ESMTP id CE6ED270CF; Sun, 1 Jun 2003 13:38:22 -0700 (PDT) X-Mailer: Mozilla 4.8 [en] (X11; U; Linux 2.4.19-4GB i686) X-Accept-Language: en Original-To: Marius Vollmer Original-cc: Bruce Korb X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Developers list for Guile, the GNU extensibility library List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:2469 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:2469 Marius Vollmer wrote: > void > scm_c_primitive_load_from_string (const char *str, > const char *filename, int line) > { > SCM port, exp; > > port = scm_open_input_string (scm_str2string (str)); > scm_set_port_file_name_x (port, scm_str2string (filename)); > scm_set_port_line_x (port, scm_int2num (line)); > > while (!SCM_EOF_OBJECT_P (exp = scm_read (port))) > scm_primitive_eval_x (exp); > } > > I think this quite straightforward, no? No. > But we might want to offer it ready-made, anyway. Opinions? Yes. It is pretty close to what I wound up with, but I don't track the preferred way to do things. For Guile 1.4, ``scm_primitive_eval_x'' gets #define-d into ``scm_eval_x'' and it works. I also try to avoid gratuitous creations of string SCM's since the file name is generally invariant. You omitted returning the final value, which is important :-). It's easier to ignore if the caller doesn't want it. And, no, I didn't find that the research required to do this was obvious. In fact, there is no ``scm_set_port_file_name_x'' in 1.6.3, so you must be talking 1.7 here. I'm still working with 1.4. Therefore, I must directly assign to ``file_name''. I may as well assign the line number, too. I'd rather it was ready made so I can just #define my ``ag_scm_c_eval_string_from_file_line'' into ``scm_c_primitive_load_from_string''. You might tweak it a bit so a NULL file pointer bypasses the scm_set_port_file_name_x call. I'd also use "file_line" in the name, but that is your call. EXPORT SCM ag_scm_c_eval_string_from_file_line( tCC* pzExpr, tCC* pzFile, int line ) { SCM port; { tSCC zEx[] = "eval-string-from-file-line"; SCM expr = scm_makfrom0str( pzExpr ); port = scm_mkstrport( SCM_INUM0, expr, SCM_OPN | SCM_RDNG, zEx ); } { static SCM file = SCM_UNDEFINED; scm_t_port* pt; if ( (file == SCM_UNDEFINED) || (strcmp( SCM_CHARS( file ), pzFile ) != 0) ) file = scm_makfrom0str( pzFile ); pt = SCM_PTAB_ENTRY( port ); pt->line_number = line - 1; pt->file_name = file; } { SCM ans = SCM_UNSPECIFIED; for (;;) { SCM form = scm_read( port ); if (SCM_EOF_OBJECT_P( form )) break; ans = scm_primitive_eval_x( form ); } return ans; // return the last answer } } _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel