[OpenBIOS] C bindings
Stefan Reinauer
stepan at openbios.org
Fri Oct 31 12:20:29 CET 2003
* Samuel Rydh <samuel at ibrium.se> [031030 23:56]:
> > > Well, I don't need concurrent instances, just recursive.
> > > enterforth() seems to be able to handle that. What I need though
> > > is runtime translation of C-string forth into tokens. I.e. basically
> > > I need to do the same stuff as interpret does. I will look into it;
> >
> > Ok, I wrote a little example which can be used as a plugin i.e. with:
> > ~/openbios/kernel/obj-x86> ./unix openfirmware.dict -P . -p mol
> >
> > The C function calls the interpreter giving it the string in
> > forthcode[]. It's the same thing as typing the following on the
> > interpreter:
> > ." This is a forth statement" cr 23 dup
One thing that might come handy is not possible yet: Adding words to the
dictionary this way in the plugin init function. This could look like:
char *prom_next_property( mol_device_node_t *dn, const char *prev_name);
static void plugin_mol_next_property(void)
{
mol_device_node_t *dn=POP();
POP(); // drop len
char *prev_name=POP();
prom_next_property(dn, prev_name);
}
int add_c_function(char *name, void (*cfunc)(void))
{
char forthcode[80];
snprintf(address, 17, ": %s h# %lx call ;\n",
name, (unsigned long)cfunc);
PUSH((ucell)forthcode);
PUSH(strlen(forthcode));
enterforth(findword("evaluate"));
}
int plugin_mol_init(void)
{
add_c_function("next-property", plugin_mol_next_property);
...
}
Unfortunately this is not yet possible since plugins are initialized
quite a bit before the dictionary is available.
I'll seperate plugin dependencies and plugin initialization and move the
init part beyound dictionary init. This way the above scenario can be
used to directly add forth words that are written in C while still
keeping them out of the openbios kernel.
Does this sound reasonable?
Stefan
More information about the OpenBIOS
mailing list