Re: Callbacks in gforth-0.6.9-20080716
  Home FAQ Contact Sign in
comp.lang.forth only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: Callbacks in gforth-0.6.9-20080716         

Group: comp.lang.forth · Group Profile
Author: ddaa
Date: Sep 5, 2008 14:37

On Aug 30, 11:56 pm, ddaa gmail.com> wrote:
> Hello, I have trouble making callbacks work in gforth-0.6.9-20080716.
>
> So far, I can use libcc to build both the callback and the caller
> function, and use them in gforth. But I cannot make the final step to
> lib.fs callbacks. Apparently, I'm not passing the callback right to
> the C code.

I had some time again to investigate. I think I tracked down the
problem to the way fflib calls back into gforth_engine.

At this point I'm stumped.

-----8<----------8<----------8<----------8<----------8<----------8<-----
\c #include
\c #include
\c static va_alist gforth_clist;
\c static Cell *gforth_RP;
\c static char *gforth_LP;
\c typedef void *Label;
\c typedef Label *Xt;
\c Label *gforth_engine(Xt *ip, Cell *sp, Cell *rp0, Float *fp, char
*lp);
\c
\c void gforth_callback_ffcall2(Xt* fcall, void * alist)
\c {
\c printf("gforth_callback_ffcall2 %%x %%x\n", fcall, alist);
\c /* save global valiables */
\c Cell *rp = gforth_RP;
\c Cell *sp = gforth_SP;
\c Float *fp = gforth_FP;
\c char *lp = gforth_LP;
\c va_alist clist = gforth_clist;
\c
\c gforth_clist = (va_alist)alist;
\c
\c printf("calling back into gforth_engine\n");
\c gforth_engine(fcall, sp, rp, fp, lp);
\c printf("returned from gforth_engine\n");
\c
\c /* restore global variables */
\c gforth_RP = rp;
\c gforth_SP = sp;
\c gforth_FP = fp;
\c gforth_LP = lp;
\c gforth_clist = clist;
\c }
c-function gforth-callback-ffcall2 gforth_callback_ffcall2 a a -- void

: forth-void ( -- )
cr ." In forth-void" ;

: forth-engine-test
." forth-engine-test" cr
['] forth-void 0 gforth-callback-ffcall2 ;

forth-engine-test
bye
-----8<----------8<----------8<----------8<----------8<----------8<-----

Terminal output:
-----8<----------8<----------8<----------8<----------8<----------8<-----
-*- mode: compilation; default-directory: "~/Documents/Forth/" -*-
Compilation started at Fri Sep 5 23:06:57

gforth callback-debug.fs
forth-engine-test
gforth_callback_ffcall2 401f0510 0
calling back into gforth_engine

in file included from *OS command line*:-1
callback-debug.fs:42: Invalid memory address
>>>forth-engine-test<<<
Backtrace:

Compilation exited abnormally with code 1 at Fri Sep 5 23:06:58
-----8<----------8<----------8<----------8<----------8<----------8<-----

Expected behaviour: at least printing "In forth-void" before crashing.
Preferably, not crash at all.
no comments
diggit! del.icio.us! reddit!