[OpenBIOS] C bindings

Stefan Reinauer stepan at openbios.org
Thu Oct 30 22:15:12 CET 2003


* Samuel Rydh <samuel at ibrium.se> [031030 17:16]:
> > > 
> > > 	call	( function_addr -- <whatever> )
> 
> Great! I'm trying to make it simple to track the latest openbios
> source so I'm avoiding MOL specific modifications whenever
> possible...

I checked this into CVS, so it will be part of BeginAgain 1.2

> > > 2. Be able to invoke the forth interpreter from C-code
> > > (I think this can be implementable without modifying
> > > the kernel code, but I haven't looked into it yet).
> 
> 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

Hope this helps...

   Stefan

-------------- next part --------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "plugins.h"
#include "dict.h"
#include "stack.h"

#define DEBUG

void enterforth(ucell _cfa);

char forthcode[]=" .\" This is a forth statement\" cr 23 dup ";

/*
 * this example function can be called from beginagain with "call".
 */

static void mol_foobar(void)
{
	ucell xt;
	printf("\nWe're in C now.\n");
	PUSH((ucell)forthcode);
	PUSH(strlen(forthcode));
	xt=findword("evaluate");
	enterforth(xt);
	printf("Done with C code.\n");
}

int plugin_mol_init(void)
{
	printf("Plugin \"mol\" initializing... ");
	
	/* output function pointer for testing with "call" */
	printf("\ntest function at %p\n", mol_foobar);
	
	printf("done.\n");
	return 0;
}

/* plugin meta information available for the plugin loader */
PLUGIN_DESCRIPTION  ("MacOnLinux extension")


More information about the OpenBIOS mailing list