[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Dumping guile's state and registering variables.
From: |
Bill Schottstaedt |
Subject: |
Re: Dumping guile's state and registering variables. |
Date: |
Wed, 7 Mar 2001 05:54:59 -0800 |
> 1) Keep track of any user defined functions so I can dump them out as
> scheme code to allow them to be reloaded at a later execution.
I don't know how complex your situation is, but in the CVS guile you
can run through the module's "obarray" and see what's been defined.
I do this for a Tab-completion feature (abstracted code below);
if I remember right there's a way to find the procedure body as
a string, using the info the debugger keeps around -- scm_procedure_source
perhaps. It might be cleaner to define a macro (in Scheme) that
does both the function definition and save.
static int scan_tab(SCM tab, char *text, int len, int matches)
{
int i, j, n, curlen;
char *sym;
n = SCM_VECTOR_LENGTH(tab);
for (i = 0; i < n; ++i)
{
SCM ls = SCM_VELTS(tab)[i], handle;
while (SCM_NNULLP(ls))
{
handle = SCM_CAR(ls);
sym = SCM_SYMBOL_CHARS(SCM_CAR(handle));
if (strncmp(text, sym, len) == 0)
{
matches++;
add_possible_completion(sym);
if (current_match == NULL)
current_match = strdup(sym);
else
{
curlen = strlen(current_match);
for (j = 0; j < curlen; j++)
if (current_match[j] != sym[j])
{
current_match[j] = '\0';
break;
}
}
}
ls = SCM_CDR(ls);
}
}
return(matches);
}
static int completions(char *text)
{
int len, matches = 0;
SCM curmod, uses;
len = strlen(text);
curmod = scm_current_module();
matches = scan_tab(SCM_MODULE_OBARRAY(curmod),
text, len, 0);
uses = SCM_MODULE_USES(curmod);
while (SCM_CONSP(uses))
{
matches = scan_tab(SCM_MODULE_OBARRAY(SCM_CAR(uses)),
text, len, matches);
uses = SCM_CDR(uses);
}
return(matches);
}