[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] for strports.c: scm_c_eval_string_from_file_line
From: |
Bruce Korb |
Subject: |
Re: [PATCH] for strports.c: scm_c_eval_string_from_file_line |
Date: |
Sun, 01 Jun 2003 13:38:22 -0700 |
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
}
}